simplify-cli
Version:
Simplify CLI - Easy Deployment
304 lines (297 loc) • 9.99 kB
YAML
AWSTemplateFormatVersion: '2010-09-09'
Description: API Gateway resource stack creation using Simplify CLI
Parameters:
Environment:
Type: String
Default: devs
AllowedValues:
- prod
- demo
- test
- devs
LambdaFunctionName:
Type: String
LambdaFunctionArn:
Type: String
CognitoUserPoolId:
Type: String
Default: eu-central-1_xxxxxxxx
Resources:
HttpApiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
Description: 'HttpApiGateway - API Gateway'
Name:
Fn::Join:
- "-"
- - !Ref AWS::StackName
Body:
swagger: '2.0'
info:
version: '2017-04-20T04:08:08Z'
title: HttpApiGateway
host:
Fn::Join:
- ''
- - apigateway.
- Ref: AWS::Region
- ".amazonaws.com"
basePath:
Fn::Join:
- ''
- - "/"
- !Ref Environment
schemes:
- https
x-amazon-apigateway-request-validators:
Passthrough:
validateRequestParameters: false
validateRequestBody: false
Validate body:
validateRequestParameters: false
validateRequestBody: true
Validate query string parameters and headers:
validateRequestParameters: true
validateRequestBody: false
x-amazon-apigateway-request-validator: Passthrough
paths:
/{proxy+}:
options:
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: 200 response
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: '200'
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: '{"statusCode": 200}'
passthroughBehavior: when_no_match
type: mock
x-amazon-apigateway-any-method:
consumes:
- application/json
produces:
- application/json
parameters:
- name: "proxy"
in: "path"
required: true
type: "string"
security:
- CognitoAuthorizer: []
responses:
'200':
description: 200 response
schema:
"$ref": "#/definitions/ResponseSchema"
x-amazon-apigateway-request-validator: Passthrough
x-amazon-apigateway-integration:
responses:
default:
statusCode: '200'
uri:
Fn::Join:
- ''
- - 'arn:aws:apigateway:'
- !Ref AWS::Region
- ":lambda:path/2015-03-31/functions/"
- !Ref LambdaFunctionArn
- "/invocations"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
# /user/{proxy+}:
# options:
# consumes:
# - application/json
# produces:
# - application/json
# responses:
# '200':
# description: 200 response
# headers:
# Access-Control-Allow-Origin:
# type: string
# Access-Control-Allow-Methods:
# type: string
# Access-Control-Allow-Headers:
# type: string
# x-amazon-apigateway-integration:
# responses:
# default:
# statusCode: '200'
# responseParameters:
# method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
# method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'"
# method.response.header.Access-Control-Allow-Origin: "'*'"
# requestTemplates:
# application/json: '{"statusCode": 200}'
# passthroughBehavior: when_no_match
# type: mock
# post:
# consumes:
# - application/json
# produces:
# - application/json
# parameters:
# - name: "proxy"
# in: "path"
# required: true
# type: "string"
# security:
# - CognitoAuthorizer: []
# responses:
# '200':
# description: 200 response
# schema:
# "$ref": "#/definitions/ResponseSchema"
# x-amazon-apigateway-request-validator: Passthrough
# x-amazon-apigateway-integration:
# responses:
# default:
# statusCode: '200'
# uri:
# Fn::Join:
# - ''
# - - 'arn:aws:apigateway:'
# - !Ref AWS::Region
# - ":lambda:path/2015-03-31/functions/"
# - !Ref LambdaFunctionArn
# - "/invocations"
# passthroughBehavior: when_no_match
# httpMethod: POST
# type: aws_proxy
securityDefinitions:
sigv4:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: awsSigv4
APIKeyAuthorizer:
type: apiKey
name: x-api-key
in: header
CognitoAuthorizer:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: cognito_user_pools
x-amazon-apigateway-authorizer:
type: cognito_user_pools
providerARNs:
- !Sub "arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/${CognitoUserPoolId}"
definitions:
RequestSchema:
type: object
required:
- data
properties:
data:
type: object
title: Request Schema
ResponseSchema:
type: object
required:
- data
properties:
data:
type: object
title: Response Schema
FailOnWarnings: true
HttpApiServerAPIGateWayDeployment:
DependsOn: HttpApiGateway
Type: AWS::ApiGateway::Deployment
Properties:
Description: The Development stage deployment of HttpApiGateway API.
StageName: !Ref Environment
RestApiId:
!Ref HttpApiGateway
HttpApiServerAPIGateWayUsagePlan:
DependsOn: HttpApiServerAPIGateWayDeployment
Type: AWS::ApiGateway::UsagePlan
Properties:
Description: The quota limits of HttpApiGateway API.
UsagePlanName: HttpApiGateway-DefaultPlan
ApiStages:
- ApiId: !Ref HttpApiGateway
Stage: !Ref Environment
Throttle:
BurstLimit: 100
RateLimit: 10
Quota:
Limit: 100
Period: "DAY"
HttpApiServerAPIGateWayApiKey:
DependsOn: HttpApiServerAPIGateWayDeployment
Type: AWS::ApiGateway::ApiKey
Properties:
Enabled: true
StageKeys:
- RestApiId: !Ref HttpApiGateway
StageName: !Ref Environment
Value: HttpApiGateway-55e39faadd193384379f1b59f399bf1068f05e48
HttpApiServerAPIGateWayUsagePlanKey:
DependsOn: HttpApiServerAPIGateWayApiKey
Type: AWS::ApiGateway::UsagePlanKey
Properties:
KeyId: !Ref HttpApiServerAPIGateWayApiKey
KeyType: API_KEY
UsagePlanId: !Ref HttpApiServerAPIGateWayUsagePlan
HttpApiServerLambdaApiGatewayPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunctionName
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn:
Fn::Join:
- ''
- - 'arn:aws:execute-api:'
- !Ref AWS::Region
- ":"
- !Ref AWS::AccountId
- ":"
- !Ref HttpApiGateway
- "/*/*/*"
HttpApiServerFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName:
Fn::Join:
- ""
- - '/aws/lambda/'
- !Ref LambdaFunctionName
RetentionInDays: 14
Outputs:
Region:
Value: !Ref AWS::Region
StackId:
Value: !Ref AWS::StackId
GatewayId:
Value: !Ref HttpApiGateway
Endpoint:
Value:
Fn::Join:
- ''
- - https://
- !Ref HttpApiGateway
- ".execute-api."
- !Ref AWS::Region
- ".amazonaws.com/"
- !Ref Environment