DynamoDB and TTL

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?

1 Like

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
Is this what you need?

3 Likes

I think it is. Thankyou

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

Here is what worked for me:

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