我试图处理从ASP.NET WEB API发送到AWS API并处理它与lambda函数请求从ASP.NET WEB API发送到AWS LAMBDA的JSON请求:如何处理如何使用Node.js
这就是我调用REST API部署在AWS方式:
// Serialize our concrete class into a JSON String
var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(payload));
// Wrap our JSON inside a StringContent which then can be used by the HttpClient class
var httpContent = new StringContent(stringPayload,Encoding.UTF8,"application/json");
using (var httpClient = new HttpClient()) {
// Do the actual request and await the response
var httpResponse = await httpClient.PostAsync("https://hosteddress-2.amazonaws.com/prod/SlashcmdIntegeration", httpContent);
// If the response contains content we want to read it!
if (httpResponse.Content != null) {
var responseContent = await httpResponse.Content.ReadAsStringAsync();
// From here on you could deserialize the ResponseContent back again to a concrete C# type using Json.Net
}
}
这是代码AWS lambda来处理它:
var AWS = require('aws-sdk');
var qs = require('querystring');
var https=require('https');
var token;
exports.handler = function (event, context) {
processEvent(event, context);
};
var processEvent = function(event, context) {
var body = event.body;
var params = qs.parse(body);
var commandText = params.CommandText;
var arr = commandText.split(" ");
var op1 = arr[0];
var op2 = arr[1];
var op = arr[2];
var result;
switch(op) {
case "+":
result = Number(op1) + Number(op2);
break;
case "-":
result = Number(op1) - Number(op2);
break;
case "*":
result = Number(op1) * Number(op2);
break;
case "/":
result = Number(op2)===0 ? NaN : Number(op1)/Number(op2);
break;
default:
result = "Invalid op";
}
console.log('data sent');
context.succeed(result);
};
我试图调试它var body = event.body;
是不确定的,但是我已经在合并请求设置,并最终登陆以下错误信息:
{“的errorMessage”:“在完成请求之前处理退出”}
对此有何想法请?
感谢
没有得到这个'var body = event.body;它不是未定义的“,你是否在请求中获得了正文? – AJS
@AJS。这就是我认为的问题,event.body是未定义的,但它应该获得正确的身体,因为我已经在AWS API的集成请求中正确设置了身体。 – TechnoSavvy
错误意味着api请求失败,因为它没有发送任何响应。 – AJS