Sending raw Body JSON to AWS Lambda via API gateway

假如想象 提交于 2021-01-28 00:52:52

问题


I have been struggling with API Gateway trying to get what I assumed would be a simple procedure, sending raw JSON from a webhook to my AWS Lambda as an event to use within my function.

All I want to do is output the Woocommerce order number and send an email of the order number as well by getting the Woocommerce webhook body to Lambda, like I have in my test event. Here is the function:

var AWS = require('aws-sdk');
var ses = new AWS.SES();

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

// Send email to customer via Amazon SES with url link of TXT transcription file on S3
var eParams = {Destination: {ToAddresses: ["flla@isdaq.com"]}, Message: {Body: { Text: { Data: event.number },},Subject: { Data: 'TITLE' }}, Source: "ses@eucommission.trade"};
var email = ses.sendEmail(eParams, function (err, data) { if (err) console.log(err); else { console.log("===EMAIL SENT==="); } });
console.log('Woocommerce Order Number is: ', event.number); // successful response

};

If I place some Woocommerce webhook into the test area in Lambda it works fine. But if I place an order in Woocommerce,nothing happens

Here is what I have done so far:

  • Setup API Gateway linked to my AWS Lambda and placed that API URL within a Woocommerce webhook as a target URL when an order is created

  • Setup a POST method in API Gateway, Integration Request using the code below and Integration Response has not been edited

    { "method": "$context.httpMethod", "body" : $input.json('$'), "headers": { #foreach($param in $input.params().header.keySet()) "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end #end } }

  • Enabled CORS for POST in the API Gateway console

Can anyone help me crack this. I have crawled the web, Stack O and tried numerous things for hours.

来源:https://stackoverflow.com/questions/55632041/sending-raw-body-json-to-aws-lambda-via-api-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!