Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs
Verwendung von GetDistributionConfig mit einem AWS-SDK oder CLI
Die folgenden Code-Beispiele zeigen, wie GetDistributionConfig verwendet wird.
Beispiele für Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Im folgenden Codebeispiel können Sie diese Aktion im Kontext sehen:
- CLI
-
- AWS CLI
-
So rufen Sie eine CloudFront-Distributionskonfiguration ab
Im folgenden Beispiel werden Metadaten zur CloudFront-Distribution mit der ID
EDFDVBD6EXAMPLEabgerufen, einschließlich ihresETag. Die Distribution-ID wird in den Befehlen create-distribution und list-distributions zurückgegeben.aws cloudfront get-distribution-config \ --idEDFDVBD6EXAMPLEAusgabe:
{ "ETag": "E2QWRUHEXAMPLE", "DistributionConfig": { "CallerReference": "cli-example", "Aliases": { "Quantity": 0 }, "DefaultRootObject": "index.html", "Origins": { "Quantity": 1, "Items": [ { "Id": "amzn-s3-demo-bucket.s3.amazonaws.com-cli-example", "DomainName": "amzn-s3-demo-bucket.s3.amazonaws.com", "OriginPath": "", "CustomHeaders": { "Quantity": 0 }, "S3OriginConfig": { "OriginAccessIdentity": "" } } ] }, "OriginGroups": { "Quantity": 0 }, "DefaultCacheBehavior": { "TargetOriginId": "amzn-s3-demo-bucket.s3.amazonaws.com-cli-example", "ForwardedValues": { "QueryString": false, "Cookies": { "Forward": "none" }, "Headers": { "Quantity": 0 }, "QueryStringCacheKeys": { "Quantity": 0 } }, "TrustedSigners": { "Enabled": false, "Quantity": 0 }, "ViewerProtocolPolicy": "allow-all", "MinTTL": 0, "AllowedMethods": { "Quantity": 2, "Items": [ "HEAD", "GET" ], "CachedMethods": { "Quantity": 2, "Items": [ "HEAD", "GET" ] } }, "SmoothStreaming": false, "DefaultTTL": 86400, "MaxTTL": 31536000, "Compress": false, "LambdaFunctionAssociations": { "Quantity": 0 }, "FieldLevelEncryptionId": "" }, "CacheBehaviors": { "Quantity": 0 }, "CustomErrorResponses": { "Quantity": 0 }, "Comment": "", "Logging": { "Enabled": false, "IncludeCookies": false, "Bucket": "", "Prefix": "" }, "PriceClass": "PriceClass_All", "Enabled": true, "ViewerCertificate": { "CloudFrontDefaultCertificate": true, "MinimumProtocolVersion": "TLSv1", "CertificateSource": "cloudfront" }, "Restrictions": { "GeoRestriction": { "RestrictionType": "none", "Quantity": 0 } }, "WebACLId": "", "HttpVersion": "http2", "IsIPV6Enabled": true } }-
Weitere API-Informationen finden Sie unter GetDistributionConfig
in der AWS CLI-Befehlsreferenz.
-
- PowerShell
-
- Tools für PowerShell V4
-
Beispiel 1: Ruft die Konfiguration für eine bestimmte Distribution ab.
Get-CFDistributionConfig -Id EXAMPLE0000ID-
Weitere API-Informationen finden Sie unter GetDistributionConfig in der AWS -Tools für PowerShell-Cmdlet-Referenz (V4)
-
- Tools für PowerShell V5
-
Beispiel 1: Ruft die Konfiguration für eine bestimmte Distribution ab.
Get-CFDistributionConfig -Id EXAMPLE0000ID-
Weitere API-Informationen finden Sie unter GetDistributionConfig in der AWS -Tools für PowerShell-Cmdlet-Referenz (V5).
-
- Python
-
- SDK für Python (Boto3)
-
Anmerkung
Auf GitHub finden Sie noch mehr. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS-Code-Beispiel-
einrichten und ausführen. class CloudFrontWrapper: """Encapsulates Amazon CloudFront operations.""" def __init__(self, cloudfront_client): """ :param cloudfront_client: A Boto3 CloudFront client """ self.cloudfront_client = cloudfront_client def update_distribution(self): distribution_id = input( "This script updates the comment for a CloudFront distribution.\n" "Enter a CloudFront distribution ID: " ) distribution_config_response = self.cloudfront_client.get_distribution_config( Id=distribution_id ) distribution_config = distribution_config_response["DistributionConfig"] distribution_etag = distribution_config_response["ETag"] distribution_config["Comment"] = input( f"\nThe current comment for distribution {distribution_id} is " f"'{distribution_config['Comment']}'.\n" f"Enter a new comment: " ) self.cloudfront_client.update_distribution( DistributionConfig=distribution_config, Id=distribution_id, IfMatch=distribution_etag, ) print("Done!")-
Weitere API-Informationen finden Sie unter GetDistributionConfig in der API-Referenz zum AWS SDK für Python (Boto3).
-