-
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
fix(apigateway): duplicate methodResponses if the same array is reused between addMethod calls #26636
Conversation
…esponses and Method methodResponses attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if methodOptions.methodResponses
is different between the two calls? Won't ignoring it the second time do something unexpected?
Wouldn't it be better to disallow the second call, and force you to add both methods in a single call?
@rix0rrr |
integrationResponses
integration option is ignored and passing methodOptions.methodResponses
to multiple addMethod
calls fails for duplicate values
I didn't understand why this would be happening because So I added more validation and as far as I can tell, we also have duplicate method responses even with a single integration? I have pushed my changes to this branch so you can see. Am I misunderstanding the API Gateway contract, or something else screwy going on? |
For example, I'm now seeing this error in a bunch of places:
Is this expected? |
Uh oh. It seems like the CloudFormation should have been rejecting this:
But didn't. But it does throw an error on duplicate entries in the array, because it's trying to convert them to a set and throws an error if that conversion is lossy. |
After looking into it a bit more, something entirely different is happening. In the code example, the
Since arrays are reference values, this leads to object sharing! Both the GET and POST method refer to the exact same array, and so the integration being executed twice adds the same elements to the same array, twice. Had the code been written like this: api.root.addMethod('POST', integration, {
methodResponses: [ ... ],
});
api.root.addMethod('GET', integration, {
methodResponses: [ ... ],
}); Both methods would have used a different That's the immediate problem. But there is another problem, that I alluded to before. If there are multiple So already doing the following: api.root.addMethod('Get', StepFunctionsIntegration.startExecution(machine, integrationOptions), {
methodResponses: [
statusCode: '200',
/* anything here */
]
}); Becomes a problem, because:
You now have multiple methodResponses with the same status code, and after deployment your API will end up with one of them, but not both. So the original use case of passing |
There are 2 problems here:
The
I pushed a tentative solution that should solve both issues. PS |
integrationResponses
integration option is ignored and passing methodOptions.methodResponses
to multiple addMethod
calls fails for duplicate values
I'm going to split this into 2 PRs:
After lunch 😉 |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Adding a new method to an API with
addMethod
and passingmethodOptions.methodResponses
was generating duplicate entries usingStepFunctionsIntegration.startExecution
as integration:For example:
Would generate (fails on deployment):
With this fix, it will keep only the specified
methodResponses
.Also, the
integrationResponses
option inStepFunctionsIntegration.startExecution
was not used by the correspondingIntegration
.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