Skip to content

Instantly share code, notes, and snippets.

@davidkryzaniak
Last active July 6, 2020 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidkryzaniak/7f62589604f9d27f2331a7ad2f9d53ee to your computer and use it in GitHub Desktop.
Save davidkryzaniak/7f62589604f9d27f2331a7ad2f9d53ee to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
# Build the API Gateway and setup an API Key
ApiGatewayEndpoint:
Type: 'AWS::Serverless::Api'
Properties:
StageName: Prod
Auth:
ApiKeyRequired: true
UsagePlan:
CreateUsagePlan: PER_API
UsagePlanName: GatewayAuthorization
# Setup the Lambda Function (You may want to change "ServerlessFunction" to something more meaningful)
ServerlessFunction:
Type: 'AWS::Serverless::Function'
Properties:
Runtime: nodejs12.x
CodeUri: .
Handler: index.handler
Description:
MemorySize: 128
Timeout: 30
Events:
HttpApiAnyPathAnyMethod:
# Wildcard all Paths and Methods (does not include "/")
Type: Api
Properties:
RestApiId:
Ref: ApiGatewayEndpoint
Path: /{proxy+}
Method: any
HttpApiSpecificPathAndMethod:
# Request to /look/at/all/those/chickens/ must be a GET
Type: Api
Properties:
RestApiId:
Ref: ApiGatewayEndpoint
Path: /look/at/all/those/chickens/
Method: get
Outputs:
ApiGateway:
Description: "The URL is:"
Value: !Sub "https://${ApiGatewayEndpoint}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
ApiKey:
Description: "You can find your API Key in the AWS console: (Put in the request HEADER as 'x-api-key')"
Value: !Sub "https://console.aws.amazon.com/apigateway/home?region=${AWS::Region}#/api-keys/${ApiGatewayEndpointApiKey}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment