# Two serverless projects use same dynamodb item

**URL:** <https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354>\
**Category:** Serverless Framework\
**Created:** [July 22, 2017, 5:41pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354 "2017-07-22T17:41:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EthanChou](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@EthanChou](https://forum.serverless.com/u/EthanChou)\
**Post date:** [July 22, 2017, 5:41pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354/1 "2017-07-22T17:41:22Z")

</div>

I create two serverless project and first one create dynamoDB item call: userInfo,  
and when I create the second one and try to access the userInfo item, deploy failed,  
error message : `already exists in stack "the first one's stack"`  
is it possible to share item between two cloudFormation?

**first serverless project:**

```
resources:
  Resources:
    EmailsDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: 'userinfo'

```

**second project: deploy failed**

```
resources:
  Resources:
    TodosDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.DYNAMODB_TABLE}
    testDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      # DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: 'userinfo'
```

---

<div class="post-metadata">

**Author:** ![EthanChou](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@EthanChou](https://forum.serverless.com/u/EthanChou)\
**Post date:** [July 22, 2017, 6:15pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354/2 "2017-07-22T18:15:24Z")

</div>

i think i know why,  
there’s no need to add `resources: xxxDynamoDbTable` if the item already exists

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [July 23, 2017, 9:14pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354/3 "2017-07-23T21:14:12Z")

</div>

Just for any one else who comes across this, the short answer is you can’t manage the same resource in multiple CloudFormation templates (or Serverless services).

As you’ve already discovered, what’s happening here is that your second service is trying to create a DDB table with the same name, and table names must be unique.

Your options are:

- Include the service name in the table name, which will make it unique. This doesn’t really help you if you only really want one table.
- Create your DDB table separately. You could do this with “pure” CloudFormation, through the web console by hand (yuck!), or though a “resources only” Serverless service - just create a `serverless.yml` with a `resources` section and no functions, and manage it just like a normal service (e.g. with `sls deploy`, etc).

---

<div class="post-metadata">

**Author:** ![ramanbuttar](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@ramanbuttar](https://forum.serverless.com/u/ramanbuttar)\
**Post date:** [July 27, 2017, 6:14pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354/4 "2017-07-27T18:14:50Z")

</div>

Is there a way to have serverless skip creating the DDB if it already exists?

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [July 27, 2017, 8:05pm UTC](https://forum.serverless.com/t/two-serverless-projects-use-same-dynamodb-item/2354/5 "2017-07-27T20:05:39Z")

</div>

Not from another template/service. Deploying the same template does exactly that.

One of the **major** benefits of using CloudFormation is idempotent deployments - having a template that does one thing one time and another thing another time (based on some outside state, not expressed in the parameters) would break that.
