
Generate Stunning AI Images: Build Your Own Website with Amazon Bedrock
Want to create your own image generation website? This guide shows you how to build a cost-effective, AI-powered platform using Amazon Bedrock, AWS Lambda, API Gateway, and a static website hosted on Amazon S3. Learn how to leverage the power of Amazon Nova Canvas foundation model to generate impressive visuals from simple text prompts, perfect for bolstering your projects or exploring the exciting possibilities of generative AI.
This tutorial is designed for IT professionals, AWS Community Builders, and GenAI enthusiasts eager to integrate AI-powered image generation into real-world applications. Plus, it’s remarkably affordable, letting you experiment with generative AI without breaking the bank.
Revolutionize Digital Marketing: Instant Image Creation with GenAI
Digital marketing companies used to rely on graphic designers or stock photos, a process involving brainstorming, searching, revisions, and approvals. This was time-consuming and costly, especially for timely content needs. But with Amazon Bedrock image generation, digital marketers can instantly create high-quality, custom images by simply describing what they need.
Think of quickly generating unique visuals for holidays, festivals, or announcements. This saves significant time and reduces costs, enabling businesses to post relevant, engaging content without delay.
Real-World Impact: Indian Festive Campaigns Reimagined
In India, businesses heavily promote during festivals. Digital marketing teams traditionally spend hours creating images using tools like Canva or searching online, manually adding branding. GenAI transforms this: simply input a prompt describing the client's background and the festival theme, and in seconds, you get a ready-to-use image. Add the trademark and logo, and what used to take hours now takes minutes, showcasing the power and cost-effectiveness of Amazon Nova. Amazon Nova Canvas delivers powerful, high-quality results.
Deep Dive: The Image Generation Architecture Explained
Our architecture utilizes several Key AWS services. Users interact with an S3-hosted static website, inputting prompts for custom images that are routed through API Gateway to trigger a Lambda function. This function enriches the request with parameters that optimize image generation.
The Lambda function then communicates with Amazon Bedrock, utilizing the Amazon Nova canvas foundation model to turn the text prompt into high-quality images. These images are securely stored in an S3 bucket, and Lambda generates a pre-signed URL (with an expiration time) for secure access. This URL is sent back through API Gateway to the user, who can view and download the generated image. The entire process provides user-friendliness and security managed through time-limited pre-signed URLs.
Amazon Nova Pricing: Cost-Effective Image Generation
Amazon Nova offers transparent pricing under the Creative Content Generation category, based on image resolution and quality, allowing you to balance cost and quality.
Here's the breakdown:
- Image Resolution: Up to 1024 x 1024
- Standard Quality Price: $0.04 per image
This makes it economical for both quick drafts and professional-grade visuals. For the most up-to-date pricing, always check the official AWS Bedrock Pricing page. Generate multiple images while keeping your costs low using Amazon Bedrock.
Get Started: Prerequisites for Building Your GenAI Website
Before diving in, make sure you have the following in place:
- AWS Account with admin/IAM access
- IAM Roles/Policies for Lambda, S3, API Gateway, Bedrock
- S3 Bucket configured for static website hosting
- Lambda & API Gateway integrated and configured
- AWS Bedrock enabled in your chosen region
- Basic AWS Console navigation skills
- Awareness of costs for Lambda, API Gateway, S3, and Bedrock
- GitHub Repository for the GenAI Image Generator code.
Step-by-Step: Access Amazon Nova Foundation Model through Bedrock
This segment will guide you through requesting access to the Amazon Nova Foundation Model through Amazon Bedrock. The Bedrock service itself streamlines access to advanced large language models with its API. This removes the need for managing the underlying infrastructure.
Step 1: Access Amazon Bedrock Through the AWS Console
- Go to the AWS Console.
- Navigate to the Amazon Bedrock service.
- Request access if needed, particularly if using a region in limited preview.
- Ensure you're in a supported AWS region.
To use Bedrock, users with correct IAM Permissions must enable access to available Bedrock foundation models (FMs).
Step 2: Enable it for Your Account
- Open the Bedrock console and select "Model access".
- Under "Manage model access", request access to the Amazon Nova Foundation Model. This access ensures you get to use the model in the next step.
Step 3: Grab the API Details
- Click on "Foundation models" from the left menu.
- In the model list, search/filter by Provider = Amazon and Model = Nova.
- Click the model name (e.g., amazon.nova-canvas-foundation-v1).
This opens a page displaying:
- Model ID: amazon.nova-canvas-v1:0 (essential for API calls)
- Supported modalities: IMAGE (image-to-image generation)
- Input/Output formats: Accepts and returns image data
- Maximum token limits: 1024
- Customizations support: Currently no support for fine-tuning or RAG (as it's an image model)
- Language: English only
- Deployment type: Serverless
- Latest Version number and Date details
These details will be integrated into our AWS Lambda function to interact with the Nova Foundation Model through Bedrock. Take note of the Model ID.
Code Walkthrough: Building Your Lambda Function
Let’s dissect the Lambda function for text-to-image creation of images. The function takes a text prompt, retrieves it through Amazon Bedrock, stores it in Amazon S3 and returns a temporary shareable link in .png format. Here is the breakdown:
1. Import Libraries and Initialize S3
This initializes the S3 client and sets up the bucket name (replace the placeholder).
2. Define the Lambda Handler and Read the Prompt
This function retrieves the prompt from the incoming request, defaulting to "The cat on beach" if no prompt is provided. This prompt is then used to generate the image.
3. Prepare Bedrock API Call for Image Generation
This configures the call to Amazon Bedrock using the Amazon Nova Canvas model(see the modelId). It passes the prompt and customizes the height, width, and quality.
4. Decode the Image Data
The Bedrock API returns the image encoded in base64 format. In this section, the code will decode it so it can be stored as an image file.
5. Create a Unique Filename
This creates a unique filename using the time stamp and the input prompt to avoid overwriting new images.
6. Upload the image to Amazon S3
This uploads the generated image to the specified S3 bucket. The bucket needs to exist and your Lambda role needs to have the permissions to write to it.
7. Return a Pre-Signed URL
Here it generates a temporary link to the image for an hour (3600 minutes).
Full Lambda Code
Lambda Function Configuration: Complete Guide
Before diving into building the Lambda function, you must first setup your storage. Create an S3 bucket to act as a repository for AI-generated images; its images will be stored securely here. To do this, replace 'your-s3-bucket-name' in the Lambda code with your bucket name.
-
Create the Lambda Function
- Go to the AWS Lambda Console.
- Click Create function.
- Choose "Author from scratch".
- Set Function name to "genai-image-generator".
- Set Runtime to Python 3.12 (Always choose the latest).
- Click Create function.
-
Upload the Code
- Scroll to the Function code section.
- In the Code source editor, paste the complete Python code.
- Click Deploy.
-
Set Up IAM Permissions
- Go to the Configuration tab → Permissions section.
- Click the role name under “Execution role”.
- In the IAM role screen:
- Click Add permissions → Attach policies.
Attach the following AWS managed policies: AmazonS3FullAccess (to upload/access images) and AmazonBedrockFullAccess (to generate images using Bedrock).
-
Increase Lambda Timeout
- Back in the Lambda function page → Configuration → General configuration.
- Click Edit.
- Set Timeout to 5 minutes (00:05:00) – this ensures Bedrock can generate high-quality images.
- Click Save.
-
Test Your Function
- Click the Test button in the Lambda UI.
- Create a new test event with the following input:
-
Click Test again.
If all goes well, you'll see a success notification where "statusCode": 200.The response will include a pre-signed S3 URL. Copy this URL and paste it into a new browser tab to view the generated sample image.