Skip to content

NodeJS Lambda function that adds a header to CloudFront viewer responses, instructing search engines not to index the response.

Notifications You must be signed in to change notification settings

DestinationCore/cloudfront-no-robots-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

CloudFront No Robots Lambda

NodeJS Lambda function that adds a X-Robots-Tag to CloudFront viewer responses, instructing search engines not to index the response.

The X-Robots-Tag header will be returned on all responses. If you need to conditionally return the header dependent on the request, consider adding some additional logic to index.js. Or, if you are using S3 as an origin set headers on specific objects and return headers in the function based upon those.

Setup

  1. Deploy the function to Lambda in the us-east-1 region and publish a new version.
  2. Set the trust entities on the Lambda functions role in IAM.
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "lambda.amazonaws.com",
          "edgelambda.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
  1. Associate the functions latest version ARN to your CloudFront distributions viewer response.
  2. Run an invalidation if you have CloudFront caching enabled.

About

NodeJS Lambda function that adds a header to CloudFront viewer responses, instructing search engines not to index the response.

Topics

Resources

Stars

Watchers

Forks