Home > Blockchain >  Pass event data to AWS Lambda through AWS CLI/Slack(ChatOps)
Pass event data to AWS Lambda through AWS CLI/Slack(ChatOps)

Time:01-03

I have a very simple nodejs based AWS Lambda function which has an event variable that I am trying to pass through slack/AWS Cli while invoking the function on Mac OS. Below is the code

exports.handler = async (event) => {
const a = event["domain"];
    return a;
};

On testing function in AWS Lambda console if I provide set it up in below way it works fine.

enter image description here

It works fine and shows the result as expected. But when I am trying to run it using AWS Cli or Slack(ChatOps) it is not passing the event data. Below is the lambda invokation command I am using,

@aws lambda invoke --invocation-type RequestResponse --function-name manrill-test 
--region us-east-1 --payload "{ \"domain\": \"xyz.com\" }"

This shows the below message and looks like the payload/ event data is not being passed properly.

ExecutedVersion: $LATEST
StatusCode: 200
Payload:
null

Any idea what I am doing wrong? Ideally it should show the value of event data which I am passing (xyz.com).

CodePudding user response:

If you are using AWS CLI V2 then you need to add the "--cli-binary-format raw-in-base64-out" flag to pass raw json

aws lambda invoke --invocation-type RequestResponse --function-name manrill-test --region us-east-1 --payload "{ \"domain\": \"xyz.com\" }" --cli-binary-format raw-in-base64-out response.json

CodePudding user response:

the issue is not on slack or lambda, its mac os keyboard setting. you have to uncheck "use smart quotation and dashes" keyboard settings under Text tab. check out the answer on the below link.

How to invoke aws lambda with payload from Slack

  • Related