forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.go
32 lines (29 loc) · 791 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
30
31
32
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, region string) (string, error) {
location := ""
sess, defaultRegion, err := NewAwsSession()
if err != nil {
return location, err
}
if region == "" {
region = defaultRegion
}
input := &s3.CreateBucketInput{
Bucket: aws.String(bucketName),
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(region),
},
}
svc := s3.New(sess)
result, err := svc.CreateBucket(input)
if result != nil && result.Location != nil {
location = *result.Location
}
return location, err
}