0

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.

2
  • Are you querying your API directly via its API Gateway endpoint, or via CloudFront? Commented Jun 19 at 9:23
  • @gshpychka via the api gateway endpoint. Nothing is deployed on Cloud Front Commented Jun 24 at 3:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.