Skip to content

Instantly share code, notes, and snippets.

@femilofin
Last active April 13, 2022 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save femilofin/4c79dae0e6daf1b1e06210af9a39bab6 to your computer and use it in GitHub Desktop.
Save femilofin/4c79dae0e6daf1b1e06210af9a39bab6 to your computer and use it in GitHub Desktop.
API Gateway Cloudformation template
AWSTemplateFormatVersion: "2010-09-09"
Description: "My API Gateway"
Parameters:
apiGatewayName:
Type: "String"
AllowedPattern: "^[a-zA-Z0-9_.\\-]+$"
apiGatewayDescription:
Type: "String"
AllowedPattern: "^[a-zA-Z0-9_.\\- ]+$"
Default: "A REST API"
apiGatewayStageName:
Type: "String"
AllowedPattern: "^[a-z0-9]+$"
Default: "dev"
Resources:
apiGateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: !Ref "apiGatewayName"
Description: !Ref "apiGatewayDescription"
apiGatewayResource:
Type: "AWS::ApiGateway::Resource"
Properties:
ParentId: !GetAtt "apiGateway.RootResourceId"
PathPart: 'mock'
RestApiId: !Ref "apiGateway"
apiGatewayRootMethod:
Type: "AWS::ApiGateway::Method"
Properties:
ApiKeyRequired: false
AuthorizationType: "NONE"
HttpMethod: "GET"
Integration:
RequestTemplates:
application/json: |
{"statusCode": 200}
IntegrationResponses:
- ResponseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
ResponseTemplates:
application/json: "{\"message\": \"OK\"}"
StatusCode: 200
Type: "MOCK"
TimeoutInMillis: 29000
MethodResponses:
- ResponseModels:
application/json: !Ref "apiGatewayModel"
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: true
StatusCode: 200
ResourceId: !Ref "apiGatewayResource"
RestApiId: !Ref "apiGateway"
apiGatewayModel:
Type: "AWS::ApiGateway::Model"
Properties:
ContentType: 'application/json'
RestApiId: !Ref "apiGateway"
Schema: {}
apiGatewayDeployment:
Type: "AWS::ApiGateway::Deployment"
DependsOn: "apiGatewayRootMethod"
Properties:
RestApiId: !Ref "apiGateway"
apiGatewayStage:
Type: "AWS::ApiGateway::Stage"
Properties:
StageName: !Ref "apiGatewayStageName"
RestApiId: !Ref "apiGateway"
DeploymentId: !Ref "apiGatewayDeployment"
MethodSettings:
- ResourcePath: /mock
HttpMethod: "GET"
MetricsEnabled: "true"
DataTraceEnabled: "true"
LoggingLevel: "INFO"
AccessLogSetting:
DestinationArn: !GetAtt "apiCloudWatch.Arn"
Format: "{\"requestId\": \"$context.requestId\", \"ip\": \"$context.identity.sourceIp\", \"caller\": \"$context.identity.caller\", \"requestTime\": \"$context.requestTimeEpoch\", \"httpMethod\": \"$context.httpMethod\", \"resourcePath\": \"$context.resourcePath\", \"status\": \"$context.status\", \"protocol\": \"$context.protocol\", \"responseLength\": \"$context.responseLength\"}"
apiCloudWatch:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Ref "apiGatewayName"
RetentionInDays: 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment