# DynamoDB and TTL

**URL:** <https://forum.serverless.com/t/dynamodb-and-ttl/8274>\
**Category:** Serverless Framework\
**Created:** [May 15, 2019, 8:51am UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274 "2019-05-15T08:51:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dombarter](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dombarter/32/3320_2.png) [@dombarter](https://forum.serverless.com/u/dombarter)\
**Post date:** [May 15, 2019, 8:51am UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274/1 "2019-05-15T08:51:33Z")

</div>

Is there anyway to define the TTL attribute in the serverless config file rather than having to log in and define this setting in the web console? I have not found any documentation regarding this - am I missing something?

---

<div class="post-metadata">

**Author:** ![moro](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/moro/32/4303_2.png) [@moro](https://forum.serverless.com/u/moro)\
**Post date:** [May 15, 2019, 11:22am UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274/2 "2019-05-15T11:22:14Z")

</div>

Hi, I think you can define your table as a resource and set `TimeToLiveSpecification`  
[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html)  
Is this what you need?

---

<div class="post-metadata">

**Author:** ![dombarter](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dombarter/32/3320_2.png) [@dombarter](https://forum.serverless.com/u/dombarter)\
**Post date:** [May 17, 2019, 7:39pm UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274/3 "2019-05-17T19:39:00Z")

</div>

I think it is. Thankyou

---

<div class="post-metadata">

**Author:** ![hons82](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hons82/32/6097_2.png) [@hons82](https://forum.serverless.com/u/hons82)\
**Post date:** [August 16, 2021, 3:05pm UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274/4 "2021-08-16T15:05:33Z")

</div>

I can’t currently get that to work, maybe the format of my field is worng.  
Do you have an example configuration for this?

---

<div class="post-metadata">

**Author:** ![ykarulin](https://avatars.discourse-cdn.com/v4/letter/y/c4cdca/32.png) [@ykarulin](https://forum.serverless.com/u/ykarulin)\
**Post date:** [October 5, 2022, 4:22am UTC](https://forum.serverless.com/t/dynamodb-and-ttl/8274/6 "2022-10-05T04:22:07Z")

</div>

Here is what worked for me:

```auto
resources:
    Resources:
      MyPersonalTable:
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: MyPersonalTable
          AttributeDefinitions:
            - AttributeName: keyValueOfMyTable
              AttributeType: S
          KeySchema:
            - AttributeName: keyValueOfMyTable
              KeyType: HASH
          TimeToLiveSpecification:
            AttributeName: timeToLive
            Enabled: true

```
