deploy: Fix CloudFront invalidation with AWS SDK2

This commit is contained in:
Bjørn Erik Pedersen 2024-01-31 21:41:04 +01:00
parent d8e1e82188
commit d8c2734178
3 changed files with 27 additions and 1 deletions

View file

@ -27,6 +27,15 @@ import (
gcaws "gocloud.dev/aws"
)
// V2ConfigFromURLParams will fail for any unknown params, so we need to remove them.
// This is a mysterious API, but inspecting the code the known params are:
var v2ConfigValidParams = map[string]bool{
"endpoint": true,
"region": true,
"profile": true,
"awssdk": true,
}
// InvalidateCloudFront invalidates the CloudFront cache for distributionID.
// Uses AWS credentials config from the bucket URL.
func InvalidateCloudFront(ctx context.Context, target *Target) error {
@ -34,7 +43,16 @@ func InvalidateCloudFront(ctx context.Context, target *Target) error {
if err != nil {
return err
}
cfg, err := gcaws.V2ConfigFromURLParams(ctx, u.Query())
vals := u.Query()
// Remove any unknown params.
for k := range vals {
if !v2ConfigValidParams[k] {
vals.Del(k)
}
}
cfg, err := gcaws.V2ConfigFromURLParams(ctx, vals)
if err != nil {
return err
}