Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly invoke AWS Lambda function from an Android app?

I'm trying to invoke one AWS Lambda function from my Android application. If I understand correctly, I have to start with something like this:

BasicAWSCredentials creds = new BasicAWSCredentials(keyId, secret);
AWSLambdaClientBuilder builder = AWSLambdaClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(creds))
            .withRegion(regionName);

AWSLambda lambdaClient = builder.build();

and then the rest of the code with InvokeRequest etc.

Problem is in the above code, after it app crashes. I can't find the correct set of libs to make this work in Android. If I use

implementation 'com.amazonaws:aws-java-sdk-lambda:1.11.782'

then it compiles fine and executes up to the "builder.build()" and then crashes and if I use

implementation 'com.amazonaws:aws-android-sdk-lambda:2.16.12'

(which is supposed to be used for Android???) Then "import com.amazonaws.services.lambda.AWSLambdaClientBuilder;" is red cause there's no such thing in the lib..

I get that AWSLambdaClient is deprecated and AWSLambda should be used, then what about AWSLambdaClientBuilder? What should I use?

Basically, if everything above is wrong, how do I get to call AWS Lambda function (by the way, this is without using API Gateway) from an Android app? What libs (with versions) would work for it?

I tried to follow https://docs.aws.amazon.com/lambda/latest/dg/with-android-example.html tutorial, but they also have deprecated stuff, plus it wants to involve Cognito and I was under the impression that I could call a function directly with a key and secret of a user with specific policy..

like image 419
galloper Avatar asked Jul 25 '26 20:07

galloper


1 Answers

A different approach, but you can use the API gateway or application load balancer and call the configured endpoint from the android application. Benefit with this, you will not need to configure the application to have the client id, and client secret set up, and even if restart, it would be simple api gateway call.

Lambda can work with both API Gateway as well as Application Load Balancer, and it is pretty easy to configure. Refer this page for details on ALB with Lambda.

like image 105
Nitin1706 Avatar answered Jul 27 '26 09:07

Nitin1706