-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (47 loc) · 1.13 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
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"os"
"path/filepath"
)
func main() {
// Initialize the session that the SDK
sess, err := session.NewSession(&aws.Config{
Region: aws.String("ap-northeast-1"),
})
if err != nil {
fmt.Errorf("error creating session: %v", err)
return
}
// Create a new service client
svc := s3.New(sess)
// Create a new request for the ListBuckets operation
dumpFilePath := "./hoge.sql"
// パスの最後の要素(ファイル名を取得)
dumpFileName := filepath.Base(dumpFilePath)
// S3バケット
bucket := "ex-bucket-lambda"
// S3オブジェクトキー
key := "dump/" + dumpFileName
// ファイルを開く
file, err := os.Open(dumpFilePath)
if err != nil {
fmt.Errorf("error opening file: %v", err)
return
}
defer file.Close()
// S3にアップロード
_, err = svc.PutObject(&s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: file,
})
if err != nil {
fmt.Errorf("error uploading file: %v", err)
return
}
fmt.Println("success")
}