Unable to delete cloudfront distribution

0

Please am the root user and am trying to delete a cloudfront distribution created by cloudformation, but to no avail. The cloudformation stacks that created the distribution, have all been deleted, but not the distribution. When I try to disable the distribution, which is the required step before the deletion, I get this error in red colour:

Failed. The S3 bucket that you specified for CloudFront logs doesn't exist: bucketname.s3.amazonaws.com

I also tried to edit the distribution, and turn off the standard logging, but I get this error in red colour:

The parameter S3 bucket has been deleted

Before deleting the cloudformation stacks, I deleted the s3 buckets that was created by the stack - I wanted to delete all the resources created by the stack before deleting the stack - bad idea.

Please can anyone be of help. Cheers

2 Answers
0
Accepted Answer

Hello,

You can recreate the S3 Bucket with the same name, ensure the bucket has the correct permissions that allow CloudFront to write logs to it and then you can disable the distribution.

Did you try using the AWS CLI?

1.Fetch the current configuration of CloudFront distribution

aws cloudfront get-distribution-config --id DISTRIBUTION_ID > dist-config.json

2.Edit the dist-config.json file to remove or update the logging configuration. The relevant section would look something like this:

"Logging": {
    "Enabled": false,
    "IncludeCookies": false,
    "Bucket": "",
    "Prefix": ""
}

3.Update the distribution with the modified configuration. You need the IfMatch value from the previous step (the ETag of the distribution config):

aws cloudfront update-distribution --id DISTRIBUTION_ID --distribution-config file://dist-config.json --if-match E_TAG

References:

  1. https://docs.aws.amazon.com/cli/latest/reference/cloudfront/get-distribution-config.html
  2. https://docs.aws.amazon.com/cli/latest/reference/cloudfront/update-distribution.html
profile picture
EXPERT
answered a year ago
profile pictureAWS
EXPERT
reviewed a year ago
0

Thank you very much @Sivaraman Selvam. I accept the answer above. I just want to add a few things. After fetching the distribution configuration into a "dist-config.json" file, I edited the "dist-config.json" file to use only a subset of the contents of the file - refer to this: https://docs.aws.amazon.com/cli/latest/reference/cloudfront/update-distribution.html I then recreated the two S3 buckets in the "dist-config.json" file and from the command line after turning logging off as shown in the answer by @Sivaraman Selvam, I disabled the distribution in the "dist-config.json" file:

Enabled: false

answered a year 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.

Guidelines for Answering Questions