Cannot redeploy - UploadBucket slsupload already exists

Hi, this might be a Cloudformation problem, but as I use Cloudformation only through serverless, I start asking here:

On my way to try walking through a tutorial for a serverless service to write to S3 (https://www.netlify.com/blog/2016/11/17/serverless-file-uploads/ ) I bump into the situation that I cannot deploy my service again.

When running deploy, I get an error message:

“An error occurred while provisioning your stack: UploadBucket
- slsupload already exists.”

I also executed the remove command, which seemed to run successful, at least no error message.
In the cloudformation stack view in the aws web interface it clearly said that it also remove the S3 resource successfully.

I the S3 webinterface on AWS there is no Bucket with either the name slsupload nor UploadBucket (I am not sure under which name it is supposed to appear).

My questions are:

  • were do I actually see this bucket in S3
  • why is it not deleted with sls remove?
  • are these cloudformation resources not idempotent?

my serverless.yml is:

service: s3-writer-test

provider:
name: aws
runtime: nodejs6.10
region: eu-central-1
iamRoleStatements:
- Effect: "Allow"
Action:
- “s3:"
Resource: "arn:aws:s3:::slsupload/

functions:
writeme:
handler: handler.writeme
events:
- http:
path: writeme
method: get

resources:
Resources:
UploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: slsupload
AccessControl: PublicRead
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- PUT
- POST
- HEAD
AllowedOrigins:
- “"
AllowedHeaders:
- "

Keep in mind that S3 Bucket names need to be globally unique.
So anybody else who’s done that tutorial has run into the same problem.
Netlify should update their tutorial to explain that you need to alter the bucket name to make it unique.
eg. instead of ‘slsupload’ pick something like 'henning-dev-slsupload’
and use that value throughout the tutorial.

Hope this helps.

For more info see the #3 on this amazon S3 Getting Started page:
and Rules for Bucket Naming in the Developers Guide.

2 Likes

yes, that seems to work!

If I rename the bucket I can also deploy and deploy my application again!

Maybe I oversaw that this error appeared already the first time I deployed it.

Thanks!

1 Like

Glad I could help.
And yes. as long as you keep the bucket, nobody else can take your bucket name.
Therefore, you can re-deploy as much as you wish forever.