DynamoDB based on condition on Table A write to Table B

0

I have a use-case where there is a rule db which stores rules and it's version id. A lambda evaluates the rule and write result to Table B. During the evaluation the rule can be updated in that case i want to previous write to fail. I want to check the rule version that got evaluated in Rule Table is the latest at the time of write. Can i achieve this via TransactWriteItems ?

질문됨 5달 전213회 조회
1개 답변
-1
수락된 답변

To achieve your goal of conditionally writing to Table B based on the rule version in Table A in DynamoDB, using TransactWriteItems is a suitable approach.

Here's how you can implement this:

  • Your Lambda function should evaluate the rule in Table A and prepare to write the result to Table B. As part of the transaction, you need to include a condition check on the rule version in Table A.
  • DynamoDB supports conditional writes using condition expressions. These expressions can check if certain attribute values in the item match what you expect them to be at the time of the request. For example, you can specify that the write operation to Table B should only occur if the version ID in Table A matches the one evaluated by your Lambda function​​.
  • In your TransactWriteItems call, you will have an array of TransactWriteItem objects. This will include the write operation to Table B and a ConditionCheck on Table A to verify the version ID. Remember that all operations within a TransactWriteItems call must succeed for the transaction to be committed. If any operation fails (such as the condition check on Table A), the entire transaction is rolled back.

Let me know if you have any further questions to discuss.

Regards!


*Edit: Removed PII—Alex L

profile picture
전문가
답변함 5달 전
profile pictureAWS
전문가
검토됨 5달 전

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

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

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

관련 콘텐츠