Amazon API Gateway Mock Integration built with CloudFormation: Difference between revisions
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
AWSTemplateFormatVersion: '2010-09-09' | |||
Description: | | |||
An API Gateway Stack. | |||
Parameters: | |||
ProjectID: | |||
Type: String | |||
Default: elysium | |||
Bucket: | |||
Type: String | |||
Description: | | |||
The name of the S3 bucket that will contain the OpenAPI AWS metadata file during stack creation. | |||
The content of the file will provide the API metadata. | |||
OpenApiAwsS3Key: | |||
Type: String | |||
Description: | | |||
The S3 key of the file that contains the OpenAPI AWS metadata. The S3 object is expected to be | |||
available in the ${Bucket} bucket. | |||
Resources: | |||
Api: | |||
Type: AWS::ApiGateway::RestApi | |||
Properties: | |||
Name: !Ref ProjectID | |||
Description: | | |||
A manually deployed API, used for experiments. If you are readin this, it means that it can be | |||
safely deleted. | |||
FailOnWarnings: true | |||
BodyS3Location: | |||
Bucket: !Ref Bucket | |||
Key: !Ref OpenApiAwsS3Key | |||
ApiDeployment: | |||
Type: AWS::ApiGateway::Deployment | |||
DependsOn: Api | |||
Properties: | |||
RestApiId: !Ref Api | |||
Description: | | |||
Deployment created as part of a CloudFormation stack. | |||
Stage: | |||
Type: AWS::ApiGateway::Stage | |||
DependsOn: | |||
- Api | |||
- ApiDeployment | |||
Properties: | |||
StageName: test | |||
RestApiId: !Ref Api | |||
DeploymentId: !Ref ApiDeployment | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 20:38, 27 March 2019
Internal
CloudFormation Stack
AWSTemplateFormatVersion: '2010-09-09'
Description: |
An API Gateway Stack.
Parameters:
ProjectID:
Type: String
Default: elysium
Bucket:
Type: String
Description: |
The name of the S3 bucket that will contain the OpenAPI AWS metadata file during stack creation.
The content of the file will provide the API metadata.
OpenApiAwsS3Key:
Type: String
Description: |
The S3 key of the file that contains the OpenAPI AWS metadata. The S3 object is expected to be
available in the ${Bucket} bucket.
Resources:
Api:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref ProjectID
Description: |
A manually deployed API, used for experiments. If you are readin this, it means that it can be
safely deleted.
FailOnWarnings: true
BodyS3Location:
Bucket: !Ref Bucket
Key: !Ref OpenApiAwsS3Key
ApiDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: Api
Properties:
RestApiId: !Ref Api
Description: |
Deployment created as part of a CloudFormation stack.
Stage:
Type: AWS::ApiGateway::Stage
DependsOn:
- Api
- ApiDeployment
Properties:
StageName: test
RestApiId: !Ref Api
DeploymentId: !Ref ApiDeployment
OpenAPI AWS Specification
---
swagger: "2.0"
info:
title: "elysium"
schemes:
- "https"
paths:
/a:
get:
consumes:
- "application/json"
produces:
- "application/json"
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_match"
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: "mock"
definitions:
Empty:
type: "object"
title: "Empty Schema"
Procedure
- Copy the OpenAPI AWS metadata file in S3.
- Deploy the stack:
aws cloudformation deploy --stack-name elysium