简体   繁体   English

您可以在 Reactjs 中使用 aws-sdk/util-dynamodb unmarshall 吗?

[英]Can you use aws-sdk/util-dynamodb unmarshall in Reactjs?

I have an API Gateway resource which calls a Dynamodb post request to query a table.我有一个 API 网关资源,它调用 Dynamodb 发布请求来查询表。 I'm trying to call the API within my React app using Axios. The API is working, returning the data as expected (console log) but I'm getting errors if I try to use @aws-sdk/util-dynamodb (unmarshall) to convert the api data.items response into JSON and use within React.我正在尝试使用 Axios 在我的 React 应用程序中调用 API。API 正在工作,按预期返回数据(控制台日志),但是如果我尝试使用 @aws-sdk/util-dynamodb(unmarshall ) 将 api data.items 响应转换为 JSON 并在 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?有没有办法在 React 中使用“unmarshall”? 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.如果我使用 Lambda 服务,这会起作用,但我会尝试查看是否可以减少我的代码。

While I'm not sure on the issue you are getting with unmarshall function, I would suggest using the DynamoDB Document Client which will return your data already unmarshalled.虽然我不确定您使用 unmarshall function 遇到的问题,但我建议使用 DynamoDB Document Client ,它将返回您已经解组的数据。

The DynamoDB Document client simplifies working with items by abstracting the notion of attribute values. DynamoDB Document 客户端通过抽象属性值的概念简化了对项目的处理。 This abstraction annotates native JavaScript types supplied as input parameters, and converts annotated response data to native JavaScript types.此抽象注释作为输入参数提供的本机 JavaScript 类型,并将带注释的响应数据转换为本机 JavaScript 类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 AWS-SDK DynamoDB 指向本地无服务器 DynamoDB - How to point AWS-SDK DynamoDB to a serverless DynamoDB local 找不到模块:错误:无法使用 React.JS 解析“node_modules/aws-sdk/lib”中的“util” - Module not found: Error: Can't resolve 'util' in `node_modules/aws-sdk/lib` using React.JS DynamoDB 表种子适用于 cli 但不适用于 AWS-SDK - DynamoDB table seed works in cli but not AWS-SDK `@aws-sdk/lib-dynamodb` DynamoDB delete() 函数返回无用的响应 - `@aws-sdk/lib-dynamodb` DynamoDB delete() function returning unhelpful response aws-sdk 与@aws-sdk 之间的区别 - Difference between aws-sdk vs @aws-sdk 无法读取 dynamodb 客户端的 aws-sdk js v3 未定义的属性“byteLength” - Cannot read property 'byteLength' of undefined for aws-sdk js v3 for dynamodb client 如何将 Java 枚举与 Amazon DynamoDB 和 AWS SDK v2 一起使用? - How can I use Java Enums with Amazon DynamoDB and AWS SDK v2? AWS-SDK for JavaScript,获取SecretValue - AWS-SDK for JavaScript, Getting SecretValue 如何在 `Node aws-sdk` sendRawEmail 函数中发送 PDF 附件? - How can send PDF attachment in `Node aws-sdk` sendRawEmail function? @aws-sdk/client-ses 和@aws-sdk/client-sesv2 有什么区别? - What is the difference between @aws-sdk/client-ses and @aws-sdk/client-sesv2?
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM