# Error: Bucket already exists when redeployed

**URL:** <https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029>\
**Category:** Serverless Framework\
**Created:** [June 8, 2017, 6:12pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029 "2017-06-08T18:12:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![luebken](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/luebken/32/706_2.png) [@luebken](https://forum.serverless.com/u/luebken)\
**Post date:** [June 8, 2017, 6:12pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/1 "2017-06-08T18:12:27Z")

</div>

Hi

severless / AWS noob here.

I have started with a simple version of a function (hello) which stores some data in an s3 bucket. This all worked fine.

Next I added a function that I wanted to get triggered whenever a s3 object is stored. The resulting severless.yaml looks like this:

```
service: aws-nodejs

provider:
  name: aws
  runtime: nodejs6.10

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:*"
      Resource: "arn:aws:s3:::test-s3bucket2/*"

functions:
  hello:
    handler: handler.hello
  stored:
    handler: handler.stored
    events:
      - s3: test-s3bucket2

resources:
  Resources:
    NewResource:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: test-s3bucket2

```

Now after I deploy it again I get an error that the bucket already exists:

```
$ sls deploy -s dev
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (598 B)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
....................Serverless: Deployment failed!

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

     An error occurred while provisioning your stack: S3BucketTests3bucket2
     - test-s3bucket2 already exists in stack arn:aws:cloudformation:us-east-1:339468856116:stack/aws-nodejs-dev/498e8ca0-4c6b-11e7-9da6-50fae98b1835.

  Get Support --------------------------------------------
     Docs: docs.serverless.com
     Bugs: github.com/serverless/serverless/issues
     Forums: forum.serverless.com
     Chat: gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS: darwin
     Node Version: 7.10.0
     Serverless Version: 1.13.2

```

This brings me to some questions:

- What does the error really say / mean? Removing the resource section from the yaml didn’t help.
- How are (s3) resources handled? What is the proposed way of working with these?
- How is cloudformation handling these? Are these calls not idempotent?

Thanks  
Matthias

---

<div class="post-metadata">

**Author:** ![luebken](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/luebken/32/706_2.png) [@luebken](https://forum.serverless.com/u/luebken)\
**Post date:** [June 8, 2017, 7:59pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/2 "2017-06-08T19:59:19Z")

</div>

So deleting the bucket manually and other resources via `sls remove` worked. But after adding a third test function and trying to redeploy I got the same error.

---

<div class="post-metadata">

**Author:** ![khinester](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/khinester/32/315_2.png) [@khinester](https://forum.serverless.com/u/khinester)\
**Post date:** [June 9, 2017, 9:35am UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/3 "2017-06-09T09:35:09Z")

</div>

> [@luebken](#):
>
> Resources:  
> NewResource:  
> Type: AWS::S3::Bucket  
> Properties:  
> BucketName: test-s3bucket2

In your handler, you are already creating the resource, so remove the resource

```
  Resources:
    NewResource:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: test-s3bucket2

```

will work.

---

<div class="post-metadata">

**Author:** ![amitm02](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/amitm02/32/1452_2.png) [@amitm02](https://forum.serverless.com/u/amitm02)\
**Post date:** [December 31, 2017, 5:07pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/4 "2017-12-31T17:07:37Z")

</div>

I have the same issue. What do you mean by “In your handler, you are already creating the resource”?

---

<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:** [January 2, 2018, 11:38pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/5 "2018-01-02T23:38:37Z")

</div>

> [@amitm02](#):
>
> What do you mean by “In your handler, you are already creating the resource”?

If you use the syntax

```yaml
events:
      - s3: photos

```

[/quote]

Then the s3 bucket is automatically created and you don’t need to define it in the resources section.

If you do want to define it in the resources section then you need to name the resource correctly so Serverless knows to override its own definition otherwise you end up trying to create two buckets with the same name.

---

<div class="post-metadata">

**Author:** ![amitm02](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/amitm02/32/1452_2.png) [@amitm02](https://forum.serverless.com/u/amitm02)\
**Post date:** [January 3, 2018, 11:05am UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/6 "2018-01-03T11:05:58Z")

</div>

> you need to name the resource correctly

what would be the correct way to name it both in the event and the resources section?

---

<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:** [January 3, 2018, 11:07pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/7 "2018-01-03T23:07:29Z")

</div>

@amitm02 Follow the example in the Serverless Framework docs.

> **[Serverless Framework - AWS Lambda Events - S3](https://www.serverless.com/framework/docs/providers/aws/events/s3)**
>
> The Serverless Framework documentation for AWS Lambda, API Gateway, EventBridge, DynamoDB and much more.

---

<div class="post-metadata">

**Author:** ![michaelm88](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@michaelm88](https://forum.serverless.com/u/michaelm88)\
**Post date:** [January 18, 2019, 8:39am UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/8 "2019-01-18T08:39:43Z")

</div>

Hi , what about if i don’t want to recreated the bucket but to use the already exists bucket

---

<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:** [January 22, 2019, 10:43am UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/9 "2019-01-22T10:43:28Z")

</div>

Then have a look at [https://github.com/mayconbordin/serverless-plugin-existing-s3](https://github.com/mayconbordin/serverless-plugin-existing-s3)

---

<div class="post-metadata">

**Author:** ![zamirajaupaj](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/zamirajaupaj/32/3136_2.png) [@zamirajaupaj](https://forum.serverless.com/u/zamirajaupaj)\
**Post date:** [March 12, 2019, 7:56pm UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/10 "2019-03-12T19:56:02Z")

</div>

Hi,  
in my handler, i’m using s3 as an event, but i have a problem to enable versioning of s3. im trying to do in this way, but the version is not going to enable

events:  
- s3:  
bucket: test  
VersioningConfiguration: Enabled  
event: s3:ObjectCreated:\*  
rules:  
- suffix: .jpg

---

<div class="post-metadata">

**Author:** ![joshua.hufford](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@joshua.hufford](https://forum.serverless.com/u/joshua.hufford)\
**Post date:** [June 11, 2021, 1:35am UTC](https://forum.serverless.com/t/error-bucket-already-exists-when-redeployed/2029/11 "2021-06-11T01:35:55Z")

</div>

Just add `existing: true`

events:  
- s3:  
bucket: test  
VersioningConfiguration: Enabled  
event: s3:ObjectCreated:\*  
**existing: true**  
rules:  
- suffix: .jpg

> **[Serverless Framework - AWS Lambda Events - S3](https://www.serverless.com/framework/docs/providers/aws/events/s3/)**
>
> Setting up AWS S3 Events with AWS Lambda via the Serverless Framework
