github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cloud/amazon/s3.go (about)

     1  package amazon
     2  
     3  import (
     4  	"github.com/aws/aws-sdk-go/aws"
     5  	"github.com/aws/aws-sdk-go/service/s3"
     6  	"github.com/olli-ai/jx/v2/pkg/cloud/amazon/session"
     7  )
     8  
     9  // CreateS3Bucket creates a new S3 bucket in the default region with the given bucket name
    10  // returning the location string
    11  func CreateS3Bucket(bucketName string, profile string, region string) (string, error) {
    12  	location := ""
    13  	sess, err := session.NewAwsSession(profile, region)
    14  	if err != nil {
    15  		return location, err
    16  	}
    17  
    18  	input := &s3.CreateBucketInput{
    19  		Bucket: aws.String(bucketName),
    20  		CreateBucketConfiguration: &s3.CreateBucketConfiguration{
    21  			LocationConstraint: sess.Config.Region,
    22  		},
    23  	}
    24  	svc := s3.New(sess)
    25  	result, err := svc.CreateBucket(input)
    26  	if result != nil && result.Location != nil {
    27  		location = *result.Location
    28  	}
    29  	return location, err
    30  }