I'm working with AWS Lambda function that serves as the backend for an API Gateway endpoint using Lambda Proxy Integration. My Lambda handler is structured like this:
def lambda_handler(event, context):
# ... business logic ...
return {
"statusCode": 200,
"body": json.dumps({"message": "Success"}),
"headers": {
"X-Content-Type-Options": "nosniff"
},
"isBase64Encoded": False
}
I want to send X-Content-Type-Options: nosniff to the client.
The API Gateway is set up as a REST API using Lambda Proxy Integration. The Lambda function is deployed via AWS CDK, and the API Gateway is created with something like:
api = aws_apigateway.LambdaRestApi(
self,
"MyApi",
handler=my_lambda_function,
# ... other config ...
)
When I test the endpoint, the response body and status code are correct, but the custom header does not appear in the response. I've tried verifying that the Lambda function returns the header in the response dictionary and checked API Gateway settings for any header filtering or mapping but no luck.