【发布时间】:2023-03-18 14:40:02
【问题描述】:
我想使用 Amazon Profile API 向网站发出 GET 请求。我正在尝试执行本文最后一个代码块中描述的操作:https://developer.amazon.com/blogs/post/Tx3CX1ETRZZ2NPC/Alexa-Account-Linking-5-Steps-to-Seamlessly-Link-Your-Alexa-Skill-with-Login-wit(文章的最后),但它并没有发生。我的回调函数似乎从未被调用过。
我已经添加了所需的 context.succeed(),实际上是最新版本,但仍然没有得到结果。我知道这个网址很好,因为我可以把它复制/粘贴到浏览器中,它会返回一个预期的结果。
这是关于在回调中使用适当的上下文函数调用的 SO 答案,我已经尝试过了。 Why is this HTTP request not working on AWS Lambda?
我没有使用 VPC。
我做错了什么?我觉得自己像个白痴,因为我已经研究了 2 天并尝试了解决方案。我记录了完整的 URL,当我从日志文件中复制/粘贴它并将其放入浏览器窗口时,我确实得到了有效的结果。感谢您的帮助。
代码如下:
function getUserProfileInfo(token, context) {
console.log("IN getUserProfileInfo");
var request = require('request');
var amznProfileURL = 'https://api.amazon.com/user/profile?access_token=';
amznProfileURL += token;
console.log("calling it");
console.log(amznProfileURL);
console.log("called it");
request(amznProfileURL, function(error, response, body) {
if (!error && response.statusCode == 200) {
var profile = JSON.parse(body);
console.log("IN getUserProfileInfo success");
console.log(profile);
context.callbackWaitsForEmptyEventLoop = false;
callback(null, 'Success message');
} else {
console.log("in getUserProfileInfo fail");
console.log(error);
context.callbackWaitsForEmptyEventLoop = false;
callback('Fail object', 'Failed result');
}
});
console.log("OUT getUserProfileInfo");
}
这是我在 CloudWatch 中得到的日志输出:
2017-03-08T22:20:53.671Z 7e393297-044d-11e7-9422-39f5f7f812f6 IN getUserProfileInfo 2017-03-08T22:20:53.728Z 7e393297-044d-11e7-9422-39f5f7f812f6 OUT getUserProfileInfo
【问题讨论】:
-
也许你应该发布日志输出,省略任何秘密。
-
我已经添加了相关的日志输出。
标签: javascript amazon-web-services aws-lambda alexa