summaryrefslogtreecommitdiffstats
path: root/deploy/cloudfront.go
diff options
context:
space:
mode:
authorMatt Brown <matt@mattb.net.nz>2023-07-09 00:00:45 +1200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-08-30 16:38:20 +0300
commitc3f273b2d7b18f921410cde6e01442694cda5fe7 (patch)
treecb521da0e0bc16180c6cad9ed5c4ef20e643b14a /deploy/cloudfront.go
parentd7dcc76d27dc55b10b9a5c4294c4a883d0bdfb2e (diff)
deploy: Create AWS session for CloudFront invalidation via Go CDK
This allows the AWS credentials to be picked up from the configured target URL (like blob does) rather than the current behaviour of only relying on the defaults. Relying on the defaults here means having to specify credentials twice (once in the URL for the blob, once in the environment for this code path) when non-default AWS credentials are in used (e.g. via a profile).
Diffstat (limited to 'deploy/cloudfront.go')
-rw-r--r--deploy/cloudfront.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/deploy/cloudfront.go b/deploy/cloudfront.go
index 2f673dc97..8ed9b858d 100644
--- a/deploy/cloudfront.go
+++ b/deploy/cloudfront.go
@@ -18,6 +18,7 @@ package deploy
import (
"context"
+ "net/url"
"time"
"github.com/aws/aws-sdk-go/aws"
@@ -26,14 +27,18 @@ import (
)
// InvalidateCloudFront invalidates the CloudFront cache for distributionID.
-// It uses the default AWS credentials from the environment.
-func InvalidateCloudFront(ctx context.Context, distributionID string) error {
- sess, err := gcaws.NewDefaultSession()
+// Uses AWS credentials config from the bucket URL.
+func InvalidateCloudFront(ctx context.Context, target *Target) error {
+ u, err := url.Parse(target.URL)
+ if err != nil {
+ return err
+ }
+ sess, _, err := gcaws.NewSessionFromURLParams(u.Query())
if err != nil {
return err
}
req := &cloudfront.CreateInvalidationInput{
- DistributionId: aws.String(distributionID),
+ DistributionId: aws.String(target.CloudFrontDistributionID),
InvalidationBatch: &cloudfront.InvalidationBatch{
CallerReference: aws.String(time.Now().Format("20060102150405")),
Paths: &cloudfront.Paths{