简体   繁体   中英

AWS PowerShell update CloudFront distribution

I am trying to update my CloudFront distribution using AWSPowerShell module for PowerShell. When I use the update cmdlet from the module, I always get an error about not providing the "IfMatch" parameter.

$cfd = Update-CFDistribution @parameters -Id "E2POBWR9AXFROP"

Error: The If-Match version is missing or not valid for the resource.
Update-CFDistribution : The If-Match version is missing or not valid for the resource.

I went to the AWS doc to know about this parameter and it says:

-IfMatch: The value of the ETag header that you received when retrieving the distribution's configuration. For example: E2QWRUHAPOMQZL.

I was wondering if there is a way to to get the content of the ETag header using the AWSPowerShell module cmdlets. I don't want to call directly the AWS API doing an Http request in my PowerShell script just to get the content of the header... but maybe it's the only way.

I tried with the Get-CFDistributionConfig cmdlet but it doesn't return this information.

$cfd = Get-CFDistributionConfig @parameters -Id "E2POBWR9AXFROP"

This is the version of PowerShell I am using:

PS C:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      15063  608  

This is the version of AWSPowerShell module I am using:

PS C:\> Get-Module "AWSPowerShell" -ListAvailable

ModuleType Version    Name
---------- -------    ----
Binary     3.3.169.0  AWSPowerShell

调用 Get-CFDistributionConfig 后,可以在 $AWSHistory.LastServiceResponse.ETag 中找到 ETag 值

The workaround I found to make it work for now is to call the API directly and read the headers. I had to implement Signature version 4 to get the security Authorization header.

$headers = Get-AWSSecurityHeaders -service "cloudfront" -httpVerb "GET" -uri "/2017-03-25/distribution/$distributionId/config"
$response = Invoke-WebRequest -Uri "https://cloudfront.amazonaws.com/2017-03-25/distribution/$distributionId/config" -Headers $headers
$etag = $response.Headers.ETag

I was then able to provide the ETag to the Update-CFDistribution cmdlet and make it work.

$distribution = Update-CFDistribution @parameters -Id $distributionId -IfMatch $etag -Verbose

Hopefully the ETag will be returned by the AWSPowerShell module in a next version to avoid having to do all that.

This is how you can get access to ETag. The select parameter should be to get all.

$ETAG = (Get-CFDistributionConfig -Id $CLOUDFRONT_DISTRIBUTION_ID -Select "*").ETag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM