I have this problem when creating S3 bucket using CloudFormation. I get a 400 Bad request. Would appreciate if anyone can help.
aws cloudformation deploy --profile DEV --stack-name testBucket --template-file create_bucket.yml --region us-east-1 --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --parameter-overrides BucketName=myBucket
Template:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
BucketName:
Description: Provisioned read throughput for each table
Type: String
Resources:
MYBUCKET:
Type: AWS::S3::Bucket
Properties:
BucketName: ${BucketName}
MYBUCKETPOLICY:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref MYBUCKET
PolicyDocument:
Id: ReportPolicy
Version: "2012-10-17"
Statement:
- Sid: ReportBucketPolicyDoc
Effect: Allow
Action: "s3:*"
Principal:
AWS: !Join ['', ["arn:aws:iam::", !Ref "AWS::AccountId", ":root"]]
Resource: !Join ['', ['arn:aws:s3:::', !Ref MYBUCKET, '/*']]
Error
Bad Request (Service: Amazon S3; Status Code: 400; Error Code: 400 Bad Request; Request ID: B4AEAA3C454B7868; S3 Extended Request ID: ATFscTA4dQw8J8AYUfkIARYhiT4/BpVWRcD172WnR75Uzm+i5dlHOTC2HCb9drkO16dzYiELJZc=)
The following thread is relevant for anyone trying to change the region of an S3 bucket just after they have deleted a bucket in another region.
Essentially there's a delay between a bucket being deleted in one region and the name being available in all other regions. So if you deleted a bucket in ap-southeast-2
and then tried to create a bucket with the same name is us-east-1
you should expect to receive this kind of error.
https://github.com/aws/aws-cdk/issues/6646#issuecomment-597905903
You did not reference the BucketName
parameter correctly:
MYBUCKET:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${BucketName} # Or !Ref BucketName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With