我有以下代码可以扫描DynamoDB表并返回结果,但是仅显示响应标头,而没有正文!
import { success, failure } from "../../libs/response-lib";
const AWS = require('aws-sdk');
const docClint = new AWS.DynamoDB.DocumentClient({region: 'eu-central-1'});
export async function main() {
let params = {
TableName: "brands",
limit: 100
};
try {
const a = await docClint.scan(params);
return success(a.Items);
} catch (e) {
return failure({ status: false });
}
}
尽管在其他js文件中,im使用另一种方式从具有DynamoDB lib的DynamoDB表中获取项目,但在这里正常工作是工作代码:
import * as dynamoDbLib from "../../libs/dynamodb-lib";
import { success, failure } from "../../libs/response-lib";
export async function main(event, context) {
const params = {
TableName: "orders",
KeyConditionExpression: "userId = :userId",
ExpressionAttributeValues: {
":userId": event.requestContext.identity.cognitoIdentityId
}
};
try {
const result = await dynamoDbLib.call("query", params);
return success(result.Items);
} catch (e) {
console.log(e);
return failure({ status: false });
}
}
我更改了查询数据库的方式,因为我没有要查询的ExpressionAttributeValues,如果有更好的方法,请提出建议。