IAM permission example for AWS SAM (original) (raw)
You can control access to your APIs by defining IAM permissions within your AWS SAM template. To do this, you use the ApiAuth data type.
The following is an example AWS SAM template that uses for IAM permissions:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Description: 'API with IAM authorization'
Auth:
DefaultAuthorizer: AWS_IAM #sets AWS_IAM auth for all methods in this API
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.10
Events:
GetRoot:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /
Method: get
InlineCode: |
def handler(event, context):
return {'body': 'Hello World!', 'statusCode': 200}
For more information about IAM permissions, see Control access for invoking an API in the API Gateway Developer Guide.
Lambda authorizer examples
Amazon Cognito user pool example
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.