# Attach/overwrite DynamoDB table?

**URL:** <https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [February 19, 2017, 2:15am UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349 "2017-02-19T02:15:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhlsthrm](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rhlsthrm/32/472_2.png) [@rhlsthrm](https://forum.serverless.com/u/rhlsthrm)\
**Post date:** [February 19, 2017, 2:15am UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349/1 "2017-02-19T02:15:46Z")

</div>

The documentation states that you can overwrite/attach existing resources: [https://serverless.com/framework/docs/providers/aws/guide/resources/](https://serverless.com/framework/docs/providers/aws/guide/resources/). However, when I deploy a DynamoDB configuration with an existing table, I get an error saying `- ${TABLE-NAME} already exists.`. How do I configure my YAML to either overwrite or attach to an existing table?

---

<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:** [February 19, 2017, 10:18am UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349/2 "2017-02-19T10:18:06Z")

</div>

In that context I think override is change the defaults that Serverless sets and attach is adding additional resources. If you want to use a DynamoDB table that’s been created outside of Serverless you just need to give your Lambda the relevant IAM permissions to access it.

---

<div class="post-metadata">

**Author:** ![rhlsthrm](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rhlsthrm/32/472_2.png) [@rhlsthrm](https://forum.serverless.com/u/rhlsthrm)\
**Post date:** [February 19, 2017, 7:21pm UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349/3 "2017-02-19T19:21:54Z")

</div>

> [@buggy](#):
>
> If you want to use a DynamoDB table that’s been created outside of Serverless

If the DynamoDB table is created through Serverless, will the behavior be to create a new table every time it is redeployed (overwrite)?

> [@buggy](#):
>
> you just need to give your Lambda the relevant IAM permissions to access it

Is there an example of how to do this somewhere? I think having two example cases would be good, one which overwrites a resource, and one which attaches to an already running 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:** [February 19, 2017, 10:41pm UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349/4 "2017-02-19T22:41:05Z")

</div>

If it’s created through Serverless then it won’t create the table again. Obviously this only applies if you’re providing a unique table name so don’t expect it to work if you’re deploying development, staging and production to the same account but you don’t prefix or suffix your table with the stage name.

I don’t have a tested example handy but I would assume it’s the same way you normally provide access to DynamoDB tables.

```auto
provider:
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DeleteItem
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:UpdateItem
        - <OTHER-ACTIONS-HERE>
      Resource: <PUT-YOUR-TABLES-ARN-HERE>

```

---

<div class="post-metadata">

**Author:** ![rhlsthrm](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rhlsthrm/32/472_2.png) [@rhlsthrm](https://forum.serverless.com/u/rhlsthrm)\
**Post date:** [February 20, 2017, 12:04am UTC](https://forum.serverless.com/t/attach-overwrite-dynamodb-table/1349/5 "2017-02-20T00:04:33Z")

</div>

Thanks, this is how I have mine set up. For whatever reason, I don’t get an error when I re-deploy when the DB table exists. Now everything works fine and I can redeploy to the same db.
