Expected Behaviour
I have a web service fronted by an edge-optimized API Gateway endpoint. The gateway proxies all requests to a Python Lambda, which uses Powertools to define our various routes. Our CORS configuration looks like:
cors_config = CORSConfig(
allow_origin=app_config.cors_allowed_origin,
allow_credentials=True,
extra_origins=list(app_config.cors_extra_origins),
)
where allow_origin is either the Beta/Prod front-end URL (e.g. app-beta.mycompany.com), or * for per-developer front-end URLs (e.g. app.{dev}.mycompany.com). We did the latter so devs could hit their web service dev stacks by running the UI either locally (localhost:<port>) or in the cloud (via app.{dev}.mycompany.com).
Our basic CORS integration test does the following:
- Issues a
GET to one of our routes, passing the Origin header with a value of either * when running locally, or the stage-specific UI endpoint when running in Beta/Prod.
- Checks the response headers, expecting that:
Access-Control-Allow-Headers is present
Access-Control-Allow-Credentials is true, and
Access-Control-Allow-Origin has the expected value.
This test has run successfully for months, until recently. It fails specifically when run locally on a dev machine (Origin: *), because the Access-Control-Allow-Credentials response header is missing. As far as I can tell, we've made no changes to our CORS setup that could explain this. The test succeeds on Beta & Prod.
Current Behaviour
The aforementioned integration test has started failing when run locally, after previously succeeding. I've tried to isolate the root cause to recent changes in either Powertools, Boto3, or CDK, but I haven't come up with anything useful. I'm not sure this is the right place for this issue - if not, I would really appreciate you pointing me in the right direction.
The response headers look like:
{
"Content-Type": "application/json",
"Content-Length": "2207",
"Connection": "close",
"Date": "Mon,17 Mar 2025 16: 55: 06 GMT",
"X-Amzn-Trace-Id": "<redacted>",
"x-amzn-RequestId": "<redacted>",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key",
"x-amz-apigw-id": "<redacted>",
"X-Cache": "Error from cloudfront",
"Via": "1.1 <redacted>.cloudfront.net (CloudFront)",
"X-Amz-Cf-Pop": "SEA19-C2",
"X-Amz-Cf-Id": "<redacted>"
}
Code snippet
Not sure how to distill the situation into a code snippet. Suggestions are welcome.
Possible Solution
No response
Steps to Reproduce
- Run integration test, checking for the
Access-Control-Accept-Credentials header.
- Header not returned, test fails.
Powertools for AWS Lambda (Python) version
2.43.1
AWS Lambda function runtime
3.10
Packaging format used
PyPi
Debugging logs
Expected Behaviour
I have a web service fronted by an edge-optimized API Gateway endpoint. The gateway proxies all requests to a Python Lambda, which uses Powertools to define our various routes. Our CORS configuration looks like:
where
allow_originis either the Beta/Prod front-end URL (e.g.app-beta.mycompany.com), or*for per-developer front-end URLs (e.g.app.{dev}.mycompany.com). We did the latter so devs could hit their web service dev stacks by running the UI either locally (localhost:<port>) or in the cloud (viaapp.{dev}.mycompany.com).Our basic CORS integration test does the following:
GETto one of our routes, passing theOriginheader with a value of either*when running locally, or the stage-specific UI endpoint when running in Beta/Prod.Access-Control-Allow-Headersis presentAccess-Control-Allow-Credentialsistrue, andAccess-Control-Allow-Originhas the expected value.This test has run successfully for months, until recently. It fails specifically when run locally on a dev machine (
Origin: *), because theAccess-Control-Allow-Credentialsresponse header is missing. As far as I can tell, we've made no changes to our CORS setup that could explain this. The test succeeds on Beta & Prod.Current Behaviour
The aforementioned integration test has started failing when run locally, after previously succeeding. I've tried to isolate the root cause to recent changes in either Powertools, Boto3, or CDK, but I haven't come up with anything useful. I'm not sure this is the right place for this issue - if not, I would really appreciate you pointing me in the right direction.
The response headers look like:
{ "Content-Type": "application/json", "Content-Length": "2207", "Connection": "close", "Date": "Mon,17 Mar 2025 16: 55: 06 GMT", "X-Amzn-Trace-Id": "<redacted>", "x-amzn-RequestId": "<redacted>", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key", "x-amz-apigw-id": "<redacted>", "X-Cache": "Error from cloudfront", "Via": "1.1 <redacted>.cloudfront.net (CloudFront)", "X-Amz-Cf-Pop": "SEA19-C2", "X-Amz-Cf-Id": "<redacted>" }Code snippet
Possible Solution
No response
Steps to Reproduce
Access-Control-Accept-Credentialsheader.Powertools for AWS Lambda (Python) version
2.43.1
AWS Lambda function runtime
3.10
Packaging format used
PyPi
Debugging logs