我创建了一个 lambda 函数并将其连接到 AWS API Gateway 以获取我的前端 JSON 格式的 DynamoDB 表数据,我试图从我的 DynamoDB 表中获取我的列条目作为 JSON 格式的列表,但我最终得到了什么getting 是我表中所有条目的完整字符串,它对前端(Flutter)的使用几乎为零。
这是我的 lambda 函数
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async event => {
const params = {
TableName: "//tableName"
};
try {
// Utilising the scan method to get all items in the table
const data = await documentClient.scan(params).promise();
const response = {
statusCode: 200,
body: JSON.stringify(data.Items)
};
return response;
} catch (e) {
return {
statusCode: 500
};
}
};
我的 API 解码后的 JSON 正文
{statusCode: 200, body: [{"product":"clear","__typename":"ProductModel","size":"small","_lastChangedAt":1625829002606,"_version":1,"company":"add","updatedAt":"2021-07-09T11:10:02.578Z","category":"Pot","createdAt":"2021-07-09T11:10:02.578Z","price":"69","description":"this doesn't even make sense","id":"f4acb29c-f8f3-4765-abf6-aef0002a837c"},{"product":"product","__typename":"ProductModel","size":"1","_lastChangedAt":1625988107746,"_version":1,"company":"company","updatedAt":"2021-07-11T07:21:47.704Z","category":"Climbers","createdAt":"2021-07-11T07:21:47.704Z","price":"221","description":"description","id":"0a51d3c3-4df3-4549-abaa-f8b88e8ac407"}]
}
我认为我的 lambda 函数存在问题,因为它的主体部分没有返回列表,但我无法让它工作。任何帮助将不胜感激