DynamoDB Auto Generate Timestamp

0

I have a DynamoDBTable "Post" which has a attribute "note". "note" holds a entity Note which is a DynamoDBDocument. I have a field createdAT in "Note". I'm trying to use @DynamoDBAutoGenerateTimestamp for createdAT field. But when i store an entry in "Post" table the createdAt in field in the DynamoDBDocument is not populated. Could you pls help me understand the behaviour and how can i fix that?

질문됨 일 년 전2968회 조회
2개 답변
0

DynamoDB supports the use of the @DynamoDBAutoGenerateTimestamp annotation to automatically populate a timestamp attribute when an item is created or updated in a DynamoDB table. However, this annotation only works on top-level attributes of an item, not on nested attributes within a DynamoDBDocument.

To fix this, you can have a few options:

One approach is to extract the "Note" entity out of the "Post" table and create a new table for it. Then you can use the @DynamoDBAutoGenerateTimestamp annotation on the "createdAt" attribute in the "Note" table. Another option is to use a Lambda function that is triggered by the DynamoDB Streams of the "Post" table. The Lambda function can check if the "createdAt" attribute in the "Note" entity is null, and if so, set it to the current timestamp before storing the item in the "Post" table. You can write a code in the application layer that will populate the createdAt field with the current timestamp before storing the item in the "Post" table. By using one of the above options, you should be able to automatically populate the "createdAt" attribute in the "Note" entity when an item is stored in the "Post" table.

profile picture
답변함 일 년 전
  • Thank you for the response :) Do we have an aws doc where this is behaviour is mentioned 🤔

0

"@DynamoDBAutoGenerateTimestamp" has a typo, did you actually use "@DynamoDBAutoGeneratedTimestamp"?

전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠