Get started with Amazon Bedrock for Image Generation - Part 1 Generative AI
Tags: genai, aws, tutorial, beginners
Published: 2023-10-08 12:47:11

## Amazon Bedrock is now GA

Amazon Bedrock is a fully managed service that helps you to build generative AI applications with foundation models from AI leaders such as AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon.

Amazon Bedrock is now generally available since [28 September 2023](https://aws.amazon.com/blogs/aws/amazon-bedrock-is-now-generally-available-build-and-scale-generative-ai-applications-with-foundation-models/). In the latest announcement, you will now be able to access Llama 2 and Meta's large language models via [Amazon Bedrock API](https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html) and also use the AWS CLI.

Amazon Bedrock announced by AWS in public preview in April 2023 and also announced at [AWS re:Inforce 2023](https://www.youtube.com/watch?v=5EDOTtYmkmI) with the talk *Securely build generative AI apps & control data with Amazon Bedrock (APS208)*.


### Learning Objectives

* Identify the features of Amazon Bedrock
* Explore the benefits of Amazon Bedrock
* Identify the common use cases of Amazon Bedrock
* Understand the solution architecture of Amazon Bedrock
* Understand pricing and AWS region support
* Identify real world industry applications of Amazon Bedrock
* Generate an image using AWS Management Console

### Why Amazon Bedrock?

* Amazon Bedrock is serverless which means that you do not need to manage any IT infrastructure. 

* You may experiment with foundation models without writing any code.

* You may use your own data and customize foundation models with fine-tuning or retrieval augmented generation (RAG) and use agents to perform [complex business tasks](https://aws.amazon.com/bedrock/).


### What are the benefits of Amazon Bedrock?

* You may access foundation models from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon to build generative AI applications using playgrounds for experiments and also use Amazon Bedrock API to make inference.

* You may customize the foundation model using your own dataset that can be uploaded into Amazon S3 for both training and testing.

* You may build agents to perform complex business tasks

* HIPAA eligibility and GDPR compliance 

* Amazon Bedrock data security ensures that your data in transit and at rest is encrypted allows the use of access keys.


[Amazon](https://aws.amazon.com/bedrock/) state that:


 

> 
You can use AWS PrivateLink with Amazon Bedrock to establish private connectivity between FMs and your Amazon Virtual Private Cloud (Amazon VPC) without exposing your traffic to the Internet.

> 

### What are the features of Amazon Bedrock?

This is an overview of Amazon Bedrock below.

![overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwmt31eiyfmamm2aw2ie.png)

The features are outlined in the Amazon Bedrock User Guide and  [include](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html):

**Text playground** – A hands-on text generation application in the AWS Management Console.

**Image playground** – A hands-on image generation application in the console.

![playground](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u8rdv0oitggrpf5z73te.png)

**Chat playground** – A hands-on conversation generation application using the console.

**Embeddings** – Use the API to generate embeddings from the Titan Embeddings G1 - Text model.

**Examples library** 

You may explore example cases from the examples library.

![examplen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qn46ysg0gitcnk3jhu4r.png)

### What are the AWS supported regions?

The supported regions to get started include US East (N. Virginia), US West (Oregon), Asia Pacific (Singapore) and Asia Pacific (Tokyo).

### What is the Pricing for Amazon Bedrock?

There are two [pricing models](https://aws.amazon.com/bedrock/pricing/) for Amazon Bedrock which are:

**On Demand pricing**: You pay for your usage and there is no time commitment.  

You may refer to details for on-demand pricing [here](https://aws.amazon.com/bedrock/pricing/):

* Text generation models: you are charged for every input token processed and every output token generated. 

* Embeddings models: you are charged for every input token processed. A token is comprised of a few characters and refers to the basic unit that a model learns to understand user input and prompt to generate results. 

* Image generation: you pay for the number of images generated.

**Provisioned Throughput pricing**: You pay for the time commitment with purchased throughput to run inference on models.

Amazon recommend that provisioned throughput is suited to large workloads. 

With Amazon Bedrock [pricing](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html), you pay to run inference on any of the third-party foundation models. Pricing is based on the volume of input tokens and output tokens, and on whether you have purchased provisioned throughput for the model.

[Provisioned Throughput](https://aws.amazon.com/bedrock/pricing/) is charged by the hour, you have the flexibility to choose between 1-month or 6-month commitment terms.

### Foundation Models

**Base Model** 

There are a variety of base foundation models for you to choose from that are subject to change. At the moment, you may access the following models:

Amazon Bedrock supports the following [models](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html):

* AI21 Labs: Jurassic-2 Ultra and Jurassic-2 Mid

* Amazon: Titan Text G1 - Express (limited preview) and Titan Embeddings G1 - Text

* Anthropic: Claude v1.x, Claude v2.x and Claude Instant v1.x

* Cohere: Command

* Stability.ai: Stable Diffusion XL 0.x and Stable Diffusion XL 1.x are in limited preview and you may contact your AWS account manager for more information.

![base](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0hiq1dnjb7bnj79twhx.png)

**Custom Model**

You may also bring in your own dataset to customize the models 
with hyperparameters epochs, batch size, learning rate, warmup steps to fine tune the model.

* You may build a foundation model with training data and deploy a fine-tuned model with Amazon Bedrock API.

![custom](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggrcar7ip942bw2zwp8n.png)


### What are the common use cases?

* Text generation e.g. write essays and blog posts
* Virtual Assistants e.g. take user request and perform the tasks 
* Chatbot: for question and answering 
* Search e.g. Search for information from within a document
* Text Summarization e.g. Summarize the main theme of a book or document
* Image Generation e.g. generate real-life photos for property brochures

### What are the real-world industry applications?

There are a few [customer stories](https://aws.amazon.com/bedrock/testimonials/) from AWS:


* Adidas: Used Amazon Bedrock to create a generative AI application for helping their community search for answers to questions.

* Booking.com: Used Amazon Bedrock to build a generative AI application to send destination and accommodation recommendations that was personalized to their customers.

* Salesforce.com: Salesforce have partnered with AWS to bring your own large language model using Salesforce Data Cloud, this was [announced](https://www.salesforce.com/news/stories/salesforce-aws-ai-announcement-dreamforce/) at Salesforce Dreamforce on 11 September 2023.

* Genesys: Genesys are adopting generative AI, to allow users to access a variety of large language models, such as Genesys-developed models and multiple third-party foundational models through Amazon Bedrock. 

### Solution Architecture

The solution architecture for image generation using Stable Diffusion on Amazon Bedrock is from the source Amazon Bedrock workshop available on [Github](https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/05_Image/Bedrock%20Stable%20Diffusion%20XL.ipynb)



![solution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7iiqe3jp0umxvvns4mk6.png)


### Tutorial: Getting started with Amazon Bedrock with Image Playground

Step 1:  Navigate to the AWS Management Console. Login to [AWS account](https://dev.to/aws-builders/getting-started-with-aws-a-sweet-journey-5cjj) as an [IAM Admin User](https://dev.to/aws-builders/creating-your-first-iam-admin-user-and-user-group-in-your-aws-account-machine-learning-part-1-3cne).

![bedrock dasn](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pndg9vjyzqilzivll52.png)


Step 2:  In this tutorial we will use AWS region N Virginia (US-east-1).



![region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zm3iq47yxu4hkan01gmq.png)

Step 3: Type the word 'Bedrock' into the search bar and navigate to the Amazon Bedrock console and click **Get started**.


![BRD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8v6naq5r6hzfmlq48w9.png)

Step 4: Request model access. Navigate to the third party provider of foundation models e.g. Stability AI and select **edit access**.
Check the box to select the foundation model and **Request Access**.
It will take a few minutes to have access granted. Refresh your browser.


![access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvggamfwkoa2cidzgnx9.png)

I selected the foundation model from Stability AI which was Stable Diffusion XL-Preview.

Step 5: Navigate to **Image** to select the image playground to commence prompting.

Select the **image** on the left-hand pane.


![navigate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/372m96mvby3xikg3kz9i.png)


Type a word in natural language which is to give a prompt. In the box you may type a few words e.g. Sydney Opera House Real Life Summer.
It will takes a few seconds to create an image.


![artist](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/56rwmfwsuqcc2hq4x302.png)


On the right-handside of the image playground, you may adjust the slider to update the inference configuration to change the output quality of the generated image.


![infer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a86olw43z5xsd8ll3nb.png)

Step 6: You may also download this image that you have generated and use this for your project e.g. blog post, newsletter, post card, document, magazine etc.

![Sydney](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lg53si04o3weyp0plmpv.png)


Step 7:  Clean Up Resources

As a best practice, if you no longer need to generate images from your foundation model, please clean up your resources by removing model access from the third party foundation model provider by clicking **edit**, un-check the box e.g Stability AI and then select **Save Changes**.

![model access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tks6pi9ir7etqyuidlg5.png)

### Resources 

If you would like to learn more about Amazon Bedrock, I encourage 
you to explore to useful resources.

**AWS Skill Builder**

You may subscribe for a 7-day free trial of [AWS Skill Builder](https://skillbuilder.aws/) for a limited time and complete the 1-hour course **Amazon Bedrock Foundations course**.


![freetrial](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wuhb9q9gkdfyddpa820z.png)

**Amazon Bedrock Workshop - Github**

You may also obtain practical hands-on knowledge of Amazon Bedrock via workshops on [Github](https://github.com/aws-samples/amazon-bedrock-workshop/tree/main/05_Image) you will be able to practice with the labs.


![github](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow9hdwgjdzunllktlf2o.png)


### Conclusion

In this lesson you have learnt how to generate images with foundation models. I hope you will continue to apply prompt engineering to your own use cases.

Until the next lesson - Happy Learning! 😀

### References

* [Amazon Bedrock User Guide]( https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html)

* [Amazon Bedrock announcement on AWS Blog](https://aws.amazon.com/blogs/aws/amazon-bedrock-is-now-generally-available-build-and-scale-generative-ai-applications-with-foundation-models/)

* [Amazon Bedrock website](https://aws.amazon.com/bedrock/)

* [Amazon Boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock.html)

### This Month - AWS Innovate Modern Application - 26 October 2023

You are invited to AWS Innovate Modern Application on 26 October 2023 in the Asia Pacific and Japan regions.

This conference is FREE, register for the keynotes and sign up for various sessions to learn the latest in Generative AI and more.

You may register at this [link](https://aws.amazon.com/events/aws-innovate/apj/modern-apps/).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2n7l4y4g9bke9jbifxl0.png)

### Next Month - AWS re:Invent 2023 - 27th November to 1st December 2023

**In-Person experience**

You are invited to AWS re:Invent 2023 in Las Vegas, you may register at this [link](https://reinvent.awsevents.com/) for an in-person experience. After you register you may navigate to the [session catalog](https://reinvent.awsevents.com/session-catalog/?trk=www.google.com) and start selecting your sessions and favourite the breakout sessions, chalk talks, keynotes, innovation talks, customer talks, community events and more. 

AWS re:invent is also about building your networks and connecting with the AWS Community at [PeerTalks](https://reinvent.awsevents.com/learn/peertalk/?trk=www.google.com)

If you need more help with selecting sessions from the catalog, be sure to browse the [attendee guides](https://reinvent.awsevents.com/learn/attendee-guides/?trk=www.google.com) that were written by AWS Heroes and written for you in mind to help you find recommended sessions from generative AI, machine learning, data and analytics, containers, community, devtools, serverless, reliability engineering, storage, sustainability, introverts and enterprise leadership.

You may also browse the [agenda](https://reinvent.awsevents.com/agenda/?trk=www.google.com) to help plan your week.

![in person](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8akiv1amwwgbiwsvzr61.png)

**Live Stream Experience**

If you can't make it to Las Vegas this year, you may register for FREE and attend the live stream so that you may also enjoy the keynotes, innovation talks and your free pass will provide you will post conference access to selected breakout sessions. You may [register](https://reinvent.awsevents.com/register/virtualregistration/) for live streaming.

![livestream](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qffb4sz6g0y99nf7a2c.png)

### Amazon Bedrock announcement - 29 September 2023 by Dr Swami Sivasubramanian the VP of Analytics, Database and Machine Learning

{% embed https://twitter.com/awscloud/status/1707412406102634826 %}