# 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](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/) for developers to build full-stack, ai-powered apps.

So, I follo[wed the tutori](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)al in the aws documentation for a recipes assistant. I just wanted to see how easy [and fast it wa](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)s 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 styl[e.](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)

# [Implementa](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)tion

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:

```typescript
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

![Screenshot of a "Short Story Generator POC" with options for genre, tone, and style. The selected options are Sci-fi, Dark, and Third Person. A generated story is displayed about a child named Echo discovering a sound-emitting artifact in a silent village surrounded by misty mountains. The story unfolds with the village experiencing sound for the first time, leading to chaos and awe.](https://cdn.hashnode.com/res/hashnode/image/upload/v1732743361700/fa0e9822-8298-4aa0-a9e6-d7386d4a76d2.png align="center")

*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.

![A diagram illustrating a system architecture where a user interacts with AWS AppSync, which communicates with Amazon Cognito for authentication, Amazon DynamoDB for data storage, AWS Lambda for processing, and Amazon Bedrock for machine learning tasks.](https://cdn.hashnode.com/res/hashnode/image/upload/v1732743676910/5620e77b-c891-4495-8dd4-638a0deacfe3.png align="center")

*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*](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)

The im[age above is the one that powers the full AI-kit from Amplify.](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/) For my simple POC app, which only uses the “generate” variant of the kit (no conversation), I d[iscovered that the stack is a bit different. It doesn’t use dy](https://aws.amazon.com/blogs/mobile/build-fullstack-ai-apps-in-minutes-with-the-new-amplify-ai-kit/)namodb 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:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732744490304/2ff9d338-9d7f-447d-a75b-47b6d0bce760.png align="center")

*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**](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**

* [https://docs.amplify.aws/react/ai/set-up-ai/](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://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](https://ui.docs.amplify.aws/react/getting-started/usage)
    
* POC Repo: [https://github.com/LucasVera/story-telling-app](https://github.com/LucasVera/story-telling-app)
    
* [https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html](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://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html)
    
* [https://aws.amazon.com/bedrock/](https://aws.amazon.com/bedrock/)
