4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AmplifyでTTLを設定する

Posted at

概要

graphql-ttl-transformerを利用すると、
AmplifyでDynamoDBをschema.graphqlで管理する場合、例えば以下のように属性の後に@ttlを付けるとTTL(Time To Live)を設定できます

schema.graphql
type Message @model @key(fields: ["fromUserId", "toUserId"]) {
  fromUserId: String!
  toUserId: String!
  message: String!
  ttl: AWSTimestamp! @ttl
  createdAt: AWSDateTime
  updatedAt: AWSDateTime
}

この状態でamplify pushすれば該当属性(上の例だとttl)にTTLが設定されます
また、TTLを設定可能な型はAWSTimestampとIntのみです

導入

npm install --save graphql-ttl-transformerした後、
./amplify/backend/api/<API名>/transform.conf.jsonに下記のようにtransformersを追記します

./amplify/backend/api//transform.conf.json
"transformers": [
    "graphql-ttl-transformer"
]

注意

Amplify ConsoleなどでCI/CDをする場合、ビルド時にamplifyPush --simpleすると思うのですが、
graphql-ttl-transformerがamplifyPush時に必要になるため、amplifyPushより前にnpm installもしくはnpm ciする必要があります

これをしていない場合、ビルド時にUnable to import custom transformer moduleが返ってきます

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?