<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Andrea Liao</title>
    <description>The latest articles on Forem by Andrea Liao (@andrealiao).</description>
    <link>https://forem.com/andrealiao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1065753%2F606fa2a2-c4dd-40a6-b6b4-5f99d823bc0a.jpeg</url>
      <title>Forem: Andrea Liao</title>
      <link>https://forem.com/andrealiao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/andrealiao"/>
    <language>en</language>
    <item>
      <title>AI-Driven Product Imagery: Custom Image Generation &amp; Variations with Amazon Bedrock</title>
      <dc:creator>Andrea Liao</dc:creator>
      <pubDate>Fri, 28 Feb 2025 01:12:46 +0000</pubDate>
      <link>https://forem.com/andrealiao/ai-driven-product-imagery-custom-image-generation-variations-with-amazon-bedrock-386e</link>
      <guid>https://forem.com/andrealiao/ai-driven-product-imagery-custom-image-generation-variations-with-amazon-bedrock-386e</guid>
      <description>&lt;p&gt;👉🏻 A step-by-step guide to generating and refining product images with prompts with Amazon Bedrock.&lt;/p&gt;

&lt;p&gt;Creating high-quality, realistic product images is crucial for industries like e-commerce, advertising, and digital content creation. with &lt;strong&gt;generative AI models&lt;/strong&gt; available in &lt;strong&gt;&lt;code&gt;Amazon Bedrock&lt;/code&gt;&lt;/strong&gt;, businesses can automate and enhance their image creation workflows, generating customized visuals quickly and efficiently.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Amazon Bedrock&lt;/code&gt; provides a &lt;strong&gt;user-friendly interface&lt;/strong&gt; and access to multiple &lt;strong&gt;foundation models&lt;/strong&gt; optimized for different generative AI tasks. &lt;strong&gt;&lt;code&gt;Amazon Titan Image Generator G1&lt;/code&gt;&lt;/strong&gt;, is specifically designed to produce high-resolution, photorealistic images with fine-tuned control over attributes such as texture, lighting, and product variations. &lt;/p&gt;

&lt;p&gt;In this use case, we will explore how to generate an advertising image for a skincare product and later on, remove the product itself to potentially replace another product. We will also create an variation of an existing image and use it as a marketing campaign poster.&lt;/p&gt;

&lt;p&gt;Specifically, we will explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The capabilities of the &lt;strong&gt;&lt;code&gt;Amazon Titan Image Generator G1&lt;/code&gt;&lt;/strong&gt;, including how it handles product image generation.&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;invoke the model using the &lt;code&gt;Amazon Bedrock&lt;/code&gt; runtime&lt;/strong&gt; within a Jupyter Notebook.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  1. Amazon Bedrock Image Generative Model
&lt;/h1&gt;

&lt;p&gt;Titan Image Generator v1 is a &lt;strong&gt;versatile tool&lt;/strong&gt; that allows users to &lt;strong&gt;create, edit, and customize images&lt;/strong&gt; based on simple text descriptions. Whether you're designing marketing materials, product visuals, or social media content, this model makes the process faster and more efficient. [1]&lt;/p&gt;

&lt;p&gt;Here are some key features and real-world examples of how you can use them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Generate Images from Text:&lt;/strong&gt; For example, if a skincare brand needs a &lt;strong&gt;“luxury serum bottle on a marble countertop with soft lighting,”&lt;/strong&gt; they can enter this prompt, and Titan will generate a high-quality image in seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edit Existing Images:&lt;/strong&gt; Upload an image and make changes without manual work. A business could upload a &lt;strong&gt;lipstick product photo&lt;/strong&gt; and change its color from red to pink just by typing &lt;strong&gt;“make the lipstick soft pink.”&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inpainting &amp;amp; Outpainting:&lt;/strong&gt; This helps fill in missing parts of an image or expand it beyond its original borders. For instance, a beauty brand might want to &lt;strong&gt;extend the background of a product photo&lt;/strong&gt; to fit different ad formats without reshooting the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate Variations:&lt;/strong&gt; Need multiple product shots with different styles? Titan can create several versions of an image with minor changes. A &lt;strong&gt;cosmetic company testing different packaging colors&lt;/strong&gt; could quickly generate variations to see which looks best.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Style Transfer:&lt;/strong&gt; Users can apply styles from reference images. For example, a &lt;strong&gt;skincare brand inspired by vintage apothecary designs&lt;/strong&gt; could upload an old-fashioned product label and transform a modern image into something with a &lt;strong&gt;classic, retro feel.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With &lt;strong&gt;&lt;code&gt;Amazon Titan Image Generator v1&lt;/code&gt;&lt;/strong&gt;, businesses and content creators can &lt;strong&gt;save time, reduce costs, and produce high-quality visuals&lt;/strong&gt; without needing advanced design skills or expensive photo shoots.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. AWS tools and control flow
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvw8lm90u20vk3w2fnqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzvw8lm90u20vk3w2fnqw.png" alt="Image description" width="530" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;AWS Tools Used:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Amazon Titan Image Generator&lt;/strong&gt;: A generative AI model available in &lt;strong&gt;&lt;code&gt;Amazon Bedrock&lt;/code&gt;&lt;/strong&gt; that creates images based on text prompts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jupyter Notebook&lt;/strong&gt;: An interactive computing environment where users can write Python code to interact with AWS services, including Amazon Bedrock.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image Playground&lt;/strong&gt;: A visualization tool where users can see the generated images and experiment with different styles, variations, and refinements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Control Flow:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Input (Prompt Entry)&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The user provides a &lt;strong&gt;text prompt&lt;/strong&gt; (e.g., &lt;em&gt;“A skincare bottle with floral background”&lt;/em&gt;) to describe the desired image.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Processing in Jupyter Notebook&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The user writes a script in &lt;strong&gt;Jupyter Notebook&lt;/strong&gt; to call the &lt;strong&gt;Amazon Titan Image Generator API&lt;/strong&gt; via &lt;strong&gt;Amazon Bedrock runtime&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The Titan model processes the request, generating an image based on the text prompt.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Amazon Titan Image Generation Pipeline&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The model &lt;strong&gt;interprets&lt;/strong&gt; the prompt and &lt;strong&gt;creates an image&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It may apply additional &lt;strong&gt;AI processing techniques&lt;/strong&gt; (e.g., style transfer, variations, inpainting).&lt;/li&gt;
&lt;li&gt;The final generated image is returned.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image Playground Visualization&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The user can view and further refine the generated image in &lt;strong&gt;Image Playground&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Additional modifications, such as adjusting styles or re-generating variations, can be applied here.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  3. Step-by-Step Guide on Image Generation &amp;amp; Variation
&lt;/h1&gt;

&lt;h2&gt;
  
  
  3.1 Generation &amp;amp; Variation in Bedrock Playground
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1.1 Generate image with prompts
&lt;/h3&gt;

&lt;p&gt;In AWS Console, go to Amazon Bedrock Image playground:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbftk9drkog2vqwo3ju8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbftk9drkog2vqwo3ju8b.png" alt="Image description" width="800" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Amazon as Model providers&lt;/li&gt;
&lt;li&gt;Select Titan Image Generator G1&lt;/li&gt;
&lt;li&gt;Click on Apply&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88n2oes8vna8dahgjl5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88n2oes8vna8dahgjl5i.png" alt="Image description" width="546" height="896"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A configuration panel is also available in the image playground to configure parameters before sending the request to the model.&lt;/p&gt;

&lt;p&gt;The following configurations are available for the &lt;strong&gt;Generate image&lt;/strong&gt; action:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Negative prompt&lt;/strong&gt;: A prompt that describes what you do not want in the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Orientation&lt;/strong&gt;: Landscape or portrait orientation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Size&lt;/strong&gt;: The resolution of the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number of images&lt;/strong&gt;: The number of images to generate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt strength&lt;/strong&gt;: How closely the model should follow the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seed&lt;/strong&gt;: A random seed value to generate a different, but similar, image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the purpose of illustration and cost-effective consideration, we will start with a lower resolution 512 x 512, and only generate 1 image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F15ibmjn980ozh3031fik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F15ibmjn980ozh3031fik.png" alt="Image description" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the prompt input box, provide the prompt for the product image that you want to generate. &lt;/p&gt;

&lt;p&gt;In this scenario, we are aiming to create a picture for a skincare product with soft and lightening background.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;How to create a good prompt for image generation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Basic Product Display:&lt;/strong&gt; &lt;em&gt;"A sleek, modern skincare serum bottle on a marble countertop with soft lighting and a blurred background."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lifestyle Context:&lt;/strong&gt; &lt;em&gt;"A hand applying a moisturizing cream, with a natural, bright bathroom setting in the background."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimalist Branding Shot:&lt;/strong&gt; &lt;em&gt;"A luxury perfume bottle placed in the center with a clean, white background and soft shadows."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple Product Variants:&lt;/strong&gt; &lt;em&gt;"Three lipsticks in different shades arranged diagonally on a glossy black surface, reflecting light."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seasonal &amp;amp; Thematic:&lt;/strong&gt; &lt;em&gt;"A festive holiday-themed packaging for a skincare set, surrounded by pinecones and warm golden lights."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;E-commerce Ready Images:&lt;/strong&gt; &lt;em&gt;"A neatly arranged flat lay of a beauty product lineup on a pastel pink background with even lighting."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Texture &amp;amp; Close-up Shots:&lt;/strong&gt; &lt;em&gt;"A macro shot of a hydrating gel with water droplets, showing a fresh and dewy texture."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.1.2 Create image variations
&lt;/h3&gt;

&lt;p&gt;Click on the image, there is an Action button in the configuration panel. Click the &lt;strong&gt;Actions&lt;/strong&gt; dropdown below the configurations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Generate variations&lt;/strong&gt;: Generate variations of the current image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove object&lt;/strong&gt;: Remove an object from the image. Also referred to as inpainting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replace background&lt;/strong&gt;: Replace the background of the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replace object&lt;/strong&gt;: Replace an object in the image with another object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inpainting is a powerful technique for removing or replacing objects and backgrounds in an image. It works by intelligently filling in missing or unwanted areas, ensuring the new content blends naturally with its surroundings. The model analyzes the surrounding details and generates a seamless replacement, making it ideal for tasks like erasing distractions, swapping backgrounds, or restoring damaged images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft63g2cvmygif4dg9vo7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft63g2cvmygif4dg9vo7v.png" alt="Image description" width="520" height="690"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our scenario, we will try to remove the skincare product. When removing an object from an image in the playground editor, you need to specify the area using either a mask selector or a text prompt. &lt;/p&gt;

&lt;p&gt;By default, the mask selector covers the entire image, but you can adjust it by dragging any of the four corners to focus on the specific area you want to edit. &lt;/p&gt;

&lt;p&gt;Alternatively, you can use a mask prompt by describing the object you want to remove, allowing the model to intelligently identify and erase it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8e4102ew7asa1kylstfy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8e4102ew7asa1kylstfy.png" alt="Image description" width="512" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After removal, we can review the image. The skincare bottle has been removed, though not entirely, and the background is attempting to fill the covered area with flowers. The refined image is not perfect, as there are still remnants of the bottle. &lt;/p&gt;

&lt;h2&gt;
  
  
  3.2 Generation &amp;amp; Variation in Bedrock runtime in Jupyter Notebook
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.2.1 Obtain AWS credentials
&lt;/h3&gt;

&lt;p&gt;This notebook requires AWS credentials to access the Amazon Bedrock runtime, including &lt;code&gt;ACCESS_KEY_ID&lt;/code&gt;, &lt;code&gt;SECRET_ACCESS_KEY&lt;/code&gt; and &lt;code&gt;REGION&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flp22fbhr4f9gzebv0yuv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flp22fbhr4f9gzebv0yuv.png" alt="Image description" width="800" height="70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2.2 Import image and create Bedrock runtime
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;IPython.display&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;PIL&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Image&lt;/span&gt;

    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;people.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;people.jpg&lt;/code&gt; image has been pre-uploaded for this use case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpn51uttnc7dgp8sfcc9z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpn51uttnc7dgp8sfcc9z.png" alt="Image description" width="800" height="478"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;

&lt;span class="n"&gt;bedrock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bedrock-runtime&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;REGION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ACCESS_KEY_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;SECRET_ACCESS_KEY&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Amazon Bedrock runtime is used to interact with the Amazon Titan Image Generator model. The &lt;code&gt;invoke_model&lt;/code&gt; method accepts inference parameters to specify how the image should be generated.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2.3 Invoke model
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;botocore.exceptions&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ClientError&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Invoke the model
&lt;/span&gt;    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bedrock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;modelId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;accept&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;contentType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;response_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

    &lt;span class="c1"&gt;# Convert the image to bytes
&lt;/span&gt;    &lt;span class="n"&gt;raw_image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response_body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;images&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nb"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw_image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ascii&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;image_bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;b64decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Return error if any
&lt;/span&gt;    &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response_body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;image_bytes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "people.jpg" image file is first read and encoded into base64 format, then decoded into a UTF-8 string. This resulting &lt;code&gt;input_image&lt;/code&gt; string is used as part of the model inference parameters in the request body.&lt;/p&gt;

&lt;p&gt;The model name "amazon.titan-image-generator-v1" is defined, and the body JSON object contains the relevant inference parameters.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;taskType&lt;/code&gt; is set to &lt;code&gt;IMAGE_VARIATION&lt;/code&gt;, with the &lt;code&gt;imageVariationParams&lt;/code&gt; object containing the &lt;code&gt;input_image&lt;/code&gt; string. The &lt;code&gt;text&lt;/code&gt; parameter serves as the model's prompt, while the &lt;code&gt;negativeText&lt;/code&gt; parameter indicates what the model should avoid generating, similar to its use in the Image Playground. The &lt;code&gt;images&lt;/code&gt; parameter can accept between 1 and 5 reference images.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;similarityStrength&lt;/code&gt; parameter controls how closely the generated image should resemble the reference image. A lower value increases randomness in the output. In this example, the &lt;code&gt;similarityStrength&lt;/code&gt; is set to 1.0, ensuring the generated image is as similar as possible to the reference image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;people.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;image_file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;input_image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;b64encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;model_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;amazon.titan-image-generator-v1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
     &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;taskType&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;IMAGE_VARIATION&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;imageVariationParams&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Generate a variation of the image with three different people, photo-realistic, 8k, hdr&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;negativeText&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bad quality, low resolution, cartoon&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;images&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;input_image&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
         &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;similarityStrength&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;imageGenerationConfig&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;numberOfImages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;width&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cfgScale&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;8.0&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code performs the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reading and encoding the image&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The code opens the file "people.jpg" in binary read mode (&lt;code&gt;"rb"&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The contents of the image file are read and then encoded into a base64 format using the &lt;code&gt;base64.b64encode()&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;The result is then decoded into a UTF-8 string with &lt;code&gt;.decode('utf8')&lt;/code&gt; and stored in the variable &lt;code&gt;input_image&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setting the model ID&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The variable &lt;code&gt;model_id&lt;/code&gt; is assigned the string &lt;code&gt;'amazon.titan-image-generator-v1'&lt;/code&gt;, which represents the model that will be used to generate the image variation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Building the request body&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The code creates a JSON object (&lt;code&gt;body&lt;/code&gt;) using &lt;code&gt;json.dumps()&lt;/code&gt;, which prepares the parameters to send in the request to the model API.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;image_bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BytesIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_bytes&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;

&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;ClientError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;A client error occured: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Trying to generate and display the image&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;try&lt;/code&gt; block attempts to execute the following:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;generate_image()&lt;/code&gt;&lt;/strong&gt;: This function is called with the &lt;code&gt;model_id&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt; parameters, which contain the model ID and the request body containing the image generation details, respectively. The function likely sends a request to an image generation API and returns the image in bytes (&lt;code&gt;image_bytes&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Image.open(io.BytesIO(image_bytes))&lt;/code&gt;&lt;/strong&gt;: The returned &lt;code&gt;image_bytes&lt;/code&gt; (binary data) are passed to &lt;code&gt;io.BytesIO()&lt;/code&gt;, which converts the byte data into a byte stream object that can be read like a file. The &lt;code&gt;Image.open()&lt;/code&gt; function from the &lt;code&gt;PIL&lt;/code&gt; library (Python Imaging Library) is then used to open the image from this byte stream and display it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5pigndln65dp8hy2bac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5pigndln65dp8hy2bac.png" alt="Image description" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this use case, we can create many variations of the image to showcase products, with aligned styles and tones, without shooting for multiple products. &lt;/p&gt;

&lt;h1&gt;
  
  
  4. Conclusion
&lt;/h1&gt;

&lt;p&gt;In this use case, we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Utilized &lt;strong&gt;&lt;code&gt;Amazon Bedrock&lt;/code&gt;&lt;/strong&gt; to access and integrate powerful AI models, specifically the &lt;strong&gt;&lt;code&gt;Titan Image Generator Model&lt;/code&gt;&lt;/strong&gt;, for generating and editing images.&lt;/li&gt;
&lt;li&gt;Leveraged the &lt;strong&gt;Image Playground&lt;/strong&gt; to easily experiment with and refine the image generation process by providing customizable prompts and parameters.&lt;/li&gt;
&lt;li&gt;Employed the &lt;strong&gt;&lt;code&gt;Amazon Bedrock&lt;/code&gt; Runtime&lt;/strong&gt; to simplify the deployment and execution of these AI models, streamlining the image generation workflow.&lt;/li&gt;
&lt;li&gt;Customized image outputs using &lt;strong&gt;image variation parameters&lt;/strong&gt; like &lt;strong&gt;text prompts&lt;/strong&gt;, &lt;strong&gt;negative text&lt;/strong&gt;, and &lt;strong&gt;similarity strength&lt;/strong&gt;, ensuring the generated images align with specific requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Reference and further readings:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;[1] &lt;strong&gt;Amazon Titan Image Generator G1 models overview.&lt;/strong&gt; &lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/titan-image-models.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/bedrock/latest/userguide/titan-image-models.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>amazonbedrock</category>
      <category>aws</category>
      <category>generative</category>
    </item>
    <item>
      <title>Build a Conversational Generative AI Assistant Using Amazon Q Business – A Step-by-Step Guide</title>
      <dc:creator>Andrea Liao</dc:creator>
      <pubDate>Sun, 22 Dec 2024 00:36:54 +0000</pubDate>
      <link>https://forem.com/aws-builders/build-a-conversational-generative-ai-assistant-using-amazon-q-business-a-step-by-step-guide-m35</link>
      <guid>https://forem.com/aws-builders/build-a-conversational-generative-ai-assistant-using-amazon-q-business-a-step-by-step-guide-m35</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Let’s empower your corporate team with a secure, permission-based conversational AI assistant created by Amazon Q Business.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a &lt;code&gt;step-by-step guidance&lt;/code&gt; on how to create a conversational generative AI application for employees, powered by your own enterprise content. With &lt;code&gt;Amazon Q Business&lt;/code&gt; application, you can ingest proprietary data through secure connectors and define access policies so the application only responds with information users are allowed to see – and confirm the response uses only content the user has permission to access.&lt;/p&gt;

&lt;p&gt;This article also explores the generative AI models utilized by &lt;code&gt;Amazon Q Business&lt;/code&gt; to power conversational experiences and generate tailored outputs, such as email responses, based on enterprise data. &lt;/p&gt;

&lt;p&gt;At the end, there will be a bonus content on how to develop a Plugin for employee to ask tailored question and submit request to corporate system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F907guwohurktndbni6wk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F907guwohurktndbni6wk.png" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Amazon Q Business&lt;/code&gt; is a generative AI–powered assistant that can answer questions, provide summaries, generate content, and securely complete tasks based on data and information in your enterprise systems. It empowers employees to be more creative, data-driven, efficient, prepared, and productive. [1]&lt;/p&gt;

&lt;p&gt;As enterprises grapple with fast technological change, the enterprise contents have been spiking to a new high level. As an employee, we may frequently interact with enterprise HR policies documents, retrieve payroll information, look for IT helpdesk contact, etc..&lt;/p&gt;

&lt;p&gt;With an in-house generative AI assistant, you can quickly find accurate answers from your enterprise content, backed up with citations and references. You can brainstorm new ideas, generate content, or create summaries using &lt;code&gt;Amazon Q Business&lt;/code&gt; based on your enterprise data. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Amazon Q Business&lt;/code&gt; ensures that users access enterprise content securely according to their permissions. You can quickly deploy &lt;code&gt;Amazon Q Business&lt;/code&gt; with built-in connectors to popular enterprise repositories.&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Control Flow Overview:
&lt;/h1&gt;

&lt;p&gt;From the user making a request to receiving a response, &lt;code&gt;Amazon Q Business&lt;/code&gt; acts as a powerful engine that processes queries, enforces access policies, and delivers accurate information securely from your enterprise data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7f0ogktuss8k18ijo2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7f0ogktuss8k18ijo2i.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Query&lt;/strong&gt;: The user initiates a request by entering a &lt;code&gt;natural language query&lt;/code&gt;, such as “How to make a claim for flood damage?”&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic Retrieval&lt;/strong&gt;: &lt;code&gt;Amazon Q Business&lt;/code&gt; performs semantic search across all ingested content repositories to locate information most relevant to the query. It ensures access control by filtering results based on the user’s permissions, retrieving only authorized documents and data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Contextualization and Prompt Construction&lt;/strong&gt;: &lt;code&gt;Amazon Q Business&lt;/code&gt; takes the user’s query along with the retrieved content and constructs a prompt to pass to the underlying &lt;code&gt;large language model&lt;/code&gt; (LLM). The prompt is carefully designed to maintain relevance and provide sufficient context to the LLM, for instance, “Using the latest sales report, summarize key financial outcomes relevant to last quarter.”&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM Processing and Response Generation&lt;/strong&gt;: The LLM leverages both the prompt and the contextual data provided to generate a detailed yet succinct response. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response Delivery&lt;/strong&gt;: The system then sends this synthesized response back to the user, ensuring it is accessible in a user-friendly format, such as a concise text summary or a highlighted passage within the original document.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  2. AWS tools and resources
&lt;/h1&gt;

&lt;p&gt;The following AWS tools and resources will be used to configure an &lt;code&gt;Amazon Q Business&lt;/code&gt; application that acts as the generative AI assistant for your company data:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhkaz9kmzqd278wz7s7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjhkaz9kmzqd278wz7s7o.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon Q Business Application Configuration&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;Amazon Q Business&lt;/code&gt;’s native retriever to upload documents and integrate external data sources.&lt;/li&gt;
&lt;li&gt;Connect a web crawler data source via &lt;code&gt;Amazon Q Business&lt;/code&gt;’s built-in connector to automatically ingest content from approved web sources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Amazon S3 Bucket Setup and Data Ingestion&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an &lt;code&gt;Amazon S3&lt;/code&gt; bucket to store company contents and data.&lt;/li&gt;
&lt;li&gt;Configure an &lt;code&gt;Access Control List&lt;/code&gt; (ACL) on the S3 bucket to enforce fine-grained permissions for data access.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Amazon Q Business&lt;/code&gt;’s connector to ingest data from the S3 bucket, ensuring only authorized content is accessible based on the ACL settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;User Authentication with AWS IAM Identity Center (IDC)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the Amazon Q application’s web experience and set up &lt;code&gt;AWS IAM&lt;/code&gt; Identity Center (IDC) as the &lt;code&gt;Identity Provider&lt;/code&gt; (IdP).&lt;/li&gt;
&lt;li&gt;Configure user and group information in IDC, allowing &lt;code&gt;Amazon Q Business&lt;/code&gt; to recognize each user’s access permissions and group memberships.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Secure Query Response Generation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users access the Amazon Q web experience and submit natural language queries.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Amazon Q Business&lt;/code&gt; retrieves relevant content, filtering responses based on the permissions defined by the S3 ACL and user/group data from IDC.&lt;/li&gt;
&lt;li&gt;Responses are generated based only on the content the logged-in user has permissions to access, ensuring data security and compliance with access policies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  3. Steps to configure and deploy an Amazon Q Business application
&lt;/h1&gt;

&lt;p&gt;With &lt;code&gt;Amazon Q Business&lt;/code&gt;, we’ll set up an &lt;strong&gt;Application&lt;/strong&gt;, configure a &lt;strong&gt;Retriever&lt;/strong&gt;, and deploy a &lt;strong&gt;Web Experience&lt;/strong&gt; using AWS IAM Identity Center. Once deployed, you can share the web experience URL with users so they can securely access the application. Here’s how to get started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Create the Application.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;AWS Management Console&lt;/code&gt; for &lt;code&gt;Amazon Q Business&lt;/code&gt; has a full step-by-step guide for creating applications. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deploy the Web Experience.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create a secure URL to share the application using AWS IAM Identity Center . &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Configure the Retriever&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose an appropriate retriever (e.g., a native retriever or an external retriever) based on your application's requirements. Configure it to optimize the retrieval process by selecting the indexing strategy, setting access policies, and ensuring the retriever aligns with your enterprise content structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set Up Data Sources&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add company documents by uploading them directly, setting up a data source with sample documents, or connecting &lt;code&gt;Amazon Q Business&lt;/code&gt; to the existing data sources using native connectors. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Try the Web Experience&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Access the secure URL to test the web experience as an end user. Submit a variety of queries to ensure the application retrieves accurate and permission-filtered responses, validating that the data ingestion and access policies are correctly implemented.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Step-by-Step Configuration Guidance
&lt;/h1&gt;

&lt;h2&gt;
  
  
  4.1 Infrastructure setup
&lt;/h2&gt;

&lt;p&gt;As our focus is going to be Amazon Q application, for the convenience, the infrastructure i.e. the S3 bucket containing the sample data to be used as the data source, and AWS IAM Identity Center (IDC) with sample users and groups were already created in advance.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.2 &lt;strong&gt;Configure Amazon Q Business&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz0x3m8k4gs0a6jdwx5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz0x3m8k4gs0a6jdwx5e.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In AWS Management Console, you may follow the steps with detailed instructions.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2.1 Create Application
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xj0n2m930nqy8cjyvsj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xj0n2m930nqy8cjyvsj.png" alt="Image description" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the application with the name “&lt;strong&gt;Generative-AI-Assistant&lt;/strong&gt;”.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Create and use a new service-linked role (SLR)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Service-Linked Role (SLR)&lt;/strong&gt; is a special type of IAM role directly associated with an AWS service—in this case, Amazon Q Business. &lt;/p&gt;

&lt;p&gt;When you create a new SLR, it simplifies permission management by linking the role specifically to &lt;code&gt;Amazon Q Business&lt;/code&gt;, allowing the service to access resources securely and as needed for your application to function properly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Amazon Q Business&lt;/code&gt; will use this role to access and manage resources like document storage, retrieval processes, and data source connections, without requiring manual setup for each task.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4.2.2 Select Retriever
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98yfobdkt3g4se5csk4d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98yfobdkt3g4se5csk4d.png" alt="Image description" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Use native retriever, leave the other selections as they are and click
Next.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The native retriever is Amazon Q Business’s built-in tool for searching and retrieving relevant information from your ingested documents and data sources. &lt;br&gt;
This option is ideal for users who don’t require advanced search features or external indexing (like Amazon Kendra). The native retriever is simple to configure and is designed to handle typical search and retrieval needs within Amazon Q Business.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4.2.3 Connect Data Source
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvta3wm9eznt7v03xvct2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvta3wm9eznt7v03xvct2.png" alt="Image description" width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the Connect data sources screen, scroll to the bottom of the screen and click Next.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.2.4 Add groups and users
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoe7ndy11kubob5g7jfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoe7ndy11kubob5g7jfz.png" alt="Image description" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Web experience service access select Use an existing service role.&lt;/li&gt;
&lt;li&gt;Click the pull down menu Service role name and then search for the pre-configured role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtc2w2hragpmzdkjqbta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtc2w2hragpmzdkjqbta.png" alt="Image description" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next click on Add Groups and users, select Assign existing users and groups, click Next and click Get Started.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fli2b0h22fjly2wxrgh7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fli2b0h22fjly2wxrgh7h.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the Assign users and groups window use the search box to find users and groups by name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foj0mw20vpo4cjevmk03h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foj0mw20vpo4cjevmk03h.png" alt="Image description" width="800" height="125"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After finishing all steps, click Create, and ensure the application is successfully created. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4.3 &lt;strong&gt;Configure data sources&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.3.1 Upload files connector
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7fvrfz6ttpikht0z0uh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7fvrfz6ttpikht0z0uh.png" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the Add data source page, upload all relevant corporate documents. We will be using a couple of corporate insurances policies html files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Start conversation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxe17ussj9zh5pg5ov8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxe17ussj9zh5pg5ov8z.png" alt="Image description" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we can start the conversation in Amazon Q Business, by asking questions, such as “How to make a claim on flood damage?”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgh8bnus29qwqln9ibmcz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgh8bnus29qwqln9ibmcz.png" alt="Image description" width="800" height="830"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We may further ask Amazon Q Business to generate an email using the results from previous conversation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5acoxzk8zbl6gwkox2zi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5acoxzk8zbl6gwkox2zi.png" alt="Image description" width="631" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Amazon Q Business leverages generative AI models, such as those based on Amazon Bedrock or proprietary large language models (LLMs) provided by AWS, to generate emails from the results of a previous conversation. &lt;/p&gt;

&lt;p&gt;Here's how it works:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Context&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;The generative AI model processes the previous conversation's context, extracting relevant details such as the user's queries, retrieved responses, and any instructions provided.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Template and Formatting&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Amazon Q Business&lt;/code&gt; can apply pre-defined email templates or formatting rules specified by the organization. The system ensures the generated email adheres to the tone, style, and branding requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generating the Email&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Using a foundation model such as GPT (via &lt;code&gt;Amazon Bedrock&lt;/code&gt;) or other proprietary LLMs, the system creates a draft email. These models are fine-tuned for enterprise-specific tasks, ensuring the content is accurate and concise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incorporating Permissions&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;The model respects access policies and includes only information the user is authorized to see, ensuring secure and compliant email generation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Review and Delivery&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;The generated email can either be sent directly to recipients or reviewed by a human for final approval before delivery.&lt;/p&gt;

&lt;p&gt;This process ensures the generated email is contextually accurate, secure, and aligned with the enterprise’s communication standards.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3.2 &lt;strong&gt;Web crawler connector&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In addition to existing corporate data, we can add Web contents as our data source to enrich the existing content.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixodks93r0hm2m5o2itf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixodks93r0hm2m5o2itf.png" alt="Image description" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Source URLs and provide Source URLs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytkzzi59zsuwoub8mnir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytkzzi59zsuwoub8mnir.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For the purpose of testing, in the scope section, we will reduce the scope to index fewer number of documents to complete the ingestion quickly. &lt;br&gt;
Setting the &lt;strong&gt;Crawl depth&lt;/strong&gt; to &lt;strong&gt;0&lt;/strong&gt; means that only the initial page or entry point of each document will be indexed. &lt;code&gt;Amazon Q Business&lt;/code&gt; won’t follow any internal links within the document, reducing the amount of content to ingest and further speeding up the process.&lt;br&gt;
With &lt;strong&gt;Maximum links per page&lt;/strong&gt; set to &lt;strong&gt;1&lt;/strong&gt;, &lt;code&gt;Amazon Q Business&lt;/code&gt; will only index a single link from each page, minimizing the amount of content being retrieved. This setting helps to limit the scope of the sync to just a few essential links, which is useful for a quick test ingestion.&lt;br&gt;
In actual deployment, you may select appropriate numbers for maximum links and throttling. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbehj1vvt568d0pgo6td6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbehj1vvt568d0pgo6td6.png" alt="Image description" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Sync run schedule set the Frequency to Run on demand from the pull down menu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8iowr8avz40bzes58n8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8iowr8avz40bzes58n8.png" alt="Image description" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once it’s been deployed successfully, you should see the ‘Active’ status from the Console. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Start conversation
&lt;/h3&gt;

&lt;p&gt;Now try to ask some questions relevant to the contents of the website:&lt;/p&gt;

&lt;p&gt;“What are some fun and unusual things to do in Yosemite?”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wme7930zukfdhfy23rm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wme7930zukfdhfy23rm.png" alt="Image description" width="800" height="647"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Benefits of Using a Web Crawler in Amazon Q Business:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Broader Information Base&lt;/strong&gt;: By crawling selected web sources, &lt;code&gt;Amazon Q Business&lt;/code&gt; can pull in valuable external information to answer questions more comprehensively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Up-to-Date Content&lt;/strong&gt;: The web crawler can be configured to re-scan sources regularly, keeping the content fresh and current for more accurate responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Retrieval&lt;/strong&gt;: The web crawler continuously gathers information without requiring manual input, providing a reliable and scalable way to expand the knowledge base &lt;code&gt;Amazon Q Business&lt;/code&gt; draws from.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.3.3 &lt;strong&gt;Amazon S3 connector&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this example, we ensure that an authenticated user interacts with the &lt;code&gt;Amazon Q Business&lt;/code&gt; application, receiving responses generated exclusively from documents the user is authorized to access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60cdx3drokar7frcm86z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60cdx3drokar7frcm86z.png" alt="Image description" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the S3 bucket with pre-setup buckets and documents. Each folder contain documents that are only accessible to certain groups of employees. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb72m0la0uzl0brkjzgq6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb72m0la0uzl0brkjzgq6.png" alt="Image description" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy the json url link of the whitepapers_acl, we will need it in a later step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjn42snfhgzncnt18f0a6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjn42snfhgzncnt18f0a6.png" alt="Image description" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name the data source ‘S3-Generative-AI-Assistant’ and select relevant IAM role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fud5oityuylzq1lqz11xc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fud5oityuylzq1lqz11xc.png" alt="Image description" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Sync scope, in the field Enter the data source location, enter the name of S3 data source and bucket name&lt;/li&gt;
&lt;li&gt;In Access control list configuration file location - optional, paste the S3 URI of
whitepapers_acl.json you copied in the previous step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqyv93jcuawvdp2ajuz7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqyv93jcuawvdp2ajuz7.png" alt="Image description" width="800" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Sync mode leave the default setting of Full sync, and for Sync run schedule select the Frequency as Run on demand from the pull down menu.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Configuring the synchronization settings when connecting Amazon Q Business to an Amazon S3 bucket using Access Control Lists (ACLs) for managing permissions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sync Mode - Full Sync&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In "Full Sync" mode, the system fetches and synchronizes the entire set of data from the specified S3 bucket. This ensures all the documents in the bucket are available for retrieval and processing. Leaving this as the default ensures that no data is missed during synchronization.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sync Run Schedule - Run on Demand&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choosing "Run on Demand" means the synchronization will only occur manually when triggered by the user. This setting is useful for cases where updates to the data source are infrequent or where the admin wants more control over when the sync process occurs, instead of scheduling it at regular intervals.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have pre-determined the following employee access with their roles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pat_candella - &lt;em&gt;SA (group of solutions architects)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;mateo_jackson - &lt;em&gt;DB_SME_SA (group of database subject matter expert solutions architects)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;john_doe - &lt;em&gt;ML_SME_SA (group of machine learning subject matter expert solutions architects)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;mary_major - &lt;em&gt;(does not belong to any of these groups)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;martha_rivera - &lt;em&gt;Admins (group of administrators)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Start conversation
&lt;/h3&gt;

&lt;p&gt;Now login as Mary_major (Note that all of these will need to be accessible by the user &lt;strong&gt;mary_major&lt;/strong&gt; who is not a member of any group)&lt;/p&gt;

&lt;p&gt;Ask a question: &lt;/p&gt;

&lt;p&gt;“How to develop a well architected serverless application on AWS?”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flf2im7wo1n8yqvx8wifq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flf2im7wo1n8yqvx8wifq.png" alt="Image description" width="705" height="814"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The answer is sourced from the documents &lt;em&gt;microservices-on-aws.pdf&lt;/em&gt;, &lt;em&gt;aws-overview.pdf&lt;/em&gt;, and &lt;em&gt;overview-aws-cloud-adoption-framework.pdf&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In the sample data, &lt;em&gt;microservices-on-aws.pdf&lt;/em&gt; is located in the &lt;em&gt;Best_Practices&lt;/em&gt; folder, while &lt;em&gt;aws-overview.pdf&lt;/em&gt; and &lt;em&gt;overview-aws-cloud-adoption-framework.pdf&lt;/em&gt; are in the &lt;em&gt;General&lt;/em&gt; folder.&lt;/p&gt;

&lt;p&gt;It is important to note that neither the &lt;em&gt;Best_Practices&lt;/em&gt; nor the &lt;em&gt;General&lt;/em&gt; folder has any ACLs defined in the ACL file configured for the data source. As a result, these folders are accessible to anyone, including the user &lt;em&gt;mary_major&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In another attempt, login as &lt;strong&gt;pat_candella&lt;/strong&gt;, and ask the same question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgf4iak7vlmvb00qrgaza.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgf4iak7vlmvb00qrgaza.png" alt="Image description" width="711" height="798"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that pat_candella is a member of the SA group, and in the ACL file, the Well_Architected folder is configured with an ACL allowing access to the SA group.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Bonus Content: Amazon Q Business Plugin
&lt;/h1&gt;

&lt;p&gt;Discover how to build a plugin that interprets user requests, populates dialogue windows, and completes tasks seamlessly within Amazon Q Business.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify the plugin URL by navigating to the plugin settings in &lt;code&gt;Amazon Q Business&lt;/code&gt;, where you can configure the endpoint URL that the plugin will use to process user requests and interact with the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpwn4ndjdhk9a73b1zfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpwn4ndjdhk9a73b1zfn.png" alt="Image description" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new custom Plugin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qnywmjixrhzyg0f6puk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qnywmjixrhzyg0f6puk.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The plugin will be an interactive tool to understand your leave balances, and for use to apply leaves.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm06y7k5jmkwzrugw4cda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm06y7k5jmkwzrugw4cda.png" alt="Image description" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide API Schema in YAML (with example code)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openapi: 3.0.0
info:
  title: Employee Management API
  description: API for managing employee leave balances using DynamoDB
  version: 1.0.0
servers:
  - url: https://61xuduba0d.execute-api.us-west-2.amazonaws.com/Prod
paths:
  /leaves:
    get:
      summary: Retrieve leave balance
      description: Retrieve the leave balance for the employee with a constant employee ID.
      operationId: getLeaveBalance
      responses:
        "200":
          description: A JSON object containing the employee's leave balance.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Balance:
                    type: string
                    description: The leave balance of the employee.
                example:
                  Balance: "10"
        "404":
          description: Employee not found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Error:
                    type: string
                    description: Error message indicating employee not found.
                example:
                  Error: Employee not found
        "500":
          description: Internal server error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Error:
                    type: string
                    description: Detailed error message.
                example:
                  Error: Internal server error
  /apply-leave:
    post:
      summary: Apply for leave
      description: Submit a leave request for the employee with a constant employee ID.
      operationId: applyForLeave
      requestBody:
        description: Details of the leave request.
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                from_date:
                  type: string
                  format: date
                  description: The start date of the leave.
                to_date:
                  type: string
                  format: date
                  description: The end date of the leave.
                time_off_type:
                  type: string
                  description: The type of time off.
                  enum:
                    - sick
                    - vacation
              required:
                - from_date
                - to_date
                - time_off_type
              example:
                from_date: "2024-07-01"
                to_date: "2024-07-10"
                time_off_type: "vacation"
      responses:
        '200':
          description: A JSON object indicating success and the updated leave balance.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Message:
                    type: string
                    description: Success message with the leave approval details.
                  new_balance:
                    type: number
                    description: The new leave balance after the leave is applied.
                example:
                  Message: "Success! Your leave from 2024-07-01 to 2024-07-10 is auto-approved. Your new balance is 5."
        '400':
          description: Bad request due to insufficient leave balance or invalid input.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Error:
                    type: string
                    description: Error message indicating the reason for failure.
              examples:
                InsufficientBalance:
                  value:
                    Error: "Insufficient leave balance"
                InvalidInput:
                  value:
                    Error: "Invalid input data"
        '404':
          description: Employee not found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Error:
                    type: string
                    description: Error message indicating employee not found.
                example:
                  Error: "Employee not found"
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  Error:
                    type: string
                    description: Detailed error message.
                example:
                  Error: "Internal server error"
components:
  schemas:
    LeaveRequest:
      type: object
      properties:
        from_date:
          type: string
          format: date
          description: The start date of the leave.
        to_date:
          type: string
          format: date
          description: The end date of the leave.
        time_off_type:
          type: string
          description: The type of time off.
          enum:
            - sick
            - vacation
      required:
        - from_date
        - to_date
        - time_off_type
      example:
        from_date: "2024-07-01"
        to_date: "2024-07-10"
        time_off_type: "vacation"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  YAML Code Explanation:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;API Metadata&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;openapi&lt;/strong&gt;: Specifies the version of OpenAPI used (3.0.0).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;info&lt;/strong&gt;: Contains basic information about the API, such as:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;title&lt;/strong&gt;: "Employee Management API"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description&lt;/strong&gt;: Describes that this API is for managing employee leave balances with DynamoDB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;version&lt;/strong&gt;: The version of the API (1.0.0).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Server Information&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;servers&lt;/strong&gt;: Specifies the base URL for the API endpoints:

&lt;ul&gt;
&lt;li&gt;The API is hosted at &lt;code&gt;https://61xuduba0d.execute-api.us-west-2.amazonaws.com/Prod&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;API Endpoints&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The API has two primary endpoints:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/leaves&lt;/code&gt; (GET)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;summary&lt;/strong&gt;: Retrieves the leave balance of an employee.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;operationId&lt;/strong&gt;: &lt;code&gt;getLeaveBalance&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;responses&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200&lt;/strong&gt;: Returns the employee's leave balance in JSON format. Example: &lt;code&gt;{"Balance": "10"}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404&lt;/strong&gt;: If the employee is not found, returns a message like &lt;code&gt;{"Error": "Employee not found"}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;500&lt;/strong&gt;: For internal server errors, returns a detailed error message.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/apply-leave&lt;/code&gt; (POST)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;summary&lt;/strong&gt;: Allows an employee to submit a leave request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;operationId&lt;/strong&gt;: &lt;code&gt;applyForLeave&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;requestBody&lt;/strong&gt;: The body of the request contains details about the leave, including:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;from_date&lt;/strong&gt;: Start date of the leave.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;to_date&lt;/strong&gt;: End date of the leave.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;time_off_type&lt;/strong&gt;: Type of leave (either &lt;code&gt;sick&lt;/code&gt; or &lt;code&gt;vacation&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;These fields are required.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;responses&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200&lt;/strong&gt;: Success message, and the new leave balance is returned.

&lt;ul&gt;
&lt;li&gt;Example: &lt;code&gt;{"Message": "Success! Your leave from 2024-07-01 to 2024-07-10 is auto-approved. Your new balance is 5.", "new_balance": 5}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;400&lt;/strong&gt;: Bad request (e.g., insufficient leave balance or invalid input). Example errors include &lt;code&gt;"Insufficient leave balance"&lt;/code&gt; or &lt;code&gt;"Invalid input data"&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;404&lt;/strong&gt;: If the employee is not found, returns an error like &lt;code&gt;{"Error": "Employee not found"}&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;500&lt;/strong&gt;: For internal errors, returns a general error message.&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Components&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;schemas&lt;/strong&gt;: Defines the &lt;code&gt;LeaveRequest&lt;/code&gt; schema, which is used in the &lt;code&gt;/apply-leave&lt;/code&gt; endpoint:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;from_date&lt;/strong&gt;: A string in date format specifying the start date of the leave.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;to_date&lt;/strong&gt;: A string in date format specifying the end date of the leave.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;time_off_type&lt;/strong&gt;: A string that can either be &lt;code&gt;sick&lt;/code&gt; or &lt;code&gt;vacation&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;This OpenAPI specification defines two operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;GET /leaves&lt;/strong&gt;: Retrieves an employee's leave balance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST /apply-leave&lt;/strong&gt;: Submits a leave request and updates the leave balance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The responses and request formats are structured in JSON, and various success and error responses are defined for each endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xrtk80tymaewp3qxr8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xrtk80tymaewp3qxr8p.png" alt="Image description" width="800" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Start conversation
&lt;/h3&gt;

&lt;p&gt;Click the three dots besides the chatbox, and select the EmployeeTimeOff Plugin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgxecu9u8o2d560uz0f2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgxecu9u8o2d560uz0f2.png" alt="Image description" width="800" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ask the question “How many leaves do I have?”. Note that the Plugin is included in the chatbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filro7wcepmzp2rnnhnm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filro7wcepmzp2rnnhnm7.png" alt="Image description" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Confirm the answer provided by Amazon Q Business Plugin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwszob8w4yuqv2muywtgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwszob8w4yuqv2muywtgh.png" alt="Image description" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now simply input your request in natural language. Amazon Q Business will populate the form with the detailed filled in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ejrok1bxdw518gd8iqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ejrok1bxdw518gd8iqy.png" alt="Image description" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Submit, and the request will be submitted to the corporate system. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F564uy8uahs0244ru65cv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F564uy8uahs0244ru65cv.png" alt="Image description" width="800" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Conclusion
&lt;/h1&gt;

&lt;p&gt;In this walkthrough, we have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create &lt;code&gt;Amazon Q Business&lt;/code&gt; applications.&lt;/li&gt;
&lt;li&gt;Ingest documents by uploading files, using web crawler data source connector and &lt;code&gt;Amazon S3&lt;/code&gt; data source connector.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Amazon Q Business&lt;/code&gt; application as a generative AI assistant using web experience.&lt;/li&gt;
&lt;li&gt;Deploy the &lt;code&gt;Amazon Q Business&lt;/code&gt; application web experience using AWS IAM Identity Center as identity provider.&lt;/li&gt;
&lt;li&gt;Use the deployed &lt;code&gt;Amazon Q Business&lt;/code&gt; application web experience as a generative AI assistant logged in as different users to experience how the responses are generated securely, based only on the content the logged in user has permissions to access.&lt;/li&gt;
&lt;li&gt;Created a plugin using APIs to extend the functionality of the application, allowing seamless interaction with external services and systems for enhanced performance. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Reference and further readings:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[1] Amazon Q Business. &lt;a href="https://aws.amazon.com/q/business/" rel="noopener noreferrer"&gt;https://aws.amazon.com/q/business/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] Amazon Q Business, now generally available, helps boost workforce productivity with generative AI. &lt;a href="https://aws.amazon.com/blogs/aws/amazon-q-business-now-generally-available-helps-boost-workforce-productivity-with-generative-ai/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/aws/amazon-q-business-now-generally-available-helps-boost-workforce-productivity-with-generative-ai&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>amazonqbusiness</category>
      <category>genai</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
