Skip to content

Commit 22a3234

Browse files
authored
feat(apigateway): add useDefaultMethodResponses property for StepFunctionsIntegrations (#27645)
In `StepFunctionsIntegration`, method response models (`methodResponses`) with 200, 400 and 500 status codes are added by default. This PR adds `useDefaultMethodResponses` property not to add default method response models by set it to `false`. Closes #27520. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0deed4d commit 22a3234

23 files changed

+2148
-3
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/SfnRestApiWithoutDefaultMethodResponses.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"Resources": {
3+
"StateMachineRoleB840431D": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "states.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
}
18+
}
19+
},
20+
"StateMachine2E01A3A5": {
21+
"Type": "AWS::StepFunctions::StateMachine",
22+
"Properties": {
23+
"DefinitionString": "{\"StartAt\":\"PassTask\",\"States\":{\"PassTask\":{\"Type\":\"Pass\",\"Result\":\"Hello\",\"End\":true}}}",
24+
"RoleArn": {
25+
"Fn::GetAtt": [
26+
"StateMachineRoleB840431D",
27+
"Arn"
28+
]
29+
},
30+
"StateMachineType": "EXPRESS"
31+
},
32+
"DependsOn": [
33+
"StateMachineRoleB840431D"
34+
],
35+
"UpdateReplacePolicy": "Delete",
36+
"DeletionPolicy": "Delete"
37+
},
38+
"StepFunctionsRestApiC6E3E883": {
39+
"Type": "AWS::ApiGateway::RestApi",
40+
"Properties": {
41+
"Name": "StepFunctionsRestApi"
42+
}
43+
},
44+
"StepFunctionsRestApiDeployment8FF8D52A481e2c6fad35132b46721c49969398fb": {
45+
"Type": "AWS::ApiGateway::Deployment",
46+
"Properties": {
47+
"Description": "Automatically created by the RestApi construct",
48+
"RestApiId": {
49+
"Ref": "StepFunctionsRestApiC6E3E883"
50+
}
51+
},
52+
"DependsOn": [
53+
"StepFunctionsRestApiANY7699CA92"
54+
]
55+
},
56+
"StepFunctionsRestApiDeploymentStageprodE1E3545E": {
57+
"Type": "AWS::ApiGateway::Stage",
58+
"Properties": {
59+
"DeploymentId": {
60+
"Ref": "StepFunctionsRestApiDeployment8FF8D52A481e2c6fad35132b46721c49969398fb"
61+
},
62+
"RestApiId": {
63+
"Ref": "StepFunctionsRestApiC6E3E883"
64+
},
65+
"StageName": "prod"
66+
}
67+
},
68+
"StepFunctionsRestApiANYStartSyncExecutionRole425C03BB": {
69+
"Type": "AWS::IAM::Role",
70+
"Properties": {
71+
"AssumeRolePolicyDocument": {
72+
"Statement": [
73+
{
74+
"Action": "sts:AssumeRole",
75+
"Effect": "Allow",
76+
"Principal": {
77+
"Service": "apigateway.amazonaws.com"
78+
}
79+
}
80+
],
81+
"Version": "2012-10-17"
82+
}
83+
}
84+
},
85+
"StepFunctionsRestApiANYStartSyncExecutionRoleDefaultPolicy7B6D0CED": {
86+
"Type": "AWS::IAM::Policy",
87+
"Properties": {
88+
"PolicyDocument": {
89+
"Statement": [
90+
{
91+
"Action": "states:StartSyncExecution",
92+
"Effect": "Allow",
93+
"Resource": {
94+
"Ref": "StateMachine2E01A3A5"
95+
}
96+
}
97+
],
98+
"Version": "2012-10-17"
99+
},
100+
"PolicyName": "StepFunctionsRestApiANYStartSyncExecutionRoleDefaultPolicy7B6D0CED",
101+
"Roles": [
102+
{
103+
"Ref": "StepFunctionsRestApiANYStartSyncExecutionRole425C03BB"
104+
}
105+
]
106+
}
107+
},
108+
"StepFunctionsRestApiANY7699CA92": {
109+
"Type": "AWS::ApiGateway::Method",
110+
"Properties": {
111+
"AuthorizationType": "NONE",
112+
"HttpMethod": "ANY",
113+
"Integration": {
114+
"Credentials": {
115+
"Fn::GetAtt": [
116+
"StepFunctionsRestApiANYStartSyncExecutionRole425C03BB",
117+
"Arn"
118+
]
119+
},
120+
"IntegrationHttpMethod": "POST",
121+
"IntegrationResponses": [
122+
{
123+
"ResponseTemplates": {
124+
"application/json": "#set($inputRoot = $input.path('$'))\n#if($input.path('$.status').toString().equals(\"FAILED\"))\n#set($context.responseOverride.status = 500)\n{\n\"error\": \"$input.path('$.error')\",\n\"cause\": \"$input.path('$.cause')\"\n}\n#else\n$input.path('$.output')\n#end"
125+
},
126+
"StatusCode": "200"
127+
},
128+
{
129+
"ResponseTemplates": {
130+
"application/json": "{\n \"error\": \"Bad request!\"\n }"
131+
},
132+
"SelectionPattern": "4\\d{2}",
133+
"StatusCode": "400"
134+
},
135+
{
136+
"ResponseTemplates": {
137+
"application/json": "\"error\": $input.path('$.error')"
138+
},
139+
"SelectionPattern": "5\\d{2}",
140+
"StatusCode": "500"
141+
}
142+
],
143+
"PassthroughBehavior": "NEVER",
144+
"RequestTemplates": {
145+
"application/json": {
146+
"Fn::Join": [
147+
"",
148+
[
149+
"## 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\": \"",
150+
{
151+
"Ref": "StateMachine2E01A3A5"
152+
},
153+
"\",\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"
154+
]
155+
]
156+
}
157+
},
158+
"Type": "AWS",
159+
"Uri": {
160+
"Fn::Join": [
161+
"",
162+
[
163+
"arn:",
164+
{
165+
"Ref": "AWS::Partition"
166+
},
167+
":apigateway:",
168+
{
169+
"Ref": "AWS::Region"
170+
},
171+
":states:action/StartSyncExecution"
172+
]
173+
]
174+
}
175+
},
176+
"ResourceId": {
177+
"Fn::GetAtt": [
178+
"StepFunctionsRestApiC6E3E883",
179+
"RootResourceId"
180+
]
181+
},
182+
"RestApiId": {
183+
"Ref": "StepFunctionsRestApiC6E3E883"
184+
}
185+
}
186+
}
187+
},
188+
"Outputs": {
189+
"StepFunctionsRestApiEndpoint0DD66FCB": {
190+
"Value": {
191+
"Fn::Join": [
192+
"",
193+
[
194+
"https://",
195+
{
196+
"Ref": "StepFunctionsRestApiC6E3E883"
197+
},
198+
".execute-api.",
199+
{
200+
"Ref": "AWS::Region"
201+
},
202+
".",
203+
{
204+
"Ref": "AWS::URLSuffix"
205+
},
206+
"/",
207+
{
208+
"Ref": "StepFunctionsRestApiDeploymentStageprodE1E3545E"
209+
},
210+
"/"
211+
]
212+
]
213+
}
214+
},
215+
"ApiEndpoint": {
216+
"Value": {
217+
"Fn::Join": [
218+
"",
219+
[
220+
"https://",
221+
{
222+
"Ref": "StepFunctionsRestApiC6E3E883"
223+
},
224+
".execute-api.",
225+
{
226+
"Ref": "AWS::Region"
227+
},
228+
".",
229+
{
230+
"Ref": "AWS::URLSuffix"
231+
},
232+
"/",
233+
{
234+
"Ref": "StepFunctionsRestApiDeploymentStageprodE1E3545E"
235+
},
236+
"/"
237+
]
238+
]
239+
}
240+
}
241+
},
242+
"Parameters": {
243+
"BootstrapVersion": {
244+
"Type": "AWS::SSM::Parameter::Value<String>",
245+
"Default": "/cdk-bootstrap/hnb659fds/version",
246+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
247+
}
248+
},
249+
"Rules": {
250+
"CheckBootstrapVersion": {
251+
"Assertions": [
252+
{
253+
"Assert": {
254+
"Fn::Not": [
255+
{
256+
"Fn::Contains": [
257+
[
258+
"1",
259+
"2",
260+
"3",
261+
"4",
262+
"5"
263+
],
264+
{
265+
"Ref": "BootstrapVersion"
266+
}
267+
]
268+
}
269+
]
270+
},
271+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
272+
}
273+
]
274+
}
275+
}
276+
}

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/integ.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)