GetItem
以下是通过 AWS API 对 DynamoDB 表执行操作的最小 JavaScript 示例:
const DYNAMODB_ENDPOINT = 'https://dynamodb.us-east-1.amazonaws.com';
let aws = new AwsClient({ accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_SECRET_KEY });
async function dynamoDbOp(op, opBody) {
let result = await aws.fetch(DYNAMODB_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'DynamoDB_20120810.' + op
},
body: JSON.stringify(opBody)
});
return result.json();
}
let dbResponse = await dynamoDbOp('GetItem', {
TableName: "someTableName",
Key: {
someTableKey: {
S: "someKeyValue"
}
}
});
console.log(dbResponse.json());
请注意,这AwsClient
是一个由aws4fetch定义的类,它负责为您签署 AWS 请求。有关更多信息,请参阅AWS GetItem API 文档。