1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go導入(+AWS SDK for Go)メモ

1
Posted at

備忘録です

gvmを導入

moovweb/gvm Go Version Manager

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

Go1.5以上をインストールするには1.4が必要

gvm install go1.4

gbを導入

gb A project based build tool for the Go programming language

AWS SDK for Go

aws/aws-sdk-go

gb-vendorを使ってパッケージをvendorディレクトリに保存

gb vendor fetch -tag v1.1.9 github.com/aws/aws-sdk-go

$HOME/.aws/credentialsにAWSへのアクセス情報を記述

[default]
aws_access_key_id = ACCESS_KEY
aws_secret_access_key = SECRET_KEY

プロファイル名を指定して使用する。credentials.NewSharedCredentialsの第1引数はcredentialsファイルのパス。指定しなければデフォルトパスを参照する。

creds := credentials.NewSharedCredentials("", "default")
credValue, err := creds.Get()
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}

S3からバケット一覧を取得

s3c := s3.New(session.New(&aws.Config{
	Region: aws.String("us-east-1"),
	Credentials: creds,
}))

var params *s3.ListBucketsInput
resp, err := s3c.ListBuckets(params)

if err != nil {
	fmt.Println(err.Error())
	return
}
fmt.Println(resp)
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?