Background
I would like to create a DynamoDB trigger such that on each new entry the value is updated before saving.
The DynamoDB table consists of Jobs/tasks and I would like to do calculations and assign the job/task to the respective employee.
The task seems relatively simple just need some guidance and assistance creating a lamda function that can accomplish this.
CodePudding user response:
[...] the value is updated before saving.
I am afraid that DynamoDB streams do not work like this. The stream will contain only items that are already stored in the table.
One way to solve this, is to add another property to your table that indicates if the "job" is ready to process. By default, jobs that are added to the table are "not ready", then the DynamoDB stream is going to trigger your Lambda, which does its calculations, assigns the job to an employee AND sets the job to "ready".
Another option to solve this might be a little restructuring. For example: why not use a Step Function that has multiple steps, the final one being a step to save the calculated result of the previous step(s) into the table.
CodePudding user response:
More than likely, you'll end up enabling DynamoDB Streams with a Lambda function to read from that stream. That'll give you the "on each new entry the value is..." The function would then do the calculations and assigning of the job you mentioned. I recommend starting with this from the DynamoDB documentation on Lambda triggers as well as this from the AWS Lambda documentation on working with DynamoDB Streams.
If that does not get you going in the right direction, let me know and I will dig up more for you.