AWS CLI:禁用分发

Ale*_*ber 0 amazon-web-services amazon-cloudfront aws-cli

据我所知,禁用云端分发意味着更新它的状态,并且必须能够删除它.

鉴于AWS CLI的文档非常稀少,我正在寻找一个仅使用CLI进行更新的最小示例.

imp*_*lix 8

虽然我无法为您提供最小的示例,但以下内容应该有效.您可以从您的发行版的存储库或http://stedolan.github.io/jq/manual/获取jq .

  1. 获取Etag,第3步将需要它:

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

获取当前配置:

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

    修改/ tmp/disable-distribution-E123456,禁用分发配置文件.

    相关部分:

    "DefaultRootObject": null,
    "PriceClass": "PriceClass_All",
    "Enabled": true,  <-- Set to false
    
    Run Code Online (Sandbox Code Playgroud)

更新分发:

  1. $ aws cloudfront update-distribution --id E123456 --if-match E3SVA578MZF6JZ --distribution-config file:/// tmp/disable-distribution-E123456


Jea*_*ier 7

奇怪的是,所提出的解决方案对我不起作用。我不断得到

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

打电话时aws cloudfront delete-distribution

问题似乎是您无法立即禁用分配aws cloudfront update-distribution,其状态需要一段时间才能更新(参见 AWS 控制台,其中状态显示为“进行中”)。

总之,以下命令序列解决了我的问题:

aws cloudfront update-distribution
aws cloudfront wait distribution-deployed
aws cloudfront delete-distribution
Run Code Online (Sandbox Code Playgroud)