如何使用 Lambda AWS 从 Amazon DynamoDB 获取行计数



我的 Lambda 脚本是:

var AWS = require("aws-sdk");
var DOC = require("dynamodb-doc");
AWS.config.update({region: "us-west-1"});
var docClient = new DOC.DynamoDB();
var dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
    var params = {};
    params.TableName = "Emails";
    params.ConditionalOperator = "AND";
    params.ScanFilter = {
        Machinekey:{
            ComparisonOperator:"EQ",
            AttributeValueList: [{S: "okok"}]
        }
    };
    params.Select= "COUNT";
    //params.IndexName = "Machinekey-index";
    //params.KeyConditions = docClient.Condition("EmailId", "NOT_NULL");
    //params.QueryFilter = docClient.Condition("Machinekey", "EQ","ARUZE-010415_15112442NLHIYTLY-A23V3.9");
    dynamodb.scan(params, function(err, data) { 
    if (err) {
        console.log(err, err.stack);
    } else {
        //console.log(data);
        context.succeed(data.Count);
    }
});
};

执行日志的结果:

[验证异常:仅当筛选器或预期具有两个或更多元素时,才能使用条件运算符] 消息:"条件运算符只能在过滤器或预期有两个或更多元素时使用", 代码:"验证异常", 时间: 星期三 六月 10 2015 03:12:34 GMT+0000 (UTC), 状态代码:400, 可重试:假,

求你,帮帮我!

您指定ConditionalOperator = "AND";,但对于仅包含一个条件的当前查询(Machinekey == "okok"),您不需要这样做。只有当您有两个或更多条件时,您才需要ConditionalOperator

尝试注释掉ConditionalOperator,然后重试:

var params = {};
params.TableName = "Emails";
//params.ConditionalOperator = "AND";
params.ScanFilter = {
    Machinekey:{
        ComparisonOperator:"EQ",
        AttributeValueList: [{S: "okok"}]
    }
};
params.Select= "COUNT";
...

相关内容

  • 没有找到相关文章

最新更新