LoginSignup
3
1

More than 3 years have passed since last update.

Serverless Frameworkでdynamoのttlを設定するときはcloud formationを使う

Last updated at Posted at 2019-07-22

経緯

QiitaやclassmethodでHitする記事だと serverless-dynamodb-ttl pluginを使うように紹介されているが、cloud formationに同一の機能が実装されたことによって現在このレポジトリはアーカイブされている。

AWS CloudFormation supports now TTL, so this plugin for Serverless is useless. More information about how to use it in the AWS documentation.

repository
https://github.com/Jimdo/serverless-dynamodb-ttl

日本語の記事
https://dev.classmethod.jp/cloud/aws/enabling-dynamodb-ttl-with-serverless-framework-or-aws-sam/
https://qiita.com/sayama0402/items/28fe9b51b17c2bd66324

Cloud formationで書こう

tableの定義部分に以下のように記載すればOK

TimeToLiveSpecification:
  AttributeName: attr_name
  Enabled: true

全体の定義は以下の感じで書けばOK.


    userTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: table_user
        AttributeDefinitions:
          - AttributeName: table_category
            AttributeType: S
          - AttributeName: id
            AttributeType: S
          - AttributeName: expired_at_unix_time
            AttributeType: N
        KeySchema:
          - AttributeName: table_category
            KeyType: HASH
          - AttributeName: id
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TimeToLiveSpecification:
          AttributeName: expired_at_unix_time
          Enabled: true

結論

pluginじゃなくて公式のcloud formation使おう。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1