Search code examples
amazon-web-servicesamazon-s3serverlessserverless-framework

S3 bucket already existing error - even after manually deleted it from aws


Am totally new to this serverless and AWS. am trying to create a S3 bucket using serverless

my serverless.yml file looks like this

service: s3-file-uploader 

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-2

custom:
  fileUploadBucketName: ${self:service}-bucket-${self:provider.stage} 

resources:
  Resources:
    FileBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:custom.fileUploadBucketName}
        AccessControl: PublicRead 

for the first time when I run serverless deploy it worked, but thereafter I have deleted the bucket manually from aws and try to redeploy it. It shows me this error

 Serverless Error ----------------------------------------

  An error occurred: FileBucket - s3-file-uploader-bucket-dev already exists.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              14.18.0
     Framework Version:         2.72.1
     Plugin Version:            5.5.4
     SDK Version:               4.3.0
     Components Version:        3.18.2

it says bucket with s3-file-uploader-bucket-dev this name already exists but there is no bucket with this name inside aws s3. even though it gives this error, also creates a bucket with the name of s3-file-uploader-dev-serverlessdeploymentbucket-1aucnojnjl618 but this is not the name I have given in the serverlesss.yml file it should be like s3-file-uploader-bucket-dev and in the cloudFormation there is a stack created with the name s3-file-uploader-dev and its status is UPDATE_ROLLBACK_COMPLETE.

Why it's showing the above-mentioned error and at the same time creating a bucket with a different name? it's confusing that give an error and create a bucket.


Solution

  • Bucket names are globally unique. You can read about it here and about deleting a bucket here. If the name has not been taken already by someone else, you need to wait for a "while" to reuse the same name. The time taken is unknown(afaik).