cfn-api-gateway-integration-response
Version:
Custom::ApiGatewayIntegrationResponse | AWS CloudFormation Custom Lambda Resource | API Gateway IntegrationResponse
610 lines (609 loc) • 15.3 kB
JSON
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Custom::ApiGatewayIntegrationResponse sample template",
"Parameters": {
"RestApiCustomResourceLambdaName": {
"Type": "String",
"Default": "cfn-api-gateway-restapi-0-6-1",
"Description": "The name of the ApiGatewayRestApi Lambda you deployed to test this stack."
},
"RestApiName": {
"Type": "String",
"Description": "Name for the API (required). Must be unique across your account for this Region.",
"Default": "TestForIntegrationResponse0-2-0"
},
"RestApiDescription": {
"Type": "String",
"Description": "Description for the API (optional)."
},
"RestApiBaseApiId": {
"Type": "String",
"Description": "API ID (not name, not ARN) from which to clone the base for the new API (optional). WARNING: Changing this value requires full replacement."
},
"MethodCustomResourceLambdaName": {
"Type": "String",
"Default": "cfn-api-gateway-method-0-3-0",
"Description": "The name of the ApiGatewayMethod Lambda you deployed to test this stack."
},
"MethodAuthorizationType": {
"Type": "String",
"Default": "NONE",
"Description": "Whether or not to require IAM authorization to invoke the method.",
"AllowedValues": [
"NONE",
"AWS_IAM"
]
},
"MethodHttpMethod": {
"Type": "String",
"Default": "GET",
"Description": "The HTTP method your deployed Method should use.",
"AllowedValues": [
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PATCH",
"POST",
"PUT"
]
},
"MyMethodMainStatusCode": {
"Type": "String",
"AllowedPattern": "^\\d{3}$",
"Default": "200",
"Description": "The HTTP status code for the method we are trying out here."
},
"DoesMethodRequireApiKey": {
"Type": "String",
"Default": "NO",
"Description": "Whether or not to require use of an API Key on the created method.",
"AllowedValues": [
"NO",
"YES"
]
},
"MethodResponseCustomResourceLambdaName": {
"Type": "String",
"Default": "cfn-api-gateway-method-response-0-2-0",
"Description": "The name of the ApiGatewayMethodResponse Lambda you deployed to test this stack."
},
"IntegrationCustomResourceLambdaName": {
"Type": "String",
"Default": "cfn-api-gateway-integration-0-2-0",
"Description": "The name of the ApiGatewayIntegration Lambda you deployed to test this stack."
},
"IntegrationResponseCustomResourceLambdaName": {
"Type": "String",
"Default": "cfn-api-gateway-integration-response-0-2-1",
"Description": "The name of the ApiGatewayIntegrationResponse Lambda you deployed to test this stack."
}
},
"Conditions": {
"NoApiDescription": {
"Fn::Equals": [
"",
{
"Ref": "RestApiDescription"
}
]
},
"NoApiBaseApiId": {
"Fn::Equals": [
"",
{
"Ref": "RestApiBaseApiId"
}
]
},
"MethodRequiresApiKey": {
"Fn::Equals": [
"YES",
{
"Ref": "DoesMethodRequireApiKey"
}
]
}
},
"Resources": {
"MyRestApi": {
"Type": "Custom::ApiGatewayRestApi",
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "RestApiCustomResourceLambdaName"
}
]
]
},
"Name": {
"Ref": "RestApiName"
},
"Description": {
"Fn::If": [
"NoApiDescription",
{
"Ref": "AWS::NoValue"
},
{
"Ref": "RestApiDescription"
}
]
},
"BaseApiId": {
"Fn::If": [
"NoApiBaseApiId",
{
"Ref": "AWS::NoValue"
},
{
"Ref": "RestApiBaseApiId"
}
]
}
}
},
"MyMethod": {
"DependsOn": [
"MyRestApi"
],
"Type": "Custom::ApiGatewayMethod",
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "MethodCustomResourceLambdaName"
}
]
]
},
"ApiKeyRequired": {
"Fn::If": [
"MethodRequiresApiKey",
true,
false
]
},
"AuthorizationType": {
"Ref": "MethodAuthorizationType"
},
"HttpMethod": {
"Ref": "MethodHttpMethod"
},
"ResourceId": {
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "MyRestApi"
},
"RequestModels": {
"application/json": "Empty"
},
"RequestParameters": {
"method.request.querystring.MapMe": true
}
}
},
"MyMethodResponseOk": {
"DependsOn": [
"MyRestApi",
"MyMethod"
],
"Type": "Custom::ApiGatewayMethodResponse",
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "MethodResponseCustomResourceLambdaName"
}
]
]
},
"StatusCode": {
"Ref": "MyMethodMainStatusCode"
},
"HttpMethod": {
"Ref": "MethodHttpMethod"
},
"ResourceId": {
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "MyRestApi"
},
"ResponseModels": {
"application/json": "Empty"
},
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true,
"method.response.header.Access-Control-Allow-Methods": true
}
}
},
"MyIntegration": {
"DependsOn": [
"MyRestApi",
"MyMethod",
"MyMethodResponseOk",
"IntegrationLambda",
"IntegrationCredentialsRole"
],
"Type": "Custom::ApiGatewayIntegration",
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "IntegrationCustomResourceLambdaName"
}
]
]
},
"Type": "AWS",
"HttpMethod": {
"Ref": "MethodHttpMethod"
},
"IntegrationHttpMethod": "POST",
"ResourceId": {
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "MyRestApi"
},
"Uri": {
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Fn::GetAtt": [
"IntegrationLambda",
"Arn"
]
},
"/invocations"
]
]
},
"Credentials": {
"Fn::GetAtt": [
"IntegrationCredentialsRole",
"Arn"
]
},
"RequestTemplates": {
"application/json": {
"Fn::Join": [
"\n",
[
"{",
" \"hello\": \"world\",",
" \"MapMeFromHeader\": \"$input.params().querystring.get('MapMe')\"",
"}"
]
]
}
},
"RequestParameters": {
"integration.request.querystring.MapMe": "method.request.querystring.MapMe"
}
}
},
"IntegrationLambda": {
"DependsOn": [
"IntegrationLambdaExecutionRole"
],
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": {
"Fn::Join": [
"\n",
[
"exports.handler = function(event, context) {",
" console.log('The debugging Lambda was called.');",
" console.log('Event: %j', event);",
" console.log('Context: %j', context);",
" event.addedProperty = 'addedValue';",
" context.succeed(event);",
"};"
]
]
}
},
"Description": "Lambda to integrate test asset with.",
"Handler": "index.handler",
"MemorySize": 128,
"Role": {
"Fn::GetAtt": [
"IntegrationLambdaExecutionRole",
"Arn"
]
},
"Runtime": "nodejs",
"Timeout": 300
}
},
"IntegrationCredentialsRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"apigateway.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": {
"Fn::Join": [
"",
[
"IntegrationCredentialsRole",
{
"Ref": "AWS::StackName"
}
]
]
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "*"
}
]
}
}
]
}
},
"IntegrationLambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": {
"Fn::Join": [
"",
[
"IntegrationLambdaExecutionRole",
{
"Ref": "AWS::StackName"
}
]
]
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:*"
}
]
}
}
]
}
},
"MyIntegrationResponse": {
"DependsOn": [
"MyRestApi",
"MyMethod",
"MyMethodResponseOk",
"MyIntegration"
],
"Type": "Custom::ApiGatewayIntegrationResponse",
"Properties": {
"ServiceToken": {
"Fn::Join": [
":",
[
"arn",
"aws",
"lambda",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"function",
{
"Ref": "IntegrationResponseCustomResourceLambdaName"
}
]
]
},
"StatusCode": {
"Ref": "MyMethodMainStatusCode"
},
"RestApiId": {
"Ref": "MyRestApi"
},
"HttpMethod": {
"Ref": "MethodHttpMethod"
},
"ResourceId": {
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
},
"SelectionPattern": ".*",
"ResponseTemplates": {
"application/json": {
"Fn::Join": [
"\n",
[
"{",
" \"hoistedResponse\": $input.json('$')",
"}"
]
]
}
},
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'",
"method.response.header.Access-Control-Allow-Methods": {
"Fn::Join": [
"",
[
"",
"'",
{
"Ref": "MethodHttpMethod"
},
", OPTIONS",
"'"
]
]
}
}
}
}
},
"Outputs": {
"MyRestApiId": {
"Description": "The unique ID value across your entire account for the created API.",
"Value": {
"Ref": "MyRestApi"
}
},
"MyRestApiRootResource": {
"Description": "The 10 char alphanum ID of the / resource for MyRestApi",
"Value": {
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
}
},
"MyMethodConsoleUrl": {
"Description": "The AWS Console URL for inspecting the created method.",
"Value": {
"Fn::Join": [
"",
[
"https://console.aws.amazon.com/apigateway/home?region=",
{
"Ref": "AWS::Region"
},
"#/restapis/",
{
"Ref": "MyRestApi"
},
"/resources/",
{
"Fn::GetAtt": [
"MyRestApi",
"RootResourceId"
]
},
"/methods/",
{
"Ref": "MethodHttpMethod"
}
]
]
}
}
}
}