Reputation: 174
I am trying to call the AWS lambda function from cli by shell script. I want to send the current logged user name to lambda function as parameter. This is the code I tried:
#!/bin/bash
user=$(whoami)
echo "=START="
echo "$user"
aws lambda invoke --invocation-type RequestResponse --function-name shell_lambda_invoke --region ap-south-1 --log-type Tail --payload '{"bashuser":"${user}", "InstanceId":"'i-0c4869ec747845b99'"}'
Thanks in advance.
Upvotes: 1
Views: 5513
Reputation: 174
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
Upvotes: 3
Reputation: 1383
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"}
Upvotes: 3