1

我正嘗試使用PowerShell的AWSPowerShell模塊更新我的CloudFront分配。當我使用模塊中的更新cmdlet時,我總是收到有關未提供「IfMatch」參數的錯誤。AWS PowerShell更新CloudFront分配

$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. 

我去AWS文檔瞭解這個參數,它說:

-IfMatch:您檢索分配的配置時收到的ETag頭的價值。例如: E2QWRUHAPOMQZL。

我想知道是否有辦法使用AWSPowerShell模塊cmdlet獲取ETag頭的內容。我不想直接調用AWS PowerShell腳本中的Http請求來獲取標題的內容......但也許這是唯一的方法。

我試着用Get-CFDistributionConfig cmdlet,但是它沒有返回這個信息。

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

這是PowerShell中的版本我使用:

PS C:\> $PSVersionTable.PSVersion 

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

這是AWSPowerShell模塊的版本我使用:

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

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

回答

0

我發現使它工作的解決方法現在是直接調用API並讀取頭文件。我不得不實施簽名版本4以獲得安全性Authorization標題。

$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 

當時我能夠提供ETagUpdate-CFDistribution cmdlet,並使其發揮作用。

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

希望的ETag將由AWSPowerShell模塊中的下一個版本恢復,以避免做這一切。