-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
apigateway: Multiple StepFunctionsIntegrations with options lead to "Property MethodResponses contains duplicate values" #26586
Comments
Looks like it returns duplicate ResponseModels for
"MethodResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true
},
"StatusCode": "200"
},
{
"ResponseModels": {
"application/json": "Empty"
},
"StatusCode": "200"
},
{
"ResponseModels": {
"application/json": "Error"
},
"StatusCode": "400"
},
{
"ResponseModels": {
"application/json": "Error"
},
"StatusCode": "500"
},
{
"ResponseModels": {
"application/json": "Empty"
},
"StatusCode": "200"
},
{
"ResponseModels": {
"application/json": "Error"
},
"StatusCode": "400"
},
{
"ResponseModels": {
"application/json": "Error"
},
"StatusCode": "500"
}
], |
I'm not even sure the user's original request can even work. I just looked at the default integrationResponses of the {
statusCode: '200',
responseTemplates: {
/* eslint-disable */
'application/json': [
'#set($inputRoot = $input.path(\'$\'))',
'#if($input.path(\'$.status\').toString().equals("FAILED"))',
'#set($context.responseOverride.status = 500)',
'{',
'"error": "$input.path(\'$.error\')",',
'"cause": "$input.path(\'$.cause\')"',
'}',
'#else',
'$input.path(\'$.output\')',
'#end',
/* eslint-enable */
].join('\n'),
},
},
{
/**
* Specifies the regular expression (regex) pattern used to choose
* an integration response based on the response from the back end.
* In this case it will match all '4XX' HTTP Errors
*/
selectionPattern: '4\\d{2}',
statusCode: '400',
responseTemplates: {
'application/json': `{
"error": "Bad request!"
}`,
},
},
{
/**
* Match all '5XX' HTTP Errors
*/
selectionPattern: '5\\d{2}',
statusCode: '500',
responseTemplates: {
'application/json': '"error": $input.path(\'$.error\')',
},
}, I'm pretty sure that as soon as you pass this: const integrationOptions = {
integrationResponses: [
{ /* ... */ }
],
};
api.root.addMethod('POST', StepFunctionsIntegration.startExecution(machine, integrationOptions), methodOptions) You completely override the built-in integrationOptions and you have to rebuild all that Velocity templating. I have prepared 2 different PRs to take a stab at this:
I'm open to making this work in a nice way because it seems useful, but I would like some design input from someone with API Gateway experience before making any choices here. |
…d between addMethod calls (#26636) Adding a new method to an API with `addMethod` and passing `methodOptions.methodResponses` was generating duplicate entries using `StepFunctionsIntegration.startExecution` as integration: For example: ``` const integ = apigw.StepFunctionsIntegration.startExecution(stateMachine, integrationOptions); api.root.addMethod('GET', integ, methodOptions); api.root.addMethod('POST', integ, methodOptions); ``` Would generate (fails on deployment): ``` "MethodResponses": [ { "ResponseParameters": { "method.response.header.Access-Control-Allow-Origin": true }, "StatusCode": "200" }, { "ResponseModels": { "application/json": "Empty" }, "StatusCode": "200" }, { "ResponseModels": { "application/json": "Error" }, "StatusCode": "400" }, { "ResponseModels": { "application/json": "Error" }, "StatusCode": "500" }, { "ResponseModels": { "application/json": "Empty" }, "StatusCode": "200" }, { "ResponseModels": { "application/json": "Error" }, "StatusCode": "400" }, { "ResponseModels": { "application/json": "Error" }, "StatusCode": "500" } ], ``` With this fix, it will keep only the specified `methodResponses`. Also, the `integrationResponses` option in `StepFunctionsIntegration.startExecution` was not used by the corresponding `Integration`. This fix will allow to use the specified option value. Closes #26586. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
@rix0rrr I'm facing the issue you addressed in your PR: https://github.com/aws/aws-cdk/pull/26720/files |
Describe the bug
Using the
StepFunctionsIntegration.startExecution()
integration with API Gateway with cors options (see reproduction steps) works, as long as only one method has the integration with options.If a second method uses the same options you will get the error
The stack named TestStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Property MethodResponses contains duplicate values., Property MethodResponses contains duplicate values.
and in the cdk.out it generates multipleResponseModels
.Expected Behavior
Multiple methods with the
StepFunctionsIntegration.startExecution()
creates methods with individual options.Current Behavior
Reproduction Steps
dk init app --language typescript
cdk deploy --require-approval never
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.89.0 (build 2ad6683)
Framework Version
No response
Node.js Version
v20.5.0
OS
macOS 13.5
Language
Typescript
Language Version
TypeScript (5.1.6)
Other information
No response
The text was updated successfully, but these errors were encountered: