ine-labs / AWSGoat

AWSGoat : A Damn Vulnerable AWS Infrastructure
MIT License
1.67k stars 983 forks source link

S3 bucket: BucketAlreadyExists #50

Closed za closed 4 months ago

za commented 5 months ago

Hi there,

I am getting this ERROR after running terraform on my local linux machine:

cd modules/module-1
terraform init
terraform apply --auto-approve
│ Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
│       status code: 409, request id: <snip>, host id: <snip>
│ 
│   with aws_s3_bucket.bucket_temp,
│   on main.tf line 3354, in resource "aws_s3_bucket" "bucket_temp":
│ 3354: resource "aws_s3_bucket" "bucket_temp" {

This is the list of my s3 buckets:

aws s3 ls

dev-blog-awsgoat-bucket-...
do-not-delete-awsgoat-state-files-...
production-blog-awsgoat-bucket-...

Am I missing something? Thanks.

za commented 4 months ago

It works, after I renamed the bucket name to ec2-temp-bucket-qwerty-${data.aws_caller_identity.current.account_id}:

$ terraform apply --auto-approve

Apply complete! Resources: 44 added, 1 changed, 2 destroyed.

Outputs:

app_url = "<snip>.amazonaws.com/prod/react"
SSKale1 commented 4 months ago

The error was due to the S3 bucket naming conventions Bucket names must be unique across all AWS accounts in all the AWS Regions within a partition, thus you received the "BucketAlreadyExists" error, someone named a bucket ec2-temp-bucket-(Your Account ID).

za commented 4 months ago

Hmm... but why somehow I can create this bucket on different region? For example: ap-southeast-3 @SSKale1 .

za commented 4 months ago

Similar issue: https://github.com/cloudposse/terraform-aws-tfstate-backend/issues/54