# How to create or update S3 in serverless.yml

**URL:** <https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [June 16, 2017, 5:44am UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080 "2017-06-16T05:44:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yamazaki](https://avatars.discourse-cdn.com/v4/letter/y/6de8d8/32.png) [@yamazaki](https://forum.serverless.com/u/yamazaki)\
**Post date:** [June 16, 2017, 5:44am UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/1 "2017-06-16T05:44:25Z")

</div>

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: ★★★★★★★★★-■■

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [June 16, 2017, 11:02am UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/2 "2017-06-16T11:02:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ghdna](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@ghdna](https://forum.serverless.com/u/ghdna)\
**Post date:** [June 30, 2017, 7:08pm UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/3 "2017-06-30T19:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [July 11, 2017, 11:30am UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/4 "2017-07-11T11:30:35Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![leftclickben](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/leftclickben/32/625_2.png) [@leftclickben](https://forum.serverless.com/u/leftclickben)\
**Post date:** [July 11, 2017, 1:48pm UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/5 "2017-07-11T13:48:36Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![ghdna](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@ghdna](https://forum.serverless.com/u/ghdna)\
**Post date:** [July 11, 2017, 6:37pm UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/6 "2017-07-11T18:37:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dlumma](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dlumma](https://forum.serverless.com/u/dlumma)\
**Post date:** [December 12, 2017, 7:22pm UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/7 "2017-12-12T19:22:49Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![dlumma](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dlumma](https://forum.serverless.com/u/dlumma)\
**Post date:** [December 12, 2017, 7:26pm UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/8 "2017-12-12T19:26:33Z")

</div>

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. ☹ At a loss…

---

<div class="post-metadata">

**Author:** ![pnandak](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@pnandak](https://forum.serverless.com/u/pnandak)\
**Post date:** [October 24, 2018, 10:54am UTC](https://forum.serverless.com/t/how-to-create-or-update-s3-in-serverless-yml/2080/9 "2018-10-24T10:54:14Z")

</div>

did u resolve this? facing the same issue
