-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (54 loc) · 1.23 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/nikhil-thomas/technik-dojo/aws/gosdk/internal/errhndl"
)
func main() {
if len(os.Args) != 4 {
errhndl.ExitErrorf(
"bucket, key, and other bucket names required\nUsage: go run %s_object bucket item other-bucket",
filepath.Base(os.Args[0]),
)
}
bucketSrc := os.Args[1]
objectName := os.Args[2]
bucketDst := os.Args[3]
copySrc := bucketSrc + "/" + objectName
sess, err := session.NewSession(&aws.Config{
Region: aws.String(os.Getenv("AWS_REGION")),
})
if err != nil {
log.Fatalln(err)
}
svc := s3.New(sess)
fmt.Println("copy object")
_, err = svc.CopyObject(&s3.CopyObjectInput{
Bucket: aws.String(bucketDst),
CopySource: aws.String(copySrc),
Key: aws.String(objectName),
})
if err != nil {
log.Fatalln(err)
}
fmt.Println("wait until object exists")
err = svc.WaitUntilObjectExists(&s3.HeadObjectInput{
Bucket: aws.String(bucketDst),
Key: aws.String(objectName),
})
if err != nil {
log.Fatalln(err)
}
fmt.Println(
objectName,
"successfully copied from",
bucketSrc,
"to",
bucketDst,
)
}