amazon-dynamodb - 任务在 3.00 秒后超时 - 使用 NodeJS 的 Lambda 应用程序

标签 amazon-dynamodb aws-lambda aws-sdk-nodejs

我正在尝试将硬编码数据项放入 DynamoDB。我正在使用 AWS SDK 对象来执行此更新。下面代码中的所有调试“Console.log”都会被打印出来,但最终会打印Task timed out after 3.00秒

没有更新 DynamoDB

function updatedb(intent, session, callback) {
    let country;
     const repromptText = null;
     const sessionAttributes = {};
     let shouldEndSession = false;

console.log("In the function");
const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1' });

var params = {
    TableName: "Location",
    Item: {
        "LocationID": { "S": "11" },
        "Country": { "S": "10" },
        "Description": { "S": "10" },
        "Name": { "S": "10" }
    }
};
console.log("Param loaded & executing the DocClient Put");

docClient.put(params, function (err, data) {
    if (err) {
        speechOutput = 'Update failed';
        console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
        callback(sessionAttributes,
            buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
    } else {
        console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
        speechOutput = 'Update successful';
        callback(sessionAttributes,
            buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
    }
});
}

以下项目已检查

1) DynamoDB 中有一个名为“Location”的表 2) DynamoDB 和此 lambda 函数均位于 ue-west-1(爱尔兰) 3)为此Lambda函数分配的角色可以对该表执行所有操作。请参阅下面的政策详细信息

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "Stmt1510603004000",
        "Effect": "Allow",
        "Action": [
            "dynamodb:*"
        ],
        "Resource": [
            "arn:aws:dynamodb:eu-west-1:752546663632:table/Location"
        ]
    }
]
}

我的 Lambda 函数如何通过区域定位表“位置”?-代码似乎没有端点等? - 刚刚根据教程开发。

这就是我所缺少的吗?

请问你能帮忙吗?

最佳答案

我遇到了类似的问题,请尝试将 require 语句放在函数的开头。

const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1' });

关于amazon-dynamodb - 任务在 3.00 秒后超时 - 使用 NodeJS 的 Lambda 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47273580/

相关文章:

python-3.x - 从 boto3 table.batch_writer 对象获取 Http 响应

python-3.x - DynamoDB 扫描未返回所需的输出

python-3.x - 使用 Dynamorm 在 Python 中构建 AWS SAM 嵌套应用程序

amazon-web-services - 如何将 AWS 公共(public)扩展添加到 AWS Lambda cloudformation 模板?

node.js - 模块初始化错误 : Error at Object. fs.openSync (fs.js :646:18) at Object. fs.readFileSync (fs.js:551:33)

node.js - 如何收听 AWS IOT Thing Shadow 更新

node.js - 来自 Node-aws : all operations fail "Cannot do operations on a non-existent table" 的 Dynamo Local

amazon-web-services - 我可以在 AWS Lambda 中使用 yum 安装工具吗?

node.js - 通过node下载s3桶中存储的sqlite文件

aws-sdk - 如何将 API key 添加到 AWS API Gateway 中的使用计划