Error creating S3 Bucket via resources section entry (...<bucket_name> already exists.)


I am trying to create an S3 bucket as part of my AWS stack deploy. However, regardless what I try I have always been met by the same error message. I have only been running the stack for the same account to the same region, and there has never existed an S3 bucket with this name (pdf-bucket-dev), and it is not existing now.

The error message snippets I get from AWS / Serverless deploy is:

CloudFormation - CREATE_FAILED - AWS::S3::Bucket - PdfBucket

An error occurred: PdfBucket - pdf-bucket-dev already exists.

This is my serverless.yaml file:

service: sls-playground 

  name: aws
  runtime: nodejs8.10
  stage: ${opt:stage, 'dev'}
  region: eu-central-1

    handler: handler.hello
      PDFBUCKET: pdf-bucket-${self:provider.stage}

      Type: AWS::S3::Bucket
        BucketName: pdf-bucket-${self:provider.stage}

I have tried my best Google skills to see if this is a known issue and what I could be missing, but I’ve come up short. Also, I’ve tried adding some of the optional Poperties to see if it would make a difference.

Any ideas what I’m doing wrong?

S3 bucket are globally unique. Once someone creates a bucket called pdf-bucket-dev no one else can use that in their AWS account. You need to find another name.

you can use your project name as prefix for every bucket you want to create via serverless.
For Eg.

BucketName: sls-playground-pdf-bucket-${self:provider.stage}

So sls-playground will be a prefix in you case and you can keep your bucket unique by using this.

Thanks for your input. Prefixing the bucket name with the service name is of course a good best practice to create useable name spaces.

This is rather embarrassing, but changing to another bucket name did make the deploy go through…

I’m not sure why I in the Web console cannot see an S3 Bucket named “pdf-bucket-dev” though? If it existed it should have been visible there, right? I have only ever used one AWS account, which is the one serverless is set up with.

In any case, I can proceed with my deployments now. Thanks!

Because it most likely belongs to somebody else on a completely different account.
Globally Unique in the sense of bucket names means across ALL AWS accounts. Not just yours.
So if I create a bucket named “my-super-sekret-bucket” in my account, you won’t be able to create a bucket with that name. Nor will you be able to see it since it’s in my account.

Hope that makes it more clear.

Ohh. Got it! Did not realise this was the case…

Thanks all for your input.