Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call AWS Lambda function from React-Native

I have build a simple function in AWS Lambda which sends sms using Twilio service. I now want to call that function from my React-Native app. Do you have any suggestion to that?

like image 671
BMX Avatar asked Apr 24 '19 18:04

BMX


People also ask

Does AWS work with react native?

AWS Amplify enables React Native developers to create high-quality applications on a flexible, scalable, and reliable serverless backend.

How do you call an AWS API in React JS?

You will want to select “New API'” here, enter in an “API name” and click “Create API”. Under the “Actions” menu please select “Create Method”. Please select “ANY” here and click on the tick to confirm. Make sure you select “Lambda Function” here and type in your “Lambda Function” name, in this case “mediumtutorial”.

Does lambda support React?

The React app is rendered with a Lambda function. The CloudFront distribution is configured to forward requests from the /ssr path to the API Gateway endpoint. This calls the Lambda function where the rendering is happening.


1 Answers

There are two ways to invoke the AWS Lambda from your React-Native application

Direct invocation using AWS browser SDK

You can use lambda#invoke API to invoke your Lambda function from your React-Native app. Catch here is that you'll have to ship AWS credentials with your app. These credential will have permission to invoke the Lambda function.

Indirect onvocation using API Gateway

You can gate your Lambda function behind an API Gateway (API Gateway + Lambda integration). Then you can use standard JavaScript HTTP utilities to make REST calls to you API Gateway resource. This API Gateway resource will be responsible for invoking your Lambda function.

I prefer second method because API Gateway provides throttling support and we don't have to ship credentials with the app.

like image 166
Hammad Akhtar Avatar answered Oct 13 '22 15:10

Hammad Akhtar