AWS CLI: disable distribution

2019-03-04 08:42发布

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.

3条回答
看我几分像从前
2楼-- · 2019-03-04 08:48

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
查看更多
你好瞎i
3楼-- · 2019-03-04 08:58

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
查看更多
仙女界的扛把子
4楼-- · 2019-03-04 09:03

imperalix's answer works perfect for me! Let me add two more basic commands just incase some new comers (like me) need it:

  1. To list all the distributions. From where you can find the id.
$ aws cloudfront list-distributions
  1. To delete the distribution. But as it was mentioned, it takes some time after you disable the distribution.
$ aws cloudfront delete-distribution --id E123456 --if-match ETag123456
查看更多
登录 后发表回答