0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-14 10:10:39 +00:00
wp-s3-action/aws/cloudfront.go

41 lines
948 B
Go
Raw Normal View History

package aws
import (
"context"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
"github.com/rs/zerolog/log"
)
type Cloudfront struct {
client CloudfrontAPIClient
Distribution string
}
type CloudfrontInvalidateOptions struct {
Path string
}
// Invalidate invalidates the specified path in the CloudFront distribution.
func (c *Cloudfront) Invalidate(ctx context.Context, opt CloudfrontInvalidateOptions) error {
log.Debug().Msgf("invalidating '%s'", opt.Path)
_, err := c.client.CreateInvalidation(ctx, &cloudfront.CreateInvalidationInput{
DistributionId: aws.String(c.Distribution),
InvalidationBatch: &types.InvalidationBatch{
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
Paths: &types.Paths{
Quantity: aws.Int32(1),
Items: []string{
opt.Path,
},
},
},
})
return err
}