Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
add CF template for the blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
vini-eero committed Oct 26, 2021
1 parent acc22a0 commit 4fce4a8
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions blog-assets/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
AWSTemplateFormatVersion: '2010-09-09'

Description: AWS API Gateway working as a Service Virtualization

Resources:

RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
ApiKeySourceType: HEADER
Description: An API Gateway as Service Virtualization
EndpointConfiguration:
Types:
- EDGE
Name: mock-api

Resource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt RestApi.RootResourceId
PathPart: 'mock'
RestApiId: !Ref RestApi

GetMethod:
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: GET
RequestParameters:
method.request.querystring.method: true
MethodResponses:
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 200
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 201
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 500
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 503
Integration:
ConnectionType: INTERNET
IntegrationResponses:
- ResponseTemplates:
application/json: |
{
"statusCode": 200,
"message": "OK. No problem here."
}
StatusCode: 200
- ResponseTemplates:
application/json: |
{
"statusCode": 201,
"message": "Created. It appears to be good."
}
SelectionPattern: '201'
StatusCode: 201
- ResponseTemplates:
application/json: |
{
"statusCode": 500,
"message": "Internal Server Error. Houston, we have a problem."
}
SelectionPattern: '500'
StatusCode: 500
- ResponseTemplates:
application/json: |
{
"statusCode": 503,
"message": "Service Unavailable. I am not ready yet."
}
SelectionPattern: '503'
StatusCode: 503
PassthroughBehavior: WHEN_NO_TEMPLATES
RequestTemplates:
application/json: |
{
#if ( $input.params('method') == "ok" )
"statusCode": 200
#elseif ( $input.params('method') == "created" )
"statusCode": 201
#elseif ( $input.params('method') == "internalerror" )
"statusCode": 500
#else
"statusCode": 503
#end
}
Type: MOCK
TimeoutInMillis: 29000
OperationName: 'mock'
ResourceId: !Ref Resource
RestApiId: !Ref RestApi

PostMethod:
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: POST
MethodResponses:
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 200
- ResponseModels:
application/json: !Ref ApiGatewayModel
StatusCode: 500
Integration:
ConnectionType: INTERNET
IntegrationResponses:
- ResponseTemplates:
application/json: "{\"message\": \"OK. No problem here.\"}"
# SelectionPattern: '2\d{2}'
StatusCode: 200
- ResponseTemplates:
application/json: "{\"message\": \"Internal Server Error. Houston, we have a problem.\"}"
SelectionPattern: '5\d{2}'
StatusCode: 500
PassthroughBehavior: WHEN_NO_TEMPLATES
RequestTemplates:
application/json: |
{
"statusCode": $input.json('$.statusCode'),
"message": $input.json('$.message')
}
Type: MOCK
TimeoutInMillis: 29000
OperationName: 'mock'
ResourceId: !Ref Resource
RestApiId: !Ref RestApi

ApiGatewayModel:
Type: AWS::ApiGateway::Model
Properties:
ContentType: 'application/json'
RestApiId: !Ref RestApi
Schema: {}

ApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref ApiGatewayDeployment
Description: Mock API Stage v0
RestApiId: !Ref RestApi
StageName: 'v0'

ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- GetMethod
- PostMethod
Properties:
Description: Mock API Deployment
RestApiId: !Ref RestApi

0 comments on commit 4fce4a8

Please sign in to comment.