Skip to content

Send CloudFront logs to CloudWatch

0

I am trying to follow this post https://aws.amazon.com/blogs/mt/sending-cloudfront-standard-logs-to-cloudwatch-logs-for-analysis/ to send logs written to S3 by my CloudFront distribution to CloudWatch.

The CloudFormation stack keeps failing with the error:

Resource handler returned message: "Error occurred while GetObject. S3 Error Code: PermanentRedirect. S3 Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: Lambda, Status Code: 400, Request ID: c96e51f3-6e2d-4ace-a98e-d3bdf7a14f5a)" (RequestToken: 1bc35d6c-bcc4-de34-96e6-a6ee4b8a1580, HandlerErrorCode: InvalidRequest)

My CF distribution and S3 log bucket are all in eu-west-2. I have replaced all references in the template file to us-east-1 with eu-west-2

I notice two things:

  1. My S3 bucket which was created from the CloudFront logging Standard Log Add journey has a permissions policy which allows Put from a us-east-1 based resource with ARN delivery-source:CreatedByCloudFront and my CF distribution ID
  2. In the template, there is a reference to a Lambda function defined in cloudfront-to-cloudwatch-blog/lambda_function.zip

Any ideas?

asked 2 years ago1.2K views

1 Answer
0

The error you're encountering suggests that there's a mismatch between the region where your resources are located and the region being used in the CloudFormation template. Here are a few things to consider:

  1. CloudFront Log Delivery: CloudFront always delivers logs from the us-east-1 region, regardless of where your distribution or S3 bucket is located. This explains why your S3 bucket policy allows PUT access from a us-east-1 based resource. This is normal and doesn't need to be changed.

  2. Lambda Function Region: The Lambda function that processes the logs should be in the same region as your S3 bucket (eu-west-2 in your case). Make sure you've updated the Lambda function's region in the CloudFormation template.

  3. S3 Bucket Configuration: Ensure that your S3 bucket is configured to allow access from the eu-west-2 region. The PermanentRedirect error suggests that the S3 bucket is trying to redirect to a different endpoint.

  4. CloudFormation Stack Region: Make sure you're creating the CloudFormation stack in the eu-west-2 region.

  5. Lambda Function Code: The reference to the Lambda function code (cloudfront-to-cloudwatch-blog/lambda_function.zip) should be updated to point to a location in your eu-west-2 region. You might need to upload this ZIP file to an S3 bucket in eu-west-2 and update the reference in the template.

  6. IAM Roles and Policies: Ensure that any IAM roles and policies defined in the template are updated to reference the correct region and resource ARNs.

To resolve the issue:

  1. Double-check all region references in your CloudFormation template, ensuring they're set to eu-west-2.
  2. Update the Lambda function code location to a eu-west-2 S3 bucket.
  3. Verify that your S3 bucket allows access from the eu-west-2 region.
  4. Ensure you're creating the CloudFormation stack in the eu-west-2 region.

If the issue persists, you may need to review the S3 bucket configuration to ensure it's not enforcing region-specific endpoints that could cause the PermanentRedirect error.
Sources
Enable logging from AWS services - Amazon CloudWatch Logs
Configure standard logging (v2) - Amazon CloudFront
Amazon CloudFront now supports additional log formats and destinations for access logs - AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.