[英]Call AWS Lambda function from React-Native
I have build a simple function in AWS Lambda which sends sms using Twilio service.我在 AWS Lambda 中构建了一个简单的函数,它使用 Twilio 服务发送短信。 I now want to call that function from my React-Native app.
我现在想从我的 React-Native 应用程序调用该函数。 Do you have any suggestion to that?
你对此有何建议?
There are two ways to invoke the AWS Lambda from your React-Native application有两种方法可以从您的 React-Native 应用程序调用 AWS Lambda
Direct invocation using AWS browser SDK使用 AWS 浏览器 SDK 直接调用
You can use lambda#invoke API to invoke your Lambda function from your React-Native app.您可以使用lambda#invoke API 从您的 React-Native 应用程序调用您的 Lambda 函数。 Catch here is that you'll have to ship AWS credentials with your app.
这里需要注意的是,您必须将 AWS 凭证与您的应用程序一起发送。 These credential will have permission to invoke the Lambda function.
这些凭据将有权调用 Lambda 函数。
Indirect onvocation using API Gateway使用 API 网关的间接调用
You can gate your Lambda function behind an API Gateway ( API Gateway + Lambda integration ).您可以在 API 网关( API 网关 + Lambda 集成)后面控制您的 Lambda 函数。 Then you can use standard JavaScript HTTP utilities to make REST calls to you API Gateway resource.
然后,您可以使用标准的 JavaScript HTTP 实用程序对您的 API 网关资源进行 REST 调用。 This API Gateway resource will be responsible for invoking your Lambda function.
此 API 网关资源将负责调用您的 Lambda 函数。
I prefer second method because API Gateway provides throttling support and we don't have to ship credentials with the app.我更喜欢第二种方法,因为 API 网关提供节流支持,而且我们不必随应用程序一起提供凭据。
You can go through these articles. 您可以阅读这些文章。
building-serverless-mobile-applications-with-react-native-aws . 用无反应的本机构建无服务器移动应用程序 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.