Search code examples
amazon-s3aws-cloudformationamazon-cloudfront

How to delete a CloudFront Distribution once the S3 Bucket used by the Origins has been deleted?


The CloudFront Distribution and S3 Bucket were created by CloudFormation. The Distribution had Origins that made use of the S3 Bucket. The S3 Bucket was deleted manually. The CloudFormation stack was then deleted, however, the CloudFront Distribution was not. Most of the rest of the CloudFormation has subsequently been deleted, but the CloudFront Distribution, related Internet Gateway and a few other things have not. A /* Invalidation has been completed.

When attempting to manually disable the Distribution through the web console there is the following error message: Failed: The parameter S3 bucket has been deleted.

When attempting to delete an Origin or change its Origin domain there is the following error message: Failed to delete origin: One or more of your cache behavior target origins or origin groups do not exist.

When attempting to delete a Behavior or change its Origin there is the following error message: The parameter S3 bucket has been deleted.

What options are there to clear up this Distribution?


Solution

  • The long and short of it is that you can create an identically named S3 Bucket and then delete the Distribution.

    1. Create a suitably named bucket by going to the Distribution > Edit the relevant S3 Origin > 'Go to S3 bucket permissions' > copy the S3 bucket name from the missing bucket error message > create a bucket with this name.
    2. Give the bucket a suitable policy by going back to S3 Origin Edit page > 'Copy policy' > paste the policy in the Bucket policy field of the Permissions tab of the S3 Bucket > Save the S3 Bucket changes and wait a minute for the changes to take effect.
    3. Delete the Distribution's Behaviors.
    4. Delete the Distribution's Origins.
    5. Disable the Distribution and once this change has deployed, delete the Distribution.
    6. Delete the S3 Bucket and anything else kicking around that has been blocked on the Distribution's deletion. You may have to wait a short while for changes to propagate.