AWS PowerShell更新CloudFront分配

问题描述 投票:1回答:2

我正在尝试使用PowerShell的AWSPowerShell模块更新我的CloudFront分配。当我使用模块中的更新cmdlet时,我总是会收到有关不提供“IfMatch”参数的错误。

$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 doc了解这个参数,它说:

-IfMatch:检索分发配置时收到的ETag标头的值。例如:E2QWRUHAPOMQZL。

我想知道是否有办法使用AWSPowerShell模块cmdlet获取ETag标头的内容。我不想直接调用AWS API在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
powershell amazon-web-services amazon-cloudfront cmdlet aws-powershell
2个回答
1
投票

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


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

然后我能够将ETag提供给Update-CFDistribution cmdlet并使其工作。

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

希望在下一个版本中由AWSPowerShell模块返回ETag,以避免必须完成所有这些操作。

© www.soinside.com 2019 - 2024. All rights reserved.