gpt4 book ai didi

amazon-web-services - 缺少必需参数 : Missing required key 'Message' in params

转载 作者:行者123 更新时间:2023-12-05 08:55:35 31 4
gpt4 key购买 nike

我正在尝试调用 AWS Lambda 中的代码。此 Lambda 代码已使用我的 IOT 按钮进行配置。在运行这段代码时,我没有看到任何错误。此外,我在我的移动设备上并没有真正看到所需的推送通知。

我可以在我的控制台中看到此消息:MissingRequiredParameter:参数中缺少必需的键“消息”

这是我的代码:

'use strict'; 

console.log('Loading function');

var AWS = require('aws-sdk');

var sns = new AWS.SNS();

AWS.config.region = 'xxxxx';

const TopicArn = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'

exports.handler = function(event, context) {

console.log("\n\nLoading handler\n\n");
console.log('Received event:', event);


const sin =
{
"default": "Start",
"APNS_SANDBOX":"{\"aps\":{\"alert\":\"Start\"}}",
"GCM": "{ \"notification\": { \"text\": \"Start\" } }"
} // for single click
const doub = {
"default": "Stop",
"APNS_SANDBOX":"{\"aps\":{\"alert\":\"Stop\"}}",
"GCM": "{ \"notification\": { \"text\": \"Stop\" } }"
} // for double click
const lon = {
"default": "SOS",
"APNS_SANDBOX":"{\"aps\":{\"alert\":\"SOS\"}}",
"GCM": "{ \"notification\": { \"text\": \"SOS\" } }"
} // for long click

var singleClick = sin[Math.floor(Math.random()*sin.length)];
var doubleClick = doub[Math.floor(Math.random()*doub.length)];
var longClick = lon[Math.floor(Math.random()*lon.length)];

var randomMessage = singleClick;

if(event.clickType == "DOUBLE")
{
randomMessage = doubleClick;
}

if(event.clickType == "LONG")
{
randomMessage = longClick;
}


sns.publish ({
Message: randomMessage,
TopicArn: TopicArn
},

function(err, data) {
if (err) {
console.log(err.stack);
return;

}
console.log('push sent');
console.log(data);
context.done(null, 'Function Finished!');
});
}

谁能帮我调试这个错误?

最佳答案

我找到了答案。我也必须使用 stringify() 命令将我的变量定义为字符串,否则无法发送 JSON 格式的消息。

关于amazon-web-services - 缺少必需参数 : Missing required key 'Message' in params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45452972/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com