Skip to content

Instantly share code, notes, and snippets.

@sihil
Created October 5, 2016 21:33
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sihil/93126ca8f319496c921a6077270fcd18 to your computer and use it in GitHub Desktop.
Save sihil/93126ca8f319496c921a6077270fcd18 to your computer and use it in GitHub Desktop.
Snippet of some CloudFormation resources for Plambda
API:
Type: AWS::ApiGateway::RestApi
Properties:
Name:
Fn::Join:
- " "
- - Restorer Plambda
- Ref: Stage
Description: Experimental Restorer Play app in Lambda
IndexGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Fn::GetAtt:
- API
- RootResourceId
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
text/html: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
- StatusCode: 303
ResponseParameters:
method.response.header.Location: true
RequestParameters:
method.request.header.Cookie: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
- SelectionPattern: status=303
StatusCode: 303
ResponseParameters:
method.response.header.Location: integration.response.body.stackTrace[0]
ResponseTemplates:
text/html: |
#set($errorRoot = $input.path('$.errorMessage'))
$inputRoot
PassthroughBehavior: WHEN_NO_TEMPLATES
ApiResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- API
- RootResourceId
PathPart: api
RestApiId:
Ref: API
ApiV1Resource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ApiResource
PathPart: 1
RestApiId:
Ref: API
ApiV1VersionListResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ApiV1Resource
PathPart: versionList
RestApiId:
Ref: API
ApiV1VersionListContentIdResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ApiV1VersionListResource
PathPart: "{contentId}"
RestApiId:
Ref: API
ApiV1VersionListContentIdGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Ref: ApiV1VersionListContentIdResource
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
application/json: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
- StatusCode: 303
ResponseParameters:
method.response.header.Location: true
RequestParameters:
method.request.header.Cookie: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
- SelectionPattern: status=303
StatusCode: 303
ResponseParameters:
method.response.header.Location: integration.response.body.stackTrace[0]
ResponseTemplates:
application/json: |
#set($errorRoot = $input.path('$.errorMessage'))
$inputRoot
PassthroughBehavior: WHEN_NO_TEMPLATES
ContentResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- API
- RootResourceId
PathPart: content
RestApiId:
Ref: API
ContentIdResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ContentResource
PathPart: "{contentId}"
RestApiId:
Ref: API
ContentIdVersionsResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ContentIdResource
PathPart: versions
RestApiId:
Ref: API
ContentIdVersionsGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Ref: ContentIdVersionsResource
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
text/html: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
- StatusCode: 303
ResponseParameters:
method.response.header.Location: true
RequestParameters:
method.request.header.Cookie: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
- SelectionPattern: status=303
StatusCode: 303
ResponseParameters:
method.response.header.Location: integration.response.body.stackTrace[0]
ResponseTemplates:
text/html: |
#set($errorRoot = $input.path('$.errorMessage'))
$inputRoot
PassthroughBehavior: WHEN_NO_TEMPLATES
ManagementResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- API
- RootResourceId
PathPart: management
RestApiId:
Ref: API
ManagementInfoResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ManagementResource
PathPart: info
RestApiId:
Ref: API
ManagementInfoGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Ref: ManagementInfoResource
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
text/plain: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
- StatusCode: 303
ResponseParameters:
method.response.header.Location: true
RequestParameters:
method.request.header.Cookie: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
- SelectionPattern: status=303
StatusCode: 303
ResponseParameters:
method.response.header.Location: integration.response.body.stackTrace[0]
ResponseTemplates:
text/plain: |
#set($errorRoot = $input.path('$.errorMessage'))
$inputRoot
PassthroughBehavior: WHEN_NO_TEMPLATES
ManagementHealthcheckResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: ManagementResource
PathPart: healthcheck
RestApiId:
Ref: API
ManagementHealthcheckGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Ref: ManagementHealthcheckResource
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
text/plain: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
PassthroughBehavior: WHEN_NO_TEMPLATES
AssetsResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- API
- RootResourceId
PathPart: assets
RestApiId:
Ref: API
AssetsItemResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: AssetsResource
PathPart: "{item}"
RestApiId:
Ref: API
AssetsNestedItemResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Ref: AssetsItemResource
PathPart: "{nestedItem}"
RestApiId:
Ref: API
AssetsItemGet:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId:
Ref: AssetsItemResource
RestApiId:
Ref: API
MethodResponses:
- StatusCode: 200
ResponseModels:
text/plain: Empty
ResponseParameters:
method.response.header.Content-Type: true
method.response.header.Content-Length: true
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ""
- - "arn:aws:apigateway:"
- Ref: AWS::Region
- :lambda:path/2015-03-31/functions/
- Fn::GetAtt:
- RestorerLambda
- Arn
- /invocations
RequestTemplates:
application/json: |
#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"uri" : "$context.resourcePath"
}
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Content-Type: integration.response.body.headers.Content-Type
method.response.header.Content-Length: integration.response.body.headers.Content-Length
ResponseTemplates:
application/json: |
$util.base64Decode( $input.path('$.body') )
PassthroughBehavior: WHEN_NO_TEMPLATES
APIDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
Description: CFN deployment 2016-09-08 22:47
RestApiId:
Ref: API
StageName:
Ref: Stage
DependsOn:
- ManagementHealthcheckGet
- ManagementInfoGet
- ContentIdVersionsGet
- ApiV1VersionListContentIdGet
- AssetsItemGet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment