Short story generator with AWS Bedrock and Amplify


Introduction
Recently, 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 the 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 recipes 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, Adventorous
Style: First Person, Third Person, Fairy Tale, Poetic
After that, changed the definition in the amplify data’s resources, which defines 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 active the amplify sandbox environment (npx ampx sandbox), the cloud resources would compile and resources would be updated to reflect these changes! Just need to 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
Image that shows the view of the completed story-telling POC app. Own creation
Pretty good considering it took me only like a couple of hours of experimentation!
Changing the AI model is very easy as well, as I was experimenting with different Claude models. Ultimately went with the Claude Sonnet 3.5
Architecture
So, what’s under the hood? When inspecting in the AWS console about what resources are spinned 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.
Image that shows the general architecture of apps created using the aws amplify’s AI kit. Taken from Build fullstack AI apps in minutes with the new Amplify AI Kit
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:
Image that shows the architecture of the short-story teller app created in this blog post using aws amplify’s generation ai kit. Own creation
Full code repository of this POC can be found here: https://github.com/LucasVera/story-telling-app
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 a 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
Subscribe to my newsletter
Read articles from Lucas Vera Toro directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Lucas Vera Toro
Lucas Vera Toro
Technical Architect and Developer with 10 years of experience, specializing in scalable and efficient digital products powered by cloud technologies.