Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudfront update-distribution with get-distribution-config config file #2479

Closed
usterk opened this issue Mar 7, 2017 · 3 comments
Closed

Comments

@usterk
Copy link

usterk commented Mar 7, 2017

I would like to edit/update my CloudFront distribution with awscli.

I'm using latest cli version:

aws-cli/1.11.56 Python/2.7.10 Darwin/16.4.0 botocore/1.5.19

I'm getting config of the distribution that I'd like to modify:

aws cloudfront get-distribution-config --id FOO_BAR_ID > cf_config.json

Looks like it worked as expected. Config looks ok for me. Now I'm trying to reconfigure my CF distribution with the same config.

aws cloudfront update-distribution --distribution-config file://cf_config.json --id FOO_BAR_ID

and I'm getting:

Parameter validation failed:
Missing required parameter in DistributionConfig: "CallerReference"
Missing required parameter in DistributionConfig: "Origins"
Missing required parameter in DistributionConfig: "DefaultCacheBehavior"
Missing required parameter in DistributionConfig: "Comment"
Missing required parameter in DistributionConfig: "Enabled"
Unknown parameter in DistributionConfig: "ETag", must be one of: CallerReference, Aliases, DefaultRootObject, Origins, DefaultCacheBehavior, CacheBehaviors, CustomErrorResponses, Comment, Logging, PriceClass, Enabled, ViewerCertificate, Restrictions, WebACLId, HttpVersion, IsIPV6Enabled
Unknown parameter in DistributionConfig: "DistributionConfig", must be one of: CallerReference, Aliases, DefaultRootObject, Origins, DefaultCacheBehavior, CacheBehaviors, CustomErrorResponses, Comment, Logging, PriceClass, Enabled, ViewerCertificate, Restrictions, WebACLId, HttpVersion, IsIPV6Enabled

Is it a bug?
What is the right way to reconfigure CF using awscli?

@usterk
Copy link
Author

usterk commented Mar 8, 2017

Sorry. Looks like this is not a bug.

You have to edit cf_config.json before using it with update-distribution and remove

{
    "ETag": "ETag_Value",
    "DistributionConfig":

from the beginning of the file and last

}

from the end of file.

Then use this command with the right id and ETag value that was removed from cf_config.json

aws cloudfront update-distribution --distribution-config file://cf_config.json --id FOO_BAR_ID --if-match ETag_Value

@usterk usterk closed this as completed Mar 8, 2017
@yaselc
Copy link

yaselc commented Mar 26, 2019

Filtering by the DistributionConfig should be enough:

aws cloudfront get-distribution-config \
    --id FOO_BAR_ID \
    --query 'DistributionConfig' \
    --output json \
    > cf_config.json

@JasonThomasData
Copy link

@yaselc this doesn't let you push it though, since you need the etag.
Here's a script I made for the purpose of updating a distribution.

#!/usr/bin/env bash

configFilePath=$1
distributionId=$2
distributionToPushPath="distribution.config"

etag=$(cat $configFilePath | python3 -c "import sys, json; print(json.load(sys.stdin)['ETag'])")
cat $configFilePath | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)['DistributionConfig']))" > $distributionToPushPath

aws cloudfront update-distribution --distribution-config file://$distributionToPushPath --id $distributionId --if-match $etag

rm distribution.config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants