0
votes

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

2 Answers

2
votes

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:

  1. Create role which can be assumed by EC2 instance and allows for invoking target lambda function

  2. Attach role to the instance

  3. Install AWS CLI on the instance and use aws lambda invoke command as described here: https://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html

1
votes

Use aws lambda invoke

   aws lambda invoke \
          --function-name my-function \
          --payload '{ "name": "Bob" }' \
          response.json

   Output:

      {
          "ExecutedVersion": "$LATEST",
          "StatusCode": 200
      }