amazon web services - aws lambda: invoke with payload from cli - Stack Overflow
shell - Invoke lambda function from AWS cli - Stack Overflow
amazon web services - AWS CLI execute a lambda function issue - Stack Overflow
Running aws-cli Commands Inside An AWS Lambda Function
Videos
use the fileb:// ("file binary") syntax for the payload parameter so you don't have to run it through base64
... --payload fileb://invoke-payload.json
Invoke Lambda with simple JSON from the CLI
Here's how to test your Lambda by giving it a short JSON payload, and displaying the result in the terminal:
aws lambda invoke \
--payload '{"beer": "tasty"}' --function-name myfunc \
--cli-binary-format raw-in-base64-out \
/dev/stdout
Building on antklim's answer
To invoke the lambda function using AWS CLI write the following code which works fine: I am sending payload to this function with instance ID and user name as I needed this in lambda if you wan't to send anything other you can send other details as input in payload section.
#!/bin/bash
user=$(whoami)
echo Please Enter the InstanceId
read InstanceId
aws lambda invoke --invocation-type RequestResponse --function-name wu_core_auto_start_stop_lambdainvoke --region us-east-1 --log-type Tail --payload '{"bashuser":"'"${user}"'", "InstanceId":"'"${InstanceId}"'"}' outputfile.txt
Since Your bash variable is inside single quotes it won't get populated.
Test:
$ echo "${user}"
root
Your sample:
$ echo '{"bashuser":"${user}", "InstanceId":"'i-0c4869ec747845b99'"}'
{"bashuser":"${user}", "InstanceId":"i-0c4869ec747845b99"}
You need to interrupt quoting like this:
$ echo '{"bashuser":"'"${user}"'", "InstanceId":"'i-0c4869ec747845b99'"}'
{"bashuser":"root", "InstanceId":"i-0c4869ec747845b99"}
It looks like you need to provide an outfile. So re-run it as follows:
aws lambda invoke \
--function-name arn:aws:lambda:us-east-1:111111111:function:xxx \
--invocation-type RequestResponse \
outfile.txt
In addition to @jarmod's answer:
You can use - if want to send output directly to stdout:
aws lambda invoke --function-name my_function --invocation-type RequestResponse --log-type Tail - | grep "LogResult"| awk -F'"' '{print $4}' | base64 --decode
or if you have jq
aws lambda invoke --function-name my_function --invocation-type RequestResponse --log-type Tail - | jq '.LogResult' -r | base64 --decode