Image Generation with Amazon Nova Canvas with Terraform
Introduction
Generative AI is opening up many possibilities in current times. One such area of this is Image Generation within your AI applications. In this article, we present how to generate images with Generative AI within the AWS Environment. This will be done with the Amazon Nova Canvas model within the AWS Bedrock service.
Background
Amazon Nova Canvas is a Diffusion model which takes a text prompt and an optional image as input and generates an image as output, conditions on the input. A diffusion model is a type of generative model, particularly effective at image generation. Diffusion models are inspired by non-equilibrium thermodynamics in which diffusion describes the movement of molecules from high to low concentration. Machine learning reverses the diffusion process to produce data similar to the training sets.
There are a few key processes involved:
- Forward Diffusion Process — The process of gradually adding random noise (often Gaussian noise) to the training data over a series of steps
- Reverse Diffusion Process — Neural network is trained to reverse the noise addition process, starting from pure noise and iteratively removing it to reconstruct the original data distribution.
- Generating New Data — After training, the reverse process can be used to generate new data samples by starting with random noise and denoising it using the learned model
Architecture Diagram
As we will be walking through an example application, we will go over some of the architecture here. Essentially, we will have a React Tailwind Front End application hosted on S3/CloudFront. This application will interact with Python AWS Lambdas behind an API Gateway. These Lambdas will interact with AWS Bedrock via VPC Interface Endpoints. The
This very same application was also covered in Prompt Engineering with Claude Opus 4 in a Full Stack Application with Terraform
Installation Guide
A VPC Interface Endpoint was used in the previously mentioned article Prompt Engineering with Claude Opus 4 in a Full Stack Application with Terraform
Simply go to the Installation Guide section and follow the steps. This uses Terraform as an Infrastructure as Code tool. This means that it is a more consisted deployment approach avoiding manual AWS Console configuration as much as possible.
All the code can be found at https://github.com/collin-smith/aidemo for review
Demonstration
When you get the application up and running you will get to a page with a prompt from which you can fill out a prompt and an image will be generated.
This image will be presented and also saved to the Gallery (or in an S3 bucket for examination)
If we just go with the default prompt as presented, it will generate an image for you.
So there, you can generate an image with this application in seconds. Before we dive further in, we also get to see the cost of this image
For detailed information, please review at https://aws.amazon.com/bedrock/pricing/
You can change the resolution or quality for different pricing.
Image generation is a powerful Generative AI tool to help people quickly generate images for whatever needs they have. One application is marketing where previously you might have relied on a photographer or content creator.
Code Examination
Just a quick look at the Python Lambda code can be seen at index.py
It is pretty straightforward to generate the prompt and then the base64 image is generated. In the application, this is saved to S3 as part of the process.
Best practices
The best practices for the Amazon Nova Canvas prompting can be seen at Amazon Nova Canvas prompting best practices
Prompts must be no longer than 1024 characters and place the least important details of your prompt near the end.
Avoid the use of negation words such as “no”, “not”, “without” in your prompts
When a prompt is close but not quite perfect, try the following techniques
- Use consistent seed value and make small changes to the prompt to retry
- Keep the prompt the same but change the seed value
When constructing the prompt include short descriptions of:
- the subject
- the environment
- to position or pose of the subject
- lighting description
- camera position/framing
- the visual style or medium (“photo”, “illustration”, “painting”, and so on)
Let us try one now.
“Realistic editorial photo of male coach at the track with a warm smile”
Let us look at “Pre-visualization for TV and film production” with the following prompt:
“drone view of a dark river winding through a rocky mountains landscape, cinematic quality”
Pretty impressive with the cost effectiveness and the speed. In mere seconds you get an original image to help you along in your creative process.
Negative Prompts can be included in your request such as follows:
Negative prompts are items that you do not want to have included as part of the image. This is to remove something that was included as part of the initial prompt.
Additional Thoughts
Prompting fundamentals
It is an art to craft text descriptions to guide the model to the desired output. Well-constructed prompts include specific details about subject, style, lighting perspective, mood, and composition.
Classifier-free Guidance
The Classifier-free guidance scale controls how closely the model should follow the prompt during image generation
- Low values (1.1–3) — allows for more creative freedom but somewhat less adherence to the prompt itself
- Medium values (4–7) — works for most image generation being more balanced
- High values (8–10) — Stricter prompt adherence, which can offer more precision
Benefits of Generative AI Image Generation
Enhancing Creativity and Innovation
Unleashing Imagination — create images from text prompts to help users visualize ideas and concepts
Exploring New Styles and possibilities — produce images in diverse styles and variations, and encouraging experimentation
Overcoming Creative Block — helping users provide a constant stream of new visual ideas and inspiration
Efficiency and Cost Savings
Time saving — AI image generation automates many tedious tasks such as image editing, resizing and background generation
Cost reduction — reducing reliance on expensive photography shoots and costly editing
Scalability — easy to produce large volumes of images, which is beneficial in areas of marketing, e-commerce, and content creation
Industry applications
Marketing and Advertising — create compelling visuals for ad campaigns, social media posts, and marketing materials
E-commerce — enhance online shopping experiences and improve product presentation
Art and Design — explore new creative possibilities and streamline these workflows
Education and Training — create engaging images for training materials and simulations
Research and Development — help to visualize complex data, generate protein sequences and drug discovery
There is nothing stopping anyone from creating beneficial images to enhance their current business and professional opportunities.
Conclusion
We have demonstrated how to use AWS Amazon Nova Canvas to generate images. There are a multitude of benefits to explore with this model!
To reach out for any of your digital transformation needs please contact Bounteous at https://www.bounteous.com/contact/
