forked from jenkins-x/jx
/
s3.go
29 lines (26 loc) · 760 Bytes
/
s3.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
package amazon
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
)
// CreateS3Bucket creates a new S3 bucket in the default region with the given bucket name
// returning the location string
func CreateS3Bucket(bucketName string, profile string, region string) (string, error) {
location := ""
sess, err := NewAwsSession(profile, region)
if err != nil {
return location, err
}
input := &s3.CreateBucketInput{
Bucket: aws.String(bucketName),
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: sess.Config.Region,
},
}
svc := s3.New(sess)
result, err := svc.CreateBucket(input)
if result != nil && result.Location != nil {
location = *result.Location
}
return location, err
}