Repository navigation
Update-CFDistribution Not Updating Distribution Despite No Loud Failure #425
|
I am trying to update the OriginPath for the one distribution I have in CloudFront as part of a CI/CD workflow. The S3 push works. The call to Update-CFDistribution seems to work, but the distribution is not updated when I look at the console in the AWS account. I have checked the credentials. I have checked the Distribution ID. I have checked the IAM permissions. I am splatting the parameters per the answer in #285. I checked that the ETag is being sent in the IfMatch parameter. The result from the Update-CFDistribution call ($result) is not returning a status ($result.Distribution.Status). I've tried the Verbose and WhatIf parameters to see if that gave me more information and nothing other than further showing me that the Distribution ID is correct. I am working with AWS.Tools.Cloudfront 4.1.674. Earlier in working on this I was working with 5.0.252, but that version wasn't returning my Origins as part of the DistributionConfig. The AWS AI said that was a known issue and that I should downgrade. I've talked to the AI until I'm blue in the face. I also used Copilot. Neither helped other than sending me down rabbit holes. AWS AI couldn't even give me a full list of the required parameters. The documentation wasn't accurate on that either. That's a separate gripe, though. I'm a bit at the end of what I can do. I need a direction to go down to further research the issue. Has anyone ever had this issue and know what I could check next? |
Replies: 3 comments 4 replies
|
We will review the question and get back to you. Thanks |
|
Hi @wdhowell84, I reproduced this on v5 (AWS.Tools.CloudFront 5.0.255). It comes down to two things, both of which work on v5. v4 is now out of support, so downgrading is not a long-term option. 1. Understand what
|
|
I tried reproducing by running your same exact code but my setup is different and still may not work for you. The cause seems to be the origin update block.
Fix: index the origin directlyBefore: if ($config.Origins.Items -is [System.Array]) {
$originToUpdate = $config.Origins.Items[0]
} else {
$originToUpdate = $config.Origins.Items
}
if ($originToUpdate.PSObject.Properties.Name -contains "OriginPath") {
$originToUpdate.OriginPath = $normalizedOriginPath
} else {
$originToUpdate | Add-Member -MemberType NoteProperty -Name "OriginPath" -Value $normalizedOriginPath -Force
}After: $originToUpdate = $config.Origins.Items[0]
$originToUpdate.OriginPath = $normalizedOriginPathYour existing I also recommend adding $after = (Get-CFDistributionConfig -Id $DistributionID).Origins.Items[0].OriginPath
if ($after -ne $normalizedOriginPath) { throw "OriginPath did not change: got '$after'" }Let me know how it goes, may not be able to reply until Monday morning. Thanks |
Hi @wdhowell84,
I reproduced this on v5 (AWS.Tools.CloudFront 5.0.255). It comes down to two things, both of which work on v5. v4 is now out of support, so downgrading is not a long-term option.
1. Understand what
-Selectreturns by default-Selectcontrols a cmdlet's output. To simplify the common case, when a response has exactly one service property (ignoring common metadata like ETag, ContentLength, HttpStatusCode) the default is that property, so you get the useful object directly, otherwise the default is*(the whole response). This explains both symptoms you hit:Update-CFDistributionreturns onlyDistribution, so it defaults to-Select 'Distribution'and its output is theDistri…