AWS新手在这里。我一直在尝试从Repository-aws-serverless-repository-api-lambda-GetOneLamb部署此Lambda函数。当我使用GET方法运行API网关时,会收到消息
{“消息”:“缺少身份验证令牌”}。
很多与此消息相关的论坛帖子,但我只是转圈。这里是index.js代码:
const AWS = require('aws-sdk'),
dynamoDb = new AWS.DynamoDB.DocumentClient(),
processResponse = require('./process-response'),
TABLE_NAME = process.env.TABLE_NAME,
PRIMARY_KEY = process.env.PRIMARY_KEY,
IS_CORS = process.env.IS_CORS;
exports.handler = (event) => {
if (event.httpMethod === 'OPTIONS') {
return Promise.resolve(processResponse(IS_CORS));
}
const requestedItemId = event.pathParameters.id;
if (!requestedItemId) {
return Promise.resolve(processResponse(IS_CORS, `Error: You missing the id parameter`, 400));
}
const key = {};
key[PRIMARY_KEY] = requestedItemId;
const params = {
TableName: TABLE_NAME,
Key: key
}
return dynamoDb.get(params)
.promise()
.then(response => processResponse(IS_CORS, response.Item))
.catch(err => {
console.log(err);
return processResponse(IS_CORS, 'dynamo-error', 500);
});
};