How to create or update S3 in serverless.yml

Hi, Everyone.

I created serverless.yml to create S3 on AWS.
When it is executed, it will succeed the first time, but it fails after the second time.

Error message is 'An error occurred while provisioning your stack: S3Bucket

  • S3BuketName already exists’.

I would like to update some S3, but how should I write it in serverless.yml?
Please teach me how to write in serverless.yml.

Current Code.

resources:
Resources:
●●Files:
Type: AWS::S3::Bucket
Properties:
BucketName: ★★★★★★★★★-●●
▲▲Files:
Type: AWS::S3::Bucket
Properties:
BucketName: ★★★★★★★★★-▲▲
■■Files:
Type: AWS::S3::Bucket
Properties:
BucketName: ★★★★★★★★★-■■

1 Like

Can you format your code properly by including ```yaml on the line before and ``` on the line after it? In YAML files formatting is significant.

Have the same issue. Can anyone provide an answer please?

@ghdna It would be helpful if you can post the relevant part of your serverless.yml. Are you deploying to the same stage & region or a different one?

The error message says what the issue is: S3BucketName already exists. However CloudFormation should know that it already created the bucket, and not attempt to create it again on a subsequent deployment. So this is certainly not the expected behaviour.

Can you confirm 2 things:

  1. As asked by @buggy, are you sure you are using the same account and region for the first and second deployments?
  2. Have you manually changed anything via the AWS console or cli?

The reason for checking account and region is, deploying to a different region (or account) will create a new stack which won’t “know” that the S3 bucket was already created in the first stack. If you are deploying to multiple regions, then you need to either have a bucket per region (include the region in the bucket name), or if you want to use a common bucket, you need to have one stack that creates the bucket and exports it (using Outputs) for other stacks to use. If you are planning on using the serverless config to create the same service in multiple AWS accounts, then you want to put the account id, or some other, account-specific parameter (e.g. given as an option to the serverless command) into the bucket name.

Assuming that’s not the problem, I would log into the console and go to CloudFormation, and check:

  1. Whether the stack you are deploying to is the stack that is listed there (or if there are multiple stacks when there should be one, maybe that is the cause).
  2. Whether the S3 bucket is indeed listed under that stack (under Resources).

Ok, let me check cloud formation template. I had given up after a whole day of trying to fix it.

I have the exact same issue here and I have confirmed that I am working in the same region, and that the bucket is NOT listed as a resource. Any pointers greatly appreciated.

My serverless.yml file:

service: visualcomparison

provider:
  name: aws
  runtime: nodejs6.10

functions:
  hello:
    handler: handler.hello
    events: 
      - s3: 
          bucket: new-bloom-image-bucket
          event: s3:ObjectCreated:*
          rules:
            - suffix: .png

plugins:
  - serverless-offline

Update: randomly trying to deploy again and it actually succeeded, however, the s3 bucket does not appear as listed under the lambda function resources, and uploading an object to this bucket does not trigger an event calling this function. :frowning: At a loss…

did u resolve this? facing the same issue