Introduction
Amazon Bedrock is a powerful AI service that enables developers to generate text and images using foundation models. This guide walks through the implementation of an API and a simple UI to generate images using Amazon Bedrock.
Development
Prerequisites
Before starting, ensure you have.
- Node.js 18+
- AWS IAM permissions (AmazonBedrockFullAccess)
- Access to available Bedrock foundation models (FMs)
In order to make sure you have been granted access to the Amazon models, go to Amazon Bedrock / Request model access. Choose the models from the Amazon tab and follow the steps in the wizard to save the configuration.
![Amazon tab]()
Clone this GitHub repository.
In the .env file, paste your AWS credentials.
AWS_REGION=your-region
AWS_ACCESS_KEY=your-access-key
AWS_SECRET_KEY=your-secret-key
In the API/src/index.ts file, you can modify the existing configuration to generate the images.
You can find documentation about it in the links below.
const input = {
contentType: "application/json",
accept: "*/*",
modelId: "amazon.titan-image-generator-v2:0",
body: JSON.stringify({
taskType: "TEXT_IMAGE",
textToImageParams: { text: prompt },
imageGenerationConfig: {
numberOfImages: 1,
quality: "standard",
cfgScale: 8.0,
height: 512,
width: 512,
seed: 0,
},
}),
};
To test the demo. Run npx ts-node src/index.ts from the API folder, and npm run dev from UI.
Here are some examples of the images generated and their prompts.
![Image generated]()
![Bedrocks]()
![Cat with birds]()
Conclusion
Amazon Bedrock provides a scalable and efficient way to generate images using advanced AI models. By integrating it with Node.js and React, developers can quickly build applications with AI-powered image generation capabilities. With further enhancements, such as fine-tuning models or expanding UI functionalities, this solution can be adapted to various creative and business needs.
Thanks for reading
Thank you very much for reading. I hope you found this article interesting and may be useful in the future. If you have any questions or ideas you need to discuss, it will be a pleasure to collaborate and exchange knowledge.