Skip to content

Instantly share code, notes, and snippets.

@daaru00
Created March 4, 2024 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daaru00/423725d838acdc117413df95497543e7 to your computer and use it in GitHub Desktop.
Save daaru00/423725d838acdc117413df95497543e7 to your computer and use it in GitHub Desktop.
API Gateway mocked API example template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Mocked HTTP API
Parameters:
ThrottlingRateLimit:
Type: Number
Description: The rate limit for the mock API.
Default: 1
ThrottlingBurstLimit:
Type: Number
Description: The burst limit for the mock API.
Default: 5
Resources:
MockedApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub "${AWS::StackName}-mocked"
StageName: api
GatewayResponses:
DEFAULT_4XX:
StatusCode: 403
ResponseTemplates:
"text/plain": "Unauthorized"
RESOURCE_NOT_FOUND:
StatusCode: 404
ResponseTemplates:
"text/plain": "Not Found"
THROTTLED:
StatusCode: 429
ResponseTemplates:
"text/plain": "Request Throttled"
DEFAULT_5XX:
StatusCode: 500
ResponseTemplates:
"text/plain": "Internal Server Error"
MethodSettings:
- ResourcePath: "/*"
HttpMethod: "*"
ThrottlingRateLimit: !Ref MockApiThrottlingRateLimit
ThrottlingBurstLimit: !Ref MockApiThrottlingBurstLimit
DefinitionBody:
swagger: 2.0
info:
title: "Mocked API"
schemes:
- "https"
paths:
/:
put:
produces:
- "application/json"
responses:
"200":
description: "OK"
x-amazon-apigateway-integration:
type: "mock"
requestTemplates:
application/json: |
{
"statusCode": 200
}
responses:
default:
statusCode: "200"
responseTemplates:
application/json: |
{
"id": "example"
}
/{id}:
get:
produces:
- "application/json"
responses:
"200":
description: "OK"
x-amazon-apigateway-integration:
type: "mock"
requestTemplates:
application/json: |
{
"statusCode": 200
}
responses:
default:
statusCode: "200"
responseTemplates:
application/json: |
{
"id": "example",
"sku": "example",
"name": "Example",
"description": "This is an example",
"price": 15.49
}
post:
produces:
- "application/json"
responses:
"200":
description: "OK"
"404":
description: "Bad Request"
x-amazon-apigateway-integration:
type: "mock"
requestTemplates:
application/json: |
{
"statusCode": 200
}
responses:
default:
statusCode: "200"
responseTemplates:
application/json: |
{
"id": "example"
}
Outputs:
ApiEndpoint:
Description: "The REST API endpoint to query data"
Value: !Sub "https://${MockedApi}.execute-api.${AWS::Region}.amazonaws.com/api/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment