AWS workshop serverless IA: Build your serverless GenAI powered MVP with AWS
-
AWS Account
-
Configure AWS cli Link
-
Install AWS Sam Link
-
⚠️ Request access to the modeljurasic-2Mid
in a region of preference
⚠️ Change the default region in this file(samconfig.toml
) , the same region than requested access tojurassic-2 Mid
version = 0.1
[default.deploy.parameters]
stack_name = "mvp-stories-demo"
resolve_s3 = true
s3_prefix = "mvp-stories-demo"
region = "us-west-2" # Your region
confirm_changeset = true
capabilities = "CAPABILITY_IAM"
image_repositories = []
- The user will connect with the frontend that is deployed on AWS Amplify Hosting
- After providing story context with selected language, the frontend will submit an HTTP request to our Amazon API Gateway backend
- The request is proxied and will trigger a syncrounous execution of an AWS Step Functions workflow
- The first step in the workflow is to generate a unique story by invoking a Large Language Model (LLM) through Amazon Bedrock
- If the requested language for the story is not english, Amazon Translate will be used to translate the story
- An AWS Lambda function is invoked and will convert the generated (and eventually translated story) to speech
- The generated mp3 will be uploaded on Amazon S3
- A presigned URL will be returned to the frontend in order for the end-user to play the generated mp3
- Deploy the backend with
aws sam
. - The infrastructure definition is in
template.yaml
file
Add Spanish language
// Function that returns the adequate voice depending on the language
// File src/handlers/textToSpeech.mjs
const getVoiceId = language => {
if (language == 'fr') return "Lea"
if (language == 'nl') return "Laura"
if (language == 'ar') return "Hala"
if (language == 'it') return "Bianca"
if (language == 'es') return "Lucia"
return "Joanna"
}
sam build
sam deploy
curl --location 'YOUR_API_GATEWAY_ENDPOINT' \
--header 'Content-Type: application/json' \
--data '{
"context": "Pinguu launching a icecream startup in the desert",
"language": "fr"
}'
Deploy Frontend
- Change the api gateway endpoint
fetch('YOUR_API_GATEWAY_ENDPOINT', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
-
Upload zip folder to aws Amplify
-
Access to url enable by amplify for test the app in different languages
Add Spanish language support
<div>
<input type="radio" name="language" value="en" checked> English
<input type="radio" name="language" value="fr"> French
<input type="radio" name="language" value="ar"> Arabic
<input type="radio" name="language" value="nl"> Dutch
<input type="radio" name="language" value="es"> Spanish
</div>
- Remove files from S3 bucket
- Run
sam destroy
- Repository build in base to WorkShop post summit: Link