IAM permission example - Amazon Serverless Application Model
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

IAM permission example

You can control access to your APIs by defining IAM permissions within your Amazon SAM template. To do this, you use the ApiAuth data type.

The following is an example Amazon 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.