Can you use aws-sdk util-dynamodb unmarshall in Reactjs

0 votes

I have a Dynamodb post request resource that an API Gateway resource calls to query a table. I'm attempting to use Axios within my React app to call the API. The API is functioning and returning the desired data (console log), but when I attempt to use @aws-sdk/util-dynamodb (unmarshall) to convert the API data, I encounter issues. converting the item response into JSON for usage in React.

./node_modules/@aws-sdk/util-dynamodb/dist-es/convertToNative.js 45:14 Module parse failed: Unexpected token (45:14)

Is there a way to use 'unmarshall' within React? Something like this:

    useEffect(() => {
    const getGoal = async () => {
        try {
            const response = await api.get(apiUrl)
            setGoal(unmarshall(response.data.Items))

This works if I use a Lambda service, but I'm try to see if I can reduce my code.

Jan 3, 2023 in AWS by Tejashwini
• 3,820 points
384 views

1 answer to this question.

0 votes

Yes, you can use the unmarshall method from the AWS SDK for JavaScript in ReactJS. The AWS SDK for JavaScript provides a set of libraries that allow you to interact with AWS services from JavaScript code, including ReactJS. The unmarshall method is part of the AWS.DynamoDB.Converter module, which provides utility methods for converting between JavaScript data types and DynamoDB data types.

To use the unmarshall method in ReactJS, you will first need to install the AWS SDK for JavaScript by running the following command:

npm install aws-sdk

Next, you will need to import the AWS.DynamoDB.Converter module and the unmarshall method into your ReactJS code. You can do this by adding the following line at the top of your file:

import { DynamoDB } from 'aws-sdk';

Then, you can use the unmarshall method to convert a DynamoDB item into a JavaScript object by calling the method and passing in the DynamoDB item as an argument, like this:

const item = { "id": { "N": "123" }, "name": { "S": "John Smith" }, "age": { "N": "35" }, "location": { "S": "New York" } }; const obj = DynamoDB.Converter.unmarshall(item); console.log(obj); // Output: { id: 123, name: 'John Smith', age: 35, location: 'New York' }

You can then use the resulting JavaScript object in your ReactJS code as needed.

For more information, you can refer to our React Certification today. 

answered Jan 4, 2023 by Ashwini
• 5,430 points

Related Questions In AWS

0 votes
1 answer
0 votes
0 answers
+5 votes
2 answers

Can we export/migrate users from AWS cognito, does it cause vendor lock-in?

Cognito actually has the capability to import ...READ MORE

answered Aug 1, 2018 in AWS by bug_seeker
• 15,520 points
4,417 views
0 votes
2 answers
+3 votes
3 answers
0 votes
1 answer

Trying to use GetApiKeys in Amazon SDK

Try using this one:  var client = new ...READ MORE

answered Jun 12, 2018 in AWS by Cloud gunner
• 4,670 points
853 views
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,300 points
3,579 views
0 votes
4 answers

ReactJS vs Angular Comparison: Which is better?

Parameters React Angular Type React is a JavaScript library, and it ...READ MORE

answered Jan 7, 2021 in Events & Trending Topics by Focusteck
• 140 points
1,115 views
+2 votes
4 answers
0 votes
1 answer

Amazon DynamoDB: warning

Yes, you should address this problem. You can ...READ MORE

answered Aug 30, 2018 in AWS by Priyaj
• 58,090 points
395 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP