Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI: disable distribution

As far as I have understood, disabling a cloudfront distribution means updating it's status and is necessary to be able to delete it.

Given the very sparse documentation of the AWS CLI, I am looking for a minimal example of how to do that update using just the CLI.

like image 639
Alexander Presber Avatar asked Nov 30 '22 11:11

Alexander Presber


2 Answers

While I can't provide you a minimal example, the following should work. You can obtain jq from your distribution's repository or from http://stedolan.github.io/jq/manual/.

  1. Get the Etag, will need it for step 3:

    $ aws cloudfront get-distribution-config --id E123456 | jq '. | .ETag'

Get current config:

  1. $ aws cloudfront get-distribution-config --id E123456 | jq '. | .DistributionConfig' > /tmp/disable-distribution-E123456

    Modify /tmp/disable-distribution-E123456, distribution config file to disable.

    Relevant section:

    "DefaultRootObject": null,
    "PriceClass": "PriceClass_All",
    "Enabled": true,  <-- Set to false
    

Update Distribution:

  1. $ aws cloudfront update-distribution --id E123456 --if-match E3SVA578MZF6JZ --distribution-config file:///tmp/disable-distribution-E123456
like image 52
imperalix Avatar answered Dec 09 '22 11:12

imperalix


Oddly enough, the proposed solutions did not work for me. I kept getting

An error occurred (DistributionNotDisabled) when calling the DeleteDistribution operation: The distribution you are trying to delete has not been disabled.

when calling aws cloudfront delete-distribution.

The issue seems to be that you can't immediately disable the distribution with aws cloudfront update-distribution, its status taking a while to be updated (cf. the AWS Console, where the status is shown as 'In Progress').

In summary, the following sequence of commands solved my issue:

aws cloudfront update-distribution
aws cloudfront wait distribution-deployed
aws cloudfront delete-distribution
like image 34
Jean Gauthier Avatar answered Dec 09 '22 10:12

Jean Gauthier