Adding additional HTTP headers for files on S3 as CloudFront origin?

I’m looking into adding some extra HTTP headers to the files we host on S3, like for example X-Content-Type-Options: nosniff.

I had the vague notion this was possible using S3 meta data, but Amazon transforms these names and returns them prefixed with ‘x-amz-meta-’, for this example I get ‘x-amz-meta-x-content-type-options:“nosniff”’.

Does anyone know if this is possible at all? We’re using a S3 wrapper based on boto3 but I don’t see it in the boto docs, headers are either direct attributes like cache control or the generic non-http meta.

We use this bucket as a CloudFront origin so maybe something could be done here? Alternately we could reverse-proxy the bucket through our own server and add the headers but it seems a bit silly to put a server inside the serverless route.


Related discussions:

Lambda@Edge can do it. Check this blog post

Thanks, this is exactly what we need.

Now I see it I remember reading about this a while ago; it is so hard to keep up with all the AWS features :slight_smile:

Just be warned, I believe this is still in Beta. We had a few teething issues when looking at his service in January. We wanted to work with adding headers, similar to your requirements and we ended up falling back to an EC2 instance as the origin for CloudFront because of the risk of this breaking our production service