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?
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() {
@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();