Building a serverless web application to edit images using Amazon Bedrock
Exploring various AWS services like AWS Amplify, Amazon Cognito, Amazon Bedrock, Amazon DynamoDB, Amazon API Gateway, and AWS Lambda, to create a web application that edits images as per your prompts
Introduction
The goal was to build a full-stack serverless web application where the users can upload an image, write a prompt as to what they want edited (operations such as masking, inpainting, outpainting, background replacement, etc.) in the image, and the AI provides the generated images with the edits implemented.
Building this app also helped in exploring on Serverless API layer to handle requests, storing image metadata, and security in terms of user authentication and authorization.
Architecture
The services used were:
- Amazon Bedrock: With Titan Image Generator G1 for image editing
- Amazon Cognito: For user management and authentication
- Amazon DynamoDB: For image generation data storage
- AWS Lambda: For serverless business logic
- AWS Amplify: For web application hosting
- Amazon API Gateway: REST endpoints for secure APIs
The workflow goes like this:

Amazon Cognito
Amazon Cognito is an AWS service providing identity management for web/mobile apps, handling user sign-up, sign-in, access control, and secure temporary AWS credentials for users, featuring user pools (directories) and identity pools (federation), supporting social/enterprise logins and scaling to millions of users with features like MFA, passwordless auth, and fine-grained permissions for AWS resources.
In the Image Editing app, I have created a Cognito User Pool and a Cognito User. The application type was taken as Single-Page App (SPA), the sign-in identifiers as email and username. Self-registration was disabled to block users from creating their own accounts, so I created a Cognito User, setting the username, email, and password (later allowing the user to set their own password). The User Pool Id and Client Id were used in Amplify.
This service allowed authentication and authorization of user, securing the app.
Amazon DynamoDB
Amazon DynamoDB is a fully managed, serverless NoSQL database service from AWS offering fast, predictable performance with seamless scalability for key-value and document data, ideal for high-traffic, internet-scale applications needing reliable low-latency data storage and retrieval without managing servers. It provides automatic scaling, high availability, durability, flexible schemas, and features like Global Tables for multi-region deployment and DAX for in-memory caching.
For the app, I created a DynamoDB table, and created an IAM Policy for DynamoDB access.
This service allowed storage of the image generation metadata.

AWS Lambda
AWS Lambda is a serverless, event-driven compute service from Amazon Web Services that lets you run code without provisioning or managing servers, automatically scaling and handling infrastructure, so you only pay for the compute time consumed, perfect for event-triggered tasks like file processing, web backends, IoT, and data streams.
Lambda was used for serverless logic for the app. I used an existing role, created a Lambda function, rewrote the code, deployed it, and added permissions (the policy from creating the DynamoDB table).

Amazon API Gateway
Amazon API Gateway is a fully managed AWS service for creating, publishing, maintaining, monitoring, and securing APIs (REST, HTTP, WebSocket) at any scale, acting as a "front door" for applications to access backend services like Lambda, EC2, or custom web apps, handling traffic, security, monitoring, and caching without managing servers. It simplifies API management by offering features like throttling, authentication, request/response mapping, and integrations with other AWS services, allowing pay-as-you-go pricing.
Amazon API Gateway was used to build REST API, POST Method, enable CORS, create Authorizers, and deploy the API. The API could be invoked while running the app. Amazon API Gateway exposes REST endpoints that trigger Lambda functions for backend processing.

AWS Amplify
Amplify Hosting provides a Git-based workflow for hosting full-stack serverless web applications with continuous deployment. Amplify deploys your app to the AWS global content delivery network (CDN).
Amplify was used to deploy the app using a compressed file manually, instead of using Git.
Amazon Bedrock
Amazon Bedrock is a managed AWS service for accessing and managing foundation models (FMs), the basic building blocks of generative AI by Amazon Web Services (AWS). Bedrock makes things so simple that you don't need to worry about provisioning GPUs, configuring model pipelines, or managing any other infrastructure.
Amazon Bedrock allowed the app to use Titan Image Generator G1 model API to generate and manipulate images by passing an input and writing prompts.
Code Snippets
AWS Lambda function (part of the function):
Python
def prepare_titan_request(prompt_content, painting_mode, mask_base64, image_base64):"""Prepare request body for Titan model"""image_generation_config = {"taskType": painting_mode,"imageGenerationConfig": {"numberOfImages": 2,"quality": "premium","height": 1024,"width": 1024,"cfgScale": 8.0,"seed": randint(0, 100000),},}params = {"image": image_base64,"text": prompt_content,"maskImage": mask_base64}if painting_mode == 'OUTPAINTING':params['outPaintingMode'] = 'DEFAULT'image_generation_config['outPaintingParams'] = paramselif painting_mode == 'precise-outpaint':params['outPaintingMode'] = 'PRECISE'image_generation_config['outPaintingParams'] = paramselse:image_generation_config['inPaintingParams'] = paramsreturn json.dumps(image_generation_config)
IAM Policy for DynamoDB Table:
JSON
{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": ["dynamodb:PutItem","dynamodb:UpdateItem"],"Resource": "arn:aws:dynamodb:*:*:table/ImageGenerationTable"}]}
UI and Output






Conclusion
Building this full-stack serverless web application provided hands-on experience with AWS services like Cognito, Lambda, and DynamoDB, enabling a secure, scalable, and efficient solution. The integration of Amazon Bedrock's Titan Image Generator for AI-driven image editing and Amplify for deployment streamlined the development process. This project highlighted the power of serverless architecture in creating real-time, scalable applications with minimal operational overhead, while also offering opportunities for future improvements in features and security.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article