Open namachieli opened 3 years ago
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.
If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!
Unless this has been solved, I think this issue should stay open.
Community Note
Terraform CLI and Terraform AWS Provider Version
Affected Resource(s)
aws_api_gateway_deployment
Terraform Configuration Files
Since funkiness with
aws_api_gateway_deployment
is well known, I'm just adding the relevant bit.Expected Behavior
The API Gateway should deploy the stage, and the invoke URL works completely to trigger the backend lambda, and return a HTTP200 to the client.
Output from workaround
Actual Behavior
Invoking the stage's invoke URL correctly passes the BODY of the request to the lambda and is processed correctly by lambda. (evidenced by cloudwatch logs and lambda outputs). However, the invoking client receives an HTTP 500.
Output before workaround
Steps to Reproduce
aws_api_gateway_deployment
andaws_api_gateway_stage
to deploy the api stageYou can easily toggle the deployment from TF and the manual deployment in API > Stages > Deployment History
Why is this a race condition?
The problem isn't about what terraform attempts to create, its WHEN it attempts to create it. By manually deploying after terraform apply, you are just doing the same thing as TF did, except every resource has been fully built and linked internally within AWS.
A workaround is to simply add:
This 5s pause allows something on the AWS backend to finish existing in time for the deployment to build correctly. There is likely a lot of other background issues contributing to this, but its easy to call it a race condition since its solvable with a pause.
I also tried moving the dependency logic to the deployment happens normally, but have the time delay gate the
aws_api_gateway_stage
resource. This always results in the race condition failure so I strongly believed its tied toaws_api_gateway_deployment
References
This lambda and the effective TF config is based on the POC from https://oozio.medium.com/serverless-discord-bot-55f95f26f743.
I am willing to provide a sanitized complete TF if required.