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?
-
what do you mean when you said "outside aws services"? Are you trying to call aws lambda programmatically in some language?kaushalparik27– kaushalparik272017-05-05 14:24:28 +00:00Commented May 5, 2017 at 14:24
-
It would be very helpful if you were to include full information (eg that you want to use Python) in your initial question. For tips on writing questions, please see: How do I ask a good question?John Rotenstein– John Rotenstein2017-05-09 07:25:31 +00:00Commented May 9, 2017 at 7:25
-
Why do you wish to use HTTP(s) without using an SDK and without using API Gateway? They are the best ways to do it, so you'd need a really good reason to not use them.John Rotenstein– John Rotenstein2017-05-09 07:26:19 +00:00Commented May 9, 2017 at 7:26
-
@JohnRotenstein because API Gateway imposes constraints of 10MB for the payload, and 30 seconds for the timeout. these constraints can be crippling when it comes to vision-based machine learning tasks.Crashalot– Crashalot2021-09-05 23:50:08 +00:00Commented Sep 5, 2021 at 23:50
5 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.
9 Comments
lambda:invoke permissions with a resource equal to the Lambda functions' ARN.AWS Lambda Function URLs: Built-in HTTPS Endpoints for Single-Function Microservices is a way to access Lambda from outside. reference - https://aws.amazon.com/blogs/aws/announcing-aws-lambda-function-urls-built-in-https-endpoints-for-single-function-microservices/
1 Comment
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.
Comments
This is how call AWS lambda function without API GateWay in Android.
Interface Class
@LambdaFunction(functionName = "lambdafunctionName", invocationType = "RequestResponse")
String lambdafunctionName(String str);
Android Code (Java)
new AsyncTask<Response, Void, String>() {
@Override
protected String doInBackground(Response... params) {
try{
CognitoCachingCredentialsProvider cognitoProvider = new
CognitoCachingCredentialsProvider(MainActivity.this, "#identitypoolID", #Region);
// creates an invocation factory
LambdaInvokerFactory factory = new LambdaInvokerFactory(MainActivity.this,
#Region, cognitoProvider);
// create a proxied object of lambdafunctionName
MyInterface lambdaFuction = factory.build(MyInterface.class,
new LambdaJsonBinder());
// invoke it just like a regular method
String AWSResponse = lambdaFuction.lambdafunctionName(#Parameter to AWS lambda) ;
return AWSResponse;
}catch(Exception e){
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
return null;
}
}
@Override
protected void onPostExecute(String result) {
if (result == null) {
Toast.makeText(MainActivity.this,"Error !", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(MainActivity.this,"Response From AWS " + result, Toast.LENGTH_LONG).show();
}
}.execute();