-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Invalidate one or more URIs from a CloudFront distribution.
// For example:
//
// $> ./bin/invalidate -client-uri 'aws://region=us-east-1&credentials=session' -distribution-id {DISTRIBUTION_ID} /data/151/194/395/1/1511943951.geojson
package main
import (
"context"
"flag"
"fmt"
"github.com/aaronland/go-aws-cloudfront"
"log"
"os"
)
func main() {
client_uri := flag.String("client-uri", "", "A valid client URI in the form of 'aws://?region={AWS_REGION}&credentials={CREDENTIALS}' where '{CREDENTIAL}' is expected to be a valid aaronland/go-aws-session credential string.")
distribution_id := flag.String("distribution-id", "", "A valid AWS CloudFront distribution ID.")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Invalidate one or more URIs from a CloudFront distribution.\n")
fmt.Fprintf(os.Stderr, "Usage:\n\t %s uri(N) uri(N)\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
ctx := context.Background()
cl, err := cloudfront.NewClientWithURI(ctx, *client_uri)
if err != nil {
log.Fatalf("Failed to create client, %v", err)
}
uris := flag.Args()
id, ref, err := cloudfront.InvalidatePaths(ctx, cl, *distribution_id, uris...)
if err != nil {
log.Fatalf("Failed to invalidate paths, %v", err)
}
fmt.Printf("%s %s\n", id, ref)
}