Attach/overwrite DynamoDB table?

The documentation states that you can overwrite/attach existing 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?

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.

1 Like

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

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,

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.

    - Effect: Allow
        - dynamodb:DeleteItem
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:UpdateItem
      Resource: <PUT-YOUR-TABLES-ARN-HERE>
1 Like

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.