Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call REST endpoint running in EC2 from a Lambda function?

I have a NodeJS server running on an EC2 instance, orchestrated by Elastic Beanstalk.

I would like to create a Lambda function that is triggered upon certain events in AWS Cognito. I want the Lambda function to make a POST call to my NodeJS server.

How can this be done?

like image 832
CodyBugstein Avatar asked Nov 04 '25 05:11

CodyBugstein


1 Answers

As far as I know, EC2 and Lambda are not integrated out of the box. You'll need to expose your EC2 endpoint through a web-server (e.g. Apache) to receive HTTP requests. Then you send a GET or POST request from Lambda to the EC2 server.

You could have both running in a VPC, so that the IP address you use to make requests to your EC2 web-server is only reachable from within your VPC. It won't make your EC2 callable only by the Lambda function but will prevent the external world from calling your EC2 server.

This tutorial might be useful to you: Configuring a Lambda Function to Access Resources in an Amazon VPC.

like image 111
Renato Byrro Avatar answered Nov 07 '25 05:11

Renato Byrro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!