// SetupBucket creates an AWS bucket with the specified name from ENV var if it does not exist already.
// If no var is specified, it uses the default name.
SetupBucket creates an AWS bucket with the specified name from ENV var if it does not exist already.
If no var is specified, it uses the default name.
// SetupBucket creates an AWS bucket with the specified name from ENV var if it does not exist already . // If no var is specified it uses the default name .
func (upld *AwsAssetUploader) SetupBucket() error {
	bucketName = os.Getenv("AWS_BUCKET_NAME")
	if bucketName == "" {
		bucketName = constants.DefaultBucketName
	}
	result, err := upld.S3Manager.ListBuckets(&s3.ListBucketsInput{})
	if err != nil {
		log.Error().Msgf("Could not list AWS buckets. Err: %s", err)
		return err
	}
	shouldCreateBucket := true
	for _, bucket := range result.Buckets {
		if *bucket.Name == bucketName {
			shouldCreateBucket = false
			break
		}
	}
	if shouldCreateBucket {
		_, err = upld.S3Manager.CreateBucket(&s3.CreateBucketInput{
			Bucket: aws.String(bucketName),
		})
		if err != nil {
			return err
		}
		err = upld.S3Manager.WaitUntilBucketExists(&s3.HeadBucketInput{
			Bucket: aws.String(bucketName),
		})
		if err != nil {
			return err
		}
	}
	return nil
}
func ( upld * AwsAssetUploader ) SetupBucket ( ) error { bucketName = os . Getenv ( " " ) if bucketName == " " { bucketName = constants . DefaultBucketName } result , err := upld . S3Manager . ListBuckets ( & s3 . ListBucketsInput { } ) if err != nil { log . Error ( ) . Msgf ( " " , err ) return err } shouldCreateBucket := true for _ , bucket := range result . Buckets { if * bucket . Name == bucketName { shouldCreateBucket = false break } } if shouldCreateBucket { _ , err = upld . S3Manager . CreateBucket ( & s3 . CreateBucketInput { Bucket : aws . String ( bucketName ) , } ) if err != nil { return err } err = upld . S3Manager . WaitUntilBucketExists ( & s3 . HeadBucketInput { Bucket : aws . String ( bucketName ) , } ) if err != nil { return err } } return nil }
SetupBucket creates an AWS bucket with the specified name from ENV var if it does not exist already.
SetupBucket creates an AWS bucket with the specified name from ENV var if it does not exist already .
// Create the S3 Bucket // Wait until bucket is created before finishing