I need to invoke the lambda function from the shell script which is in ec2 instance. Is it possible to invoke that. If yes what are the steps to be followed. My requirement is when one job is finished in ec2 ,then main script should execute the lambda function
2 Answers
While it is indeed possible, depending on the scale of the task, AWS Step Functions are better suited for orchestrating workflows between different services.
If you're adamant about doing it on EC2 instance, you need to:
Create role which can be assumed by EC2 instance and allows for invoking target lambda function
Attach role to the instance
Install AWS CLI on the instance and use
aws lambda invokecommand as described here: https://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html
1 Comment
sanjay
I nee to call the lambda from the api, so if call I call the step functions from api it works but what if the multiple user call the api whether the step functions can be executed for all the user again
aws lambda invoke \
--function-name my-function \
--payload '{ "name": "Bob" }' \
response.json
Output:
{
"ExecutedVersion": "$LATEST",
"StatusCode": 200
}