Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apigateway): duplicate methodResponses if the same array is reused between addMethod calls #26636

Merged
merged 11 commits into from
Aug 17, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "33.0.0",
"files": {
"8cbe12776c2bea21b28f7f29c548b0d830b9c92d7f8f93dc5fe6047a274592bc": {
"source": {
"path": "aws-cdk-aws-apigateway-stepfunctions-startexecution.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "8cbe12776c2bea21b28f7f29c548b0d830b9c92d7f8f93dc5fe6047a274592bc.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,358 @@
{
"Resources": {
"myrestapiBAC2BF45": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "my-rest-api"
}
},
"myrestapiDeployment010A9D4F59b46296e944eb988c600755d169a00d": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Automatically created by the RestApi construct",
"RestApiId": {
"Ref": "myrestapiBAC2BF45"
}
},
"DependsOn": [
"myrestapiGET3A49A218",
"myrestapiPOST155A9625"
]
},
"myrestapiDeploymentStageprod3140E1BE": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "myrestapiDeployment010A9D4F59b46296e944eb988c600755d169a00d"
},
"RestApiId": {
"Ref": "myrestapiBAC2BF45"
},
"StageName": "prod"
}
},
"myrestapiGETStartSyncExecutionRoleC284C05B": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"myrestapiGETStartSyncExecutionRoleDefaultPolicy8B2F6ADF": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "states:StartSyncExecution",
"Effect": "Allow",
"Resource": {
"Ref": "StateMachine2E01A3A5"
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "myrestapiGETStartSyncExecutionRoleDefaultPolicy8B2F6ADF",
"Roles": [
{
"Ref": "myrestapiGETStartSyncExecutionRoleC284C05B"
}
]
}
},
"myrestapiGET3A49A218": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
"HttpMethod": "GET",
"Integration": {
"Credentials": {
"Fn::GetAtt": [
"myrestapiGETStartSyncExecutionRoleC284C05B",
"Arn"
]
},
"IntegrationHttpMethod": "POST",
"IntegrationResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
},
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": {
"Fn::Join": [
"",
[
"## Velocity Template used for API Gateway request mapping template\n##\n## This template forwards the request body, header, path, and querystring\n## to the execution input of the state machine.\n##\n## \"@@\" is used here as a placeholder for '\"' to avoid using escape characters.\n\n#set($inputString = '')\n#set($includeHeaders = false)\n#set($includeQueryString = true)\n#set($includePath = true)\n#set($includeAuthorizer = false)\n#set($allParams = $input.params())\n{\n \"stateMachineArn\": \"",
{
"Ref": "StateMachine2E01A3A5"
},
"\",\n\n #set($inputString = \"$inputString,@@body@@: $input.body\")\n\n #if ($includeHeaders)\n #set($inputString = \"$inputString, @@header@@:{\")\n #foreach($paramName in $allParams.header.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.header.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n \n #end\n\n #if ($includeQueryString)\n #set($inputString = \"$inputString, @@querystring@@:{\")\n #foreach($paramName in $allParams.querystring.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.querystring.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #if ($includePath)\n #set($inputString = \"$inputString, @@path@@:{\")\n #foreach($paramName in $allParams.path.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.path.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n \n #if ($includeAuthorizer)\n #set($inputString = \"$inputString, @@authorizer@@:{\")\n #foreach($paramName in $context.authorizer.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($context.authorizer.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #set($requestContext = \"\")\n ## Check if the request context should be included as part of the execution input\n #if($requestContext && !$requestContext.empty)\n #set($inputString = \"$inputString,\")\n #set($inputString = \"$inputString @@requestContext@@: $requestContext\")\n #end\n\n #set($inputString = \"$inputString}\")\n #set($inputString = $inputString.replaceAll(\"@@\",'\"'))\n #set($len = $inputString.length() - 1)\n \"input\": \"{$util.escapeJavaScript($inputString.substring(1,$len)).replaceAll(\"\\\\'\",\"'\")}\"\n}\n"
]
]
}
},
"Type": "AWS",
"Uri": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
":states:action/StartSyncExecution"
]
]
}
},
"MethodResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true
},
"StatusCode": "200"
}
],
"ResourceId": {
"Fn::GetAtt": [
"myrestapiBAC2BF45",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "myrestapiBAC2BF45"
}
}
},
"myrestapiPOSTStartSyncExecutionRole7AFBE835": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"myrestapiPOSTStartSyncExecutionRoleDefaultPolicy7D411AE9": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "states:StartSyncExecution",
"Effect": "Allow",
"Resource": {
"Ref": "StateMachine2E01A3A5"
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "myrestapiPOSTStartSyncExecutionRoleDefaultPolicy7D411AE9",
"Roles": [
{
"Ref": "myrestapiPOSTStartSyncExecutionRole7AFBE835"
}
]
}
},
"myrestapiPOST155A9625": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
"HttpMethod": "POST",
"Integration": {
"Credentials": {
"Fn::GetAtt": [
"myrestapiPOSTStartSyncExecutionRole7AFBE835",
"Arn"
]
},
"IntegrationHttpMethod": "POST",
"IntegrationResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
},
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": {
"Fn::Join": [
"",
[
"## Velocity Template used for API Gateway request mapping template\n##\n## This template forwards the request body, header, path, and querystring\n## to the execution input of the state machine.\n##\n## \"@@\" is used here as a placeholder for '\"' to avoid using escape characters.\n\n#set($inputString = '')\n#set($includeHeaders = false)\n#set($includeQueryString = true)\n#set($includePath = true)\n#set($includeAuthorizer = false)\n#set($allParams = $input.params())\n{\n \"stateMachineArn\": \"",
{
"Ref": "StateMachine2E01A3A5"
},
"\",\n\n #set($inputString = \"$inputString,@@body@@: $input.body\")\n\n #if ($includeHeaders)\n #set($inputString = \"$inputString, @@header@@:{\")\n #foreach($paramName in $allParams.header.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.header.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n \n #end\n\n #if ($includeQueryString)\n #set($inputString = \"$inputString, @@querystring@@:{\")\n #foreach($paramName in $allParams.querystring.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.querystring.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #if ($includePath)\n #set($inputString = \"$inputString, @@path@@:{\")\n #foreach($paramName in $allParams.path.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.path.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n \n #if ($includeAuthorizer)\n #set($inputString = \"$inputString, @@authorizer@@:{\")\n #foreach($paramName in $context.authorizer.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($context.authorizer.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #set($requestContext = \"\")\n ## Check if the request context should be included as part of the execution input\n #if($requestContext && !$requestContext.empty)\n #set($inputString = \"$inputString,\")\n #set($inputString = \"$inputString @@requestContext@@: $requestContext\")\n #end\n\n #set($inputString = \"$inputString}\")\n #set($inputString = $inputString.replaceAll(\"@@\",'\"'))\n #set($len = $inputString.length() - 1)\n \"input\": \"{$util.escapeJavaScript($inputString.substring(1,$len)).replaceAll(\"\\\\'\",\"'\")}\"\n}\n"
]
]
}
},
"Type": "AWS",
"Uri": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":apigateway:",
{
"Ref": "AWS::Region"
},
":states:action/StartSyncExecution"
]
]
}
},
"MethodResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true
},
"StatusCode": "200"
}
],
"ResourceId": {
"Fn::GetAtt": [
"myrestapiBAC2BF45",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "myrestapiBAC2BF45"
}
}
},
"StateMachineRoleB840431D": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "states.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"StateMachine2E01A3A5": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"DefinitionString": "{\"StartAt\":\"passTask\",\"States\":{\"passTask\":{\"Type\":\"Pass\",\"InputPath\":\"$.somekey\",\"End\":true}}}",
"RoleArn": {
"Fn::GetAtt": [
"StateMachineRoleB840431D",
"Arn"
]
},
"StateMachineType": "EXPRESS"
},
"DependsOn": [
"StateMachineRoleB840431D"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
},
"Outputs": {
"myrestapiEndpoint0DE8A5DE": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "myrestapiBAC2BF45"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "myrestapiDeploymentStageprod3140E1BE"
},
"/"
]
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Loading