Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkRecently, I got curious about how easy it is nowadays to build an AI-powered app. So, I decided to give it a shot and was blown away by how easy and fast it was.
Given some recent AWSome pre:Invent announcements, I saw that the Amplify team released an Amplify AI Kit for developers to build full-stack, AI-powered apps.
So, I followed the tutorial in the AWS documentation for a recipe assistant. I just wanted to see how easy and fast it was to have something up and running. My aim was to create a story-telling app that could take different inputs for the story, like genre, tone, and style.
Implementation
After approximately 40 minutes of implementing the tutorial (I like to read first and type the code instead of copy/pasting), I already had a simple POC ready, with authentication, somewhat nice views, and inference for creating cooking recipes!
After that, it was a matter of playing around with what the app would do. I added a couple of selects with options for the user to generate different kinds of stories:
- Genre: Sci-fi, Mystery, Fantasy, Romance, Horror
- Tone: Light, Humorous, Dark, Adventurous
- Style: First Person, Third Person, Fairy Tale, Poetic
After that, I changed the definition of the amplify data’s resources, which defines the cloud resources that will be used. So three things mainly changed: the arguments, returns, and the system prompt:
const schema = a.schema({
generateShortStory: a.generation({
aiModel: a.ai.model('Claude 3.5 Sonnet'),
systemPrompt: "You are a story-teller that generates short, engaging stories based on user-provided themes or genres. Each story should have a clear structure: an introduction to set the stage, a middle to develop the plot, a twist to surprise the reader, and a satisfying ending. The characters should be fictional, with at least one relatable protagonist. Adapt the tone and style based on user input. Ensure the story is concise and self-contained.",
})
.arguments({
genre: a.string(),
tone: a.string(),
style: a.string(),
})
.returns(
a.customType({
numberOfParagraphs: a.integer(),
story: a.string(),
})
)
.authorization((allow) => allow.authenticated()),
})
After making this change and saving, while still having the amplify sandbox environment active (npx ampx sandbox), the cloud resources will compile and resources will be updated to reflect these changes! Just wait for a minute or two and it’s done!
After making a couple of minor tweaks to the UI, so the page looks a bit nicer, the end result was the following:
Pretty good considering it took me only a couple of hours of experimentation!
Changing the AI model is very easy as well, as I was experimenting with different Claude models. Ultimately I went with the Claude Sonnet 3.5
Architecture
So, what’s under the hood? When inspecting in the AWS console about what resources are spun up, we realize it’s some awesome AWS serverless infrastructure that’s powering this AI kit. So apps created with this AI kit are ready to power your web apps and scale as easily as a serverless stack allows.
The image above is the one that powers the full AI kit from Amplify. For my simple POC app, which only uses the “generate” variant of the kit (no conversation), I discovered that the stack is a bit different. It doesn’t use DynamoDB or Lambda, instead, AWS AppSync makes a direct HTTP request to Bedrock, and the mapping template from AppSync does the logic of formatting the response properly:
The full code repository of this POC can be found on Github.
Conclusion
This experiment showed me just how far tools like AWS Amplify and Bedrock have come. In just a few hours, I could get my app from idea to working proof-of-concept. The best part is that it’s backed by a scalable and efficient serverless infrastructure!
It’s exciting to see how easy it is nowadays to experiment with AI-powered projects, and I’m looking forward to exploring and enhancing the POC even further. Even launching it may also be a good idea!
References
- https://docs.amplify.aws/react/ai/set-up-ai/
- https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/
- https://ui.docs.amplify.aws/react/getting-started/usage
- POC Repo: https://github.com/LucasVera/story-telling-app
- https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html
- https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html
- https://aws.amazon.com/bedrock/