go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/blogctl/pkg/aws/cloudfront/invalidate.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package cloudfront
     9  
    10  import (
    11  	"context"
    12  
    13  	"github.com/aws/aws-sdk-go/aws/session"
    14  	"github.com/aws/aws-sdk-go/service/cloudfront"
    15  
    16  	"go.charczuk.com/sdk/uuid"
    17  
    18  	"go.charczuk.com/projects/blogctl/pkg/aws"
    19  )
    20  
    21  // InvalidateMany invalidates a given set of paths for a distribution.
    22  func InvalidateMany(ctx context.Context, session *session.Session, distribution string, items ...string) error {
    23  	_, err := cloudfront.New(session).CreateInvalidationWithContext(ctx, &cloudfront.CreateInvalidationInput{
    24  		DistributionId: aws.RefStr(distribution),
    25  		InvalidationBatch: &cloudfront.InvalidationBatch{
    26  			CallerReference: aws.RefStr(uuid.V4().String()),
    27  			Paths: &cloudfront.Paths{
    28  				Items:    aws.RefStrs(items...),
    29  				Quantity: quantity(items),
    30  			},
    31  		},
    32  	})
    33  	return err
    34  }
    35  
    36  func quantity(items []string) *int64 {
    37  	l := int64(len(items))
    38  	return &l
    39  }