Building AI Enabled GraphQL Applications
6. Now we need to update the Lambda function with the bucket name we’ll be using. In lambda/index.js
on line 8, update the Bucket
property with the S3 bucket name you created earlier.
7. Finally, we need to add the actual Lambda function we will be running! In the lambda
folder of this project, there is a Lambda function (index.js
package.json
file. From within this directory, install the dependencies and then zip the folder into a zip file using the following command:yarn || npm install
zip -r ../translate.zip *
Upload this zip file to AWS Lambda as the function code and click Save.
A look at the Lambda function
Let’s take a look at and discuss the Lambda function we will be using:
- The first thing we do is import the
aws-sdk
and create new instances of Translate, Polly, & S3. - Next, we create the handler function.
- The first thing we do in the handler function is create a params object for Translate that will describe the Text & the Language Code we have coming in from the API.
- Next, we call
translate.translateText
passing in this params object. This will return the translated text and we set the message variable to that text. - Now we will use the language code to get the proper voice to go with the language. Each language has a couple of voices that work properly with the language so we make sure to choose the right voice for the right language.
- We then create a new params object for Polly containing a few things including the Text & VoiceID.
- Now we call
polly.synthesizeSpeech
& pass in the params object we just created. - If
polly.synthesizeSpeech
is successful, we will get a data object returned with anAudioStream
property. - We use the
data.AudioStream
along with a unique ID to store the Audio in an S3 bucket usingS3.putObject
. If the item is stored without error we get a success callback function. - If the
S3.putObject
method is successful, we call thecallback
of the Lambda function passing in theid
of the S3 object (which we will use later to play back the MP3).
Building the GraphQL API
The last step is creating the GraphQL API.
- Give the API a name, choose Custom Schema & click create.
- Create a new AWS Lambda data source
- Click Data Sources
- Click NEW
- Give the data source a name, choose AWS Lambda Function as the Data source type
- For the region, choose the region where you created the AWS Lamba function
- For the Function ARN, choose the Lambda function you just created
- For the Role, choose New Role
4. Click on Schema and create the following schema:
type TranslatedSentence {
sentence: String!
}
type Query {
getTranslatedSentence(sentence: String!, code: String!): TranslatedSentence
}
5. Add a resolver to the getTranslatedSentence
query
- From within the Schema editor, on the Right (under Data Types), click on Attach next to the
getTranslatedSentence
field. - For the Data Source name, choose the new data source we just created
- Click Save
6. Add AWS AppSync configuration to the project
Next, we need to edit the aws-exports.js file to specify our AWS AppSync configuration. In the root directory of the React Native project, update aws-exports.js with your AWS AppSync credentials:
const awsmobile = {
'aws_appsync_graphqlEndpoint': 'YOURENDPOINT',
'aws_appsync_region': 'YOURREGION',
'aws_appsync_authenticationType': 'API_KEY',
'aws_appsync_apiKey': 'YOURAPIKEY',
}
7. Run the React Native app
If building for iOS, run the following command from the terminal:
react-native run-ios
If building for Android, first open an Android emulator and then run the following command from the terminal:
react-native run-android
Conclusion
With AWS AppSync you can leverage a single GraphQL endpoint to work with multiple databases, data sources & AWS Lambda functions giving you the power to do almost anything you would like. In this post, we’ve scratched the surface by demonstrating how we can use a GraphQL query to work with an AWS Lambda function to interact with other AWS services such as Amazon Polly, Amazon Translate, & Amazon S3.
To learn more about AWS AppSync, check out this repo.
I encourage you to experiment more and reach out to me to show me cool stuff you are building with this stack!
If you enjoyed this article, please clap n number of times and share it! Thanks for your time.
相關推薦
Building AI Enabled GraphQL Applications
6. Now we need to update the Lambda function with the bucket name we’ll be using. In lambda/index.js on line 8, update the Bucket property with the S3 buck
Building real-time dashboard applications with Apache Flink, Elasticsearch, and Kibana
https://www.elastic.co/cn/blog/building-real-time-dashboard-applications-with-apache-flink-elasticsearch-and-kibana Fabian Hue
Building trust in AI applications
Building Trust in AI ApplicationsAll of us have seen those fear mongering headlines about how artificial intelligence is going to steal our jobs and how we
轉載 -- 構建健壯的Nodejs應用:錯誤處理 Building Robust Node Applications: Error Handling
Building Robust Node Applications: Error Handling https://strongloop.com/strongblog/robust-node-applications-error-handling/ by&
Mobile Development with C#:Building Native iOS, Android, and Windows Phone Applications
Mobile Development with C#, 該書詳細介紹使用C#開發跨平臺移動應用,基於Mono平臺,使用.Net開發語言,開發多移動平臺應用,iOS,Android,Windows Phone。 書籍下載
Don’t miss the chance to deploy AI in your customer service applications
Customer service is one of the most exposed parts of an organization’s corporate image. Delivering a great customer experi
Neuton: A new, disruptive neural network framework for AI applications
Only basic technical skills required. And, if you are not puzzled enough yet, here's one more thing: In Neuton's FAQ, it is mentioned that the first releas
SRA Targets Legal AI A2J Applications with ‘Innovate Testbed’
The regulator for solicitors in the UK, the SRA, is to create an ‘innovation testbed’ to try out different legal AI applications and explore regulatory
Ask HN: How are you building large apps with react and GraphQL
What patterns and tools are you using to build large apps with react and GraphQL?With Apollo, do you use cache or link-state? Are you using redux (I love r
Artificial Intelligence Applications: AI can Determine Your Sexuality [Stanford Research]
What if Artificial Intelligence, Deep Neural Networks can look at your picture and determine if you are gay or straight? In this video, I want to share wit
AI Permeation & Applications
This video tutorial is all about AI Permeation and its applications. Artificial Intelligence has not become an essential part of our day to day life. AI Pe
The AI Paradox: How A Deep Learning Startup Is Building Successful AI Solutions
We have a paradox staring us in the face. All that web content creates a great forum for philosophical debate: Will AI save the world or bring about the ex
How to Use IoT Datasets in #AI Applications
Recently, google launched a Dataset search – which is a great resource to find Datasets. In this post, I list some IoT datasets which can be used for Machi
7 Things I Learned From Building An AI Chatbot For Leadership Development
My mission is to spark 100 million leaders in the next ten years. How can I possibly reach so many people in so little time? More specifically, how can we
Building a Slack Bot with Go and Wit.ai @ Alex Pliutau's Blog
Building a Slack Bot with Go and Wit.ai We will build a simple Slack Bot with NLU functionality to get some useful information from Wolfr
How AI can Improve Human Decision Making in IoT Applications
CA Technologies announced its participation in scientific research to discover how Internet of Things (IoT) applications can use a type of AI known as'deep
Build secure, efficient, cloud enabled applications
Amazon Web Services is Hiring. Amazon Web Services (AWS) is a dynamic, growing business unit within Amazon.com. We are currently hiring So
Building Real Time AI with AWS Fargate
This post is a contribution from AWS customer, Veritone. It was originally published on the company’s Website. Here at Veritone,
Building Serverless SaaS Applications on AWS
By Tod Golding, Partner Solutions Architect at AWS Software as a service (SaaS) solutions often present architects with a diverse mix of s
AWS AppSync : créez des applications basées sur GraphQL et axées sur les données, avec des capacités hors ligne et en temps réel
Avec AWS AppSync, vous ne payez qu'en fonction de votre consommation. Le service n'entraîne aucuns frais minimums ni aucune obligation d'utilisa