Tips for retrieving only the changes or updates from DynamoDB streams

Currently, I am faced with a scenario where I must comprehend the distinction between NEW_IMAGE and OLD_IMAGE on dynamoDB streams.

As per the information available at:

https://aws.amazon.com/blogs/database/dynamodb-streams-use-cases-and-design-patterns/

DynamoDB Streams offers various stream record viewpoints:

KEYS_ONLY—Consisting of only the key attributes of the modified item
NEW_IMAGE—Comprising the complete item after modification
OLD_IMAGE—Containing the complete item before being modified
NEW_AND_OLD_IMAGES—Showcasing both the new and old versions of the item

I am unable to subscribe for observing IMAGE_DIFFERENCE or similar events.

Hence, what would be the optimal approach to address this query? Kindly provide an example, preferably in JavaScript/TypeScript.

Answer №1

One way to approach this is by monitoring NEW_AND_OLD_IMAGES and comparing them manually. If AWS were to introduce an IMAGE_DIFFERENCE feature, it would require a unique method of indicating deleted and added entries. However, implementing such functionality could potentially increase latency in the streams, making it less practical for various use cases.

Answer №2

To achieve the desired result, you can utilize the functions unmarshall and json-diff:

npm install json-diff

const { unmarshall } = require("@aws-sdk/util-dynamodb");
const jsonDiff = require('json-diff');

exports.handler = async (event) => {
    console.log(JSON.stringify(event));
    const dynamoDBEvent = event.Records[0].dynamodb;
    const newImage = unmarshall(dynamoDBEvent.NewImage);
    const oldImage = unmarshall(dynamoDBEvent.OldImage);
    const diff = jsonDiff.diffString(oldImage, newImage)
    console.log(diff);
    return 'completed';
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to perform a nextAuth sign in using Postman?

I am currently working on implementing user authentication using NextAuth. The authentication works perfectly within my webapp, but now I want to test the sign-in functionality using Postman so that I can share the login endpoint. Below is the configuratio ...

Is there a way to retrieve and store a JSON object from a URL using JavaScript and jQuery?

I have a PHP page that is returning a JSON object in the correct format, like this: [ { "name":"Users", "parent":"null", "children":[ { "name": "adsd", "parent": "Users", "children": [] } , { "name": "ca", "p ...

Tips for storing JQUERY GET response (data) for later use in a separate function

In my database, there is a table that looks like this: +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------------- ...

Modifying TextField color in a react application with Material UI

I have a react component that consists of a text field and a button. I want these elements to be displayed in green color on a black background, but I am unable to modify the default colors of all the elements. Following a similar query on how to change th ...

Enhancing React with TypeScript: Best Practices for Handling Context Default Values

As I dive into learning React, TypeScript, and Context / Hooks, I have decided to create a simple Todo app to practice. However, I'm finding the process of setting up the context to be quite tedious. For instance, every time I need to make a change t ...

Error: DataTables FixedColumn module "Uncaught ReferenceError: FixedColumns is not defined"

I am currently struggling to implement the FixedColumns plugin from datatables. I am following the example code provided on the website: $(document).ready( function () { var oTable = $('#example').dataTable( { "sScrollX": "100%", ...

Monitor the number of clicks (conversions) on Google Adwords

On my website, I have a contact form and I would like to keep track of how many people click on it and gather information similar to what Google analytics provides. Here is what I want the form to do: When the button is clicked Ensure that all fields are ...

Encountering an error: Module missing after implementing state syntax

My browser console is showing the error message: Uncaught Error: Cannot find module "./components/search_bar" As I dive into learning ReactJS and attempt to create a basic component, this error pops up. It appears after using the state syntax within my ...

What is the best way to connect two buttons in separate divs?

I'm facing a challenge of adding two buttons side by side when they are located in different div elements. I've tried using the float property in the btn-group, but it interferes with the functionality of the dropdown and affects the animation. H ...

Troubleshooting issues with Angular 2 HTTP post and Web API integration

Here is an example of my Web Api Core Controller Method: public void Post(Sample sample) { _sampleService.CreateSample(sample); } The Sample POCO is defined as follows: public class Sample : BaseEntity { public string BarCode { get; s ...

What is the process for transforming a JSON object into a TypeScript interface?

After receiving a JSON output from an api: { "id": 13, "name": "horst", "cars": [{ "brand": "VW", "maxSpeed": 120, "isWastingGazoline": true ...

What is the most effective way to access a variable from a service in all HTML files of Angular 2/4 components?

In my angular 4 project, I have an alert service where all components can set alerts, but only specific components display them in unique locations. My question is: how can I access a variable from this service across all HTML files? The structure of my s ...

What is the best way to restrict a mapped type in typescript to only allow string keys?

In the Typescript documentation, I learned about creating a mapped type to restrict keys to those of a specific type: type OptionsFlags<Type> = { [K in keyof Type]: boolean; }; If I want to use a generic type that only accepts strings as values: t ...

Code for remotely connecting to a server and starting a Node.js application called app.js via SSH

I am attempting to establish an SSH connection to two servers sequentially in order to execute the following command: sudo node app.js This is the code I am using: #!/bin/bash while read line; do ssh -i "sshtest.pem" ec2-user@$line "sudo node app. ...

using vuejs to pass a function as a prop

As I work on creating a foundational "TableComponent," incorporating selectable rows and more, I am faced with the requirement for this TableComponent to accept a prop named "buttons." These buttons are expected to be in the form of an array of objects ...

What is the reason behind angular 4.3's httpclient returning Object instead of any?

The Angular 4.3 update introduces the new HttpClient class, which appears to return Object instead of any as the default type. Is there a specific reason for this decision, especially considering the TypeScript documentation advises against using types li ...

Google Maps API now offers the ability to generate directions with up to 500 waypoints

I am facing a challenge with displaying a route on Google Maps using an array of 500 waypoints extracted from a GPS route. Google Maps is unable to create a direction or route with more than 23 waypoints, making it difficult to replicate the original GPS ...

Sort by characteristics of embedded array - Knockout

I'm struggling with filtering a nested array using Knockout. My goal is to filter the array by both 'tag-names' and 'name'. For example, searching for 'whal' should display all objects that contain a tag with that name ...

What is the standard approach for indicating the lack of a specific attribute?

Is there a standardized way to specify that a specific property must definitely NOT appear on an object? I have come up with a method like this: type NoValue<T extends { value?: never, [key: string]: unknown }> = T type Foo = NoValue<{}> // Thi ...

How to ensure unique results when using DFS for Combination Sum?

I am currently tackling the challenge of solving LeetCode #49 Combination Sum. The objective here is to identify all the distinct combinations that add up to the specified target. While it's relatively straightforward to find permutations that result ...