Skip to content

Instantly share code, notes, and snippets.

@davidkryzaniak
Last active July 6, 2020 02:53
Show Gist options
  • Select an option

  • Save davidkryzaniak/7f62589604f9d27f2331a7ad2f9d53ee to your computer and use it in GitHub Desktop.

Select an option

Save davidkryzaniak/7f62589604f9d27f2331a7ad2f9d53ee to your computer and use it in GitHub Desktop.

Revisions

  1. davidkryzaniak revised this gist Jul 6, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion template.yml
    Original file line number Diff line number Diff line change
    @@ -25,18 +25,20 @@ Resources:
    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: /
    Path: /look/at/all/those/chickens/
    Method: get

    Outputs:
  2. davidkryzaniak created this gist Jul 6, 2020.
    48 changes: 48 additions & 0 deletions template.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    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:
    Type: Api
    Properties:
    RestApiId:
    Ref: ApiGatewayEndpoint
    Path: /{proxy+}
    Method: any
    HttpApiSpecificPathAndMethod:
    Type: Api
    Properties:
    RestApiId:
    Ref: ApiGatewayEndpoint
    Path: /
    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}"