AWS Builder Center
From Prompt to Web App with Amazon Bedrock
 Copy

From Prompt to Web App with Amazon Bedrock Copy

Hands-on lessons from building a serverless AI app with SageMaker, Lambda, API Gateway, and S3. Copy

Cloud Engineer | AWS | Generative AI & Agentic AI

Introduction

I recently completed the AWS SimuLearn: Prompt Engineering with Amazon Bedrock lab on AWS Skill Builder.
Initially, I expected to focus only on writing better prompts. However, this hands-on lab helped me understand how to integrate generative AI into a serverless web application using AWS services.
Here is what I learned and how the different AWS services work together.

1. Understanding the Architecture

The application uses several AWS services, each with a specific responsibility:
  • Amazon SageMaker AI: Provides a Jupyter Notebook environment for experimenting with Python code and prompts.
  • Amazon Bedrock: Provides access to foundation models for generating AI responses.
  • AWS Lambda: Executes Python code to invoke Bedrock models.
  • Amazon API Gateway: Exposes a REST API for the frontend application.
  • Amazon S3: Stores the static HTML website.
  • Amazon CloudFront: Delivers the website content to users.
The architecture separates AI experimentation from application deployment.

2. Experimenting with Amazon Bedrock

I used a Jupyter Notebook in SageMaker to interact with Amazon Bedrock through the AWS SDK for Python (Boto3).
The process involved:
  1. Creating a Bedrock Runtime client using  boto3.client('bedrock-runtime') .
  1. Building a prompt template containing user metadata and a question.
  1. Converting the request into JSON.
  1. Invoking the foundation model using  invoke_model() .
  1. Extracting the generated response and measuring inference latency.
One interesting concept was prompt personalization.
By including information such as a user's interests and occupation, the application can provide additional context to help the AI generate more relevant responses.
I also learned that SageMaker was being used as a development environment, not to train a new foundation model. Bedrock handled the actual model inference.

3. Deploying the Backend with AWS Lambda

After experimenting with prompts, I worked on deploying the Python code to AWS Lambda.
First, I packaged the Python file:
 zip lambda_function.zip lambda_function.py 
Then, I updated the Lambda function using AWS CLI:
 aws lambda update-function-code --function-name invoke_bedrock --zip-file fileb://lambda_function.zip 
This demonstrated how Python code developed in a notebook could become part of a serverless backend.
With API Gateway connected to Lambda, the application can receive HTTP requests, invoke Amazon Bedrock, and return AI-generated responses.

4. Hosting the Frontend with Amazon S3

The next part involved deploying the HTML frontend.
I used AWS CLI to locate the lab's website S3 bucket and upload the HTML file:
 aws s3 cp index.html s3://$WEB_BUCKET/ 
In this architecture, Amazon S3 stores the static website files, while CloudFront delivers the content.
The frontend communicates with the backend through API Gateway.
The complete application follows this workflow:
User → API Gateway → Lambda → Amazon Bedrock → AI Response
Meanwhile, CloudFront and S3 handle delivery of the website.

5. Key Lessons Learned

This lab helped me understand several important concepts:
  • Prompt Engineering: How structured prompts and contextual information influence AI responses.
  • Foundation Model Integration: How to invoke models using Amazon Bedrock APIs.
  • Serverless Architecture: How Lambda and API Gateway connect a web application to AI services.
  • Cloud Deployment: How S3 and CloudFront support static web applications.
  • AWS CLI: How to deploy application files and update Lambda functions from a terminal.
An important consideration for real-world applications is security. User metadata should be handled carefully, sensitive information should not be unnecessarily included in prompts, and IAM permissions should follow the principle of least privilege.

6. Final Thoughts

My biggest takeaway from this lab is that building a generative AI application does not always require training a machine learning model from scratch.
Instead, developers can use Amazon Bedrock to access existing foundation models and integrate them into applications using serverless AWS services.
This hands-on experience helped me connect the concepts of prompt engineering, API integration, and cloud architecture.
I look forward to exploring more advanced topics such as Retrieval-Augmented Generation (RAG), prompt evaluation, and production-ready AI applications on AWS.
__
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article