API key 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).

API key example

You can control access to your APIs by requiring API keys within your Amazon SAM template. To do this, you use the ApiAuth data type.

The following is an example Amazon SAM template section for API keys:

Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Auth: ApiKeyRequired: true # sets for all methods MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: . Handler: index.handler Runtime: nodejs12.x Events: ApiKey: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: get Auth: ApiKeyRequired: true

For more information about API keys, see Creating and using usage plans with API keys in the API Gateway Developer Guide.