最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AWS Lambda更新函数,显示ValidationException

网站源码admin15浏览0评论

AWS Lambda更新函数,显示ValidationException

AWS Lambda更新函数,显示ValidationException

我正在尝试通过lamda函数更新数据。在阅读文档后,我刚刚创建了一个PUT方法并在方法中添加了lambda函数我在这里创建了一个函数,代码如下:

const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'});

AWS.config.update({region: 'us-east-2', apiVersion: '2012-08-10'});

var docClient = new AWS.DynamoDB.DocumentClient();

exports.handler = (event, context, callback) => {

    const params = {
    TableName: "Would-You-Rather",
    Key:{
        "QuestionID": "a670b861-8a34-4bda-93e0-8bbf2cd25eb6",
    },
    UpdateExpression: "set would = :w, rather = :r, wouldClick = :wC, , ratherClick = :rC ",
    ExpressionAttributeValues:{
        ":w": "Working",
        ":r": "Working",
        ":wC": 12,
        ":rC": 1
    },
    ReturnValues:"UPDATED_NEW"
};

console.log("Updating the item...");
docClient.update(params, function(err, data) {
    if (err) {
        console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
    }
});

};

但是当我测试功能时,它会显示出来

   "message": "Invalid UpdateExpression: Syntax error; token: \",\", near: \", , ratherClick\"",
  "code": "ValidationException",

如果我包装像这样的ExpressionAttributes

ExpressionAttributeValues:{
    ":w": "Working",
    ":r": "Working",
    ":wC": "12",
    ":rC": "1"
},

然后显示此错误

  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Invalid or unexpected token",

这是我的POST方法,可以很好地添加它,因为它可能有助于更好地理解

const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'});

exports.handler = (event, context, callback) => {
    const params = {
        Item: {
            "QuestionID": {
                S: context.awsRequestId
            },
            "Would": {
                S: event.would
            },
            "Rather": {
                S: event.rather
            },
            "wouldClick": {
                N: event.wouldClick
            },
            "ratherClick": {
                N: event.ratherClick
            }
        },
        TableName: "Would-You-Rather"
    };
    dynamodb.putItem(params, function(err, data) {
        if (err) {
            console.log(err);
            callback(err);
        } else {
            console.log(data);

            callback(null, data);
        }
    });
};

代码笔代码

var xhr = new XMLHttpRequest();
xhr.open('PUT', '');
xhr.onreadystatechange = function(event) {
  console.log(event.target.response);
}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'allow');

xhr.send(JSON.stringify({Would: Coffe, Rather: Tea, wouldClick: 15, ratherClick: 13, QuestionID: 3e8976be-e763-4c69-84c3-be03ec4a38de}));

我正在尝试通过lamda函数更新数据。在阅读文档后,我刚刚创建了一个PUT方法并在方法中添加了lambda函数我在这里创建了一个函数,代码是const AWS = require('aws -...

回答如下:

存在语法错误。您忘了在此处输入结束语

发布评论

评论列表(0)

  1. 暂无评论