How to add custom headers to Swagger UI requests in AWS Lambda Powertools? #6524
harshitsinghai77
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi team 👋
I'm using aws_lambda_powertools.event_handler and have enabled Swagger UI using enable_swagger. I have a use case where I want to add custom headers to the requests triggered from Swagger UI — for example, when a user clicks "Execute" on an endpoint, I want headers like "x-custom-header": "custom-value" to be included automatically.
Here’s the middleware I’ve tried:
However, this results in the following error:
AttributeError: property 'headers' of 'APIGatewayProxyEvent' object has no setter
It seems headers is a read-only property on the event object. I've also tried other approaches, but nothing seems to allow me to inject custom headers into the request that Swagger UI makes to my backend endpoints.
Question:
What’s the recommended or supported way to add custom headers to requests that Swagger UI makes when using enable_swagger()? Ideally, I’d like to set these headers globally without requiring users to input them manually every time.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions