DEV Community

1

Generating Images with Amazon Bedrock

Introduction

Amazon Bedrock is a powerful AI service that enables developers to generate text, images, and more 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.

Image description

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
Enter fullscreen mode Exit fullscreen mode

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,
        },
      }),
    };
Enter fullscreen mode Exit fullscreen mode

To test the demo. Run npx ts-node src/index.ts from API folder, and npm run dev from UI.

Here are some examples of the images generated and their prompts.

Image description

Image description

Image description

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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post