Skip to content

Commit b71c7b8

Browse files
committed
🐛 fix: s3 bucket in us-east-1 should not set locations
`us-east-1` is invalid as a Location Contraint when creating a bucket. "Buckets in Region us-east-1 have a LocationConstraint of null."[1] [1] https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html#API_GetBucketLocation_ResponseSyntax
1 parent 25a0086 commit b71c7b8

File tree

1 file changed

+9
-4
lines changed
  • pkg/cloud/services/s3

1 file changed

+9
-4
lines changed

pkg/cloud/services/s3/s3.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import (
3838
"sigs.k8s.io/cluster-api-provider-aws/v2/util/system"
3939
)
4040

41+
// AWSDefaultRegion is the default AWS region.
42+
const AWSDefaultRegion string = "us-east-1"
43+
4144
// Service holds a collection of interfaces.
4245
// The interfaces are broken down like this to group functions together.
4346
// One alternative is to have a large list of functions from the ec2 client.
@@ -223,11 +226,13 @@ func (s *Service) Delete(m *scope.MachineScope) error {
223226
}
224227

225228
func (s *Service) createBucketIfNotExist(bucketName string) error {
226-
input := &s3.CreateBucketInput{
227-
Bucket: aws.String(bucketName),
228-
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
229+
input := &s3.CreateBucketInput{Bucket: aws.String(bucketName)}
230+
231+
// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#AmazonS3-CreateBucket-request-LocationConstraint.
232+
if s.scope.Region() != AWSDefaultRegion {
233+
input.CreateBucketConfiguration = &s3.CreateBucketConfiguration{
229234
LocationConstraint: aws.String(s.scope.Region()),
230-
},
235+
}
231236
}
232237

233238
_, err := s.S3Client.CreateBucket(input)

0 commit comments

Comments
 (0)