Closed MagnusBrzenk closed 4 years ago
In case anyone else struggles with this, I managed to fix the problem by:
terraform plan
and carefully inspecting the differences between what was provisioned by my manual actions and what would be provisioned were I to run my terraform scripts again (and making appropriate changes to my terraform scripts).It appears that the key difference between working and breaking was adding:
request_templates = {
"application/json" = jsonencode(
{
statusCode = 200
}
)
}
to my resource "aws_api_gateway_integration" "options_integration"
block. I'm glad I got this working but I'm also a bit disconcerted by how (1) far from obvious this was, and (2) the fact that this essential block was not recommended in any template/demo I came across. (And this essentially all pieced together from templates offered on the terraform website.)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Terraform Configuration Files
I'm building an aws-lambda-emailer service through api gateway. My terraform scripts for provisioning are here
Expected Behavior
Post requests submitted from a browser will succeed.
Actual Behavior
The browser will first perform an OPTIONS request to check that CORS is enabled before following up with a POST request. I attempt to provision such an OPTIONS request from the lambda_api.tf file with
{status_code: 200}
. However, when this options method is called, API Gateway will encounter a{statusCode: 500}
server error with the following message:And since this error response does not have headers enabling CORS, the browser will fail to do a follow-up POST request (and the whole thing fails).
So it seems that terraform is causing the value of the statusCode in AWS to be set with a non-integer. I am totally stumped why this is happening.
Steps to Reproduce
npm i
cp .env-template .env
and edit variables (you'll need to use emails verified with AWS SES if you want to test the entire api-lambda-ses pipeline)terraform init terraform/lambda_emailer
./_run_terraform 2
./_test_email_api
ought to successfully send an email (sincecurl
doesn't attempt an OPTIONS request and goes straight to POST)./_set_email_endpoint
to inject email endpoint into source code at build timeng serve
localhost:4200/contact
and try sending a message to the lambda emailer service; will errorAdditional Context
I've found elsewhere that this problem can be caused if you set your statusCode using a string
status_code = "200"
. But, as you can see in my scripts, I tried this (even with the hyper explicittonumber(200)
), and it still thinks I'm not using integers :(