1

我正在尝试使用适用于 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 文档了解这个参数,它说:

-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
4

2 回答 2

1

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

于 2019-03-22T20:59:25.507 回答
0

我发现使它现在可以工作的解决方法是直接调用 API 并读取标头。我必须实施 Signature 版本 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

然后,我能够向 cmdlet 提供ETagcmdletUpdate-CFDistribution并使其工作。

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

希望ETagAWSPowerShell 模块会在下一个版本中返回,以避免必须执行所有这些操作。

于 2018-03-08T16:09:20.337 回答