Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call aws Lambda function without using API Gateway and EC2 Instance

Tags:

Can we call lambda function from outside aws without using API Gateway? I want to call lambda function directly from outside aws services is it possible?

like image 725
Rukamesh Kumar Avatar asked May 04 '17 10:05

Rukamesh Kumar


People also ask

Can you call AWS Lambda without API gateway?

Looks like an ability to directly call Lambdas over the Internet without an API Gateway was just added to the SDK. Function URLs are available using the Lambda API and are supported in CloudFormation, AWS SAM and AWS CDK.

Is API gateway required for Lambda?

You can create a web API with an HTTP endpoint for your Lambda function by using Amazon API Gateway. API Gateway provides tools for creating and documenting web APIs that route HTTP requests to Lambda functions. You can secure access to your API with authentication and authorization controls.

Can you call Lambda directly?

You can call Lambda directly (as shown in my example above). Or, you can call it via the AWS Command-Line Interface (CLI).


2 Answers

AWS Lambda functions can be triggered by:

  • Events happening on other AWS services (eg Object uploaded to an Amazon S3 bucket)
  • A message being sent to AWS API Gateway (eg a REST call)
  • A schedule in Amazon CloudWatch Events
  • A direct API call

From Supported Event Sources documentation:

In addition to invoking Lambda functions using event sources, you can also invoke your Lambda function on demand. You don't need to preconfigure any event source mapping in this case. However, make sure that the custom application has the necessary permissions to invoke your Lambda function.

For example, user applications can also generate events (build your own custom event sources). User applications such as client, mobile, or web applications can publish events and invoke Lambda functions using the AWS SDKs or AWS Mobile SDKs such as the AWS Mobile SDK for Android.

So, anything on the Internet can invoke a Lambda function, but it will need to use AWS credentials to authenticate.

like image 194
John Rotenstein Avatar answered Oct 18 '22 07:10

John Rotenstein


You can also use an application load balancer to call the lambda. This option is useful when you have timeouts larger than 30 seconds. To use this option you need to add a trigger to the lambda function and select Application Load Balancer and then procede with the configuration which is not hard.

This is awful compare to using the API Gateway, because it creates a target group for each lambda but well... its sometimes useful.

like image 31
roccolocko Avatar answered Oct 18 '22 09:10

roccolocko