Hands-On Lab894 words

Hands-On Lab: Building with Amazon Bedrock and Amazon Q

Amazon Bedrock and Amazon Q

Hands-On Lab: Building with Amazon Bedrock and Amazon Q

Welcome to this guided hands-on lab! In this session, you will explore AWS's primary generative AI platforms. You will invoke foundation models using Amazon Bedrock, experiment with inference parameters, and interact with Amazon Q Developer to accelerate your cloud workflows.


Prerequisites

Before starting this lab, ensure you have the following:

  • AWS Account: Access to an AWS account with AdministratorAccess or sufficient IAM permissions to use Amazon Bedrock and Amazon Q.
  • CLI Tools: The AWS CLI installed and configured (aws configure) with your access keys.
  • Region Selection: Set your default region to us-east-1 (N. Virginia) or us-west-2 (Oregon), as these regions have the broadest Amazon Bedrock model availability.
  • Prior Knowledge: Basic familiarity with navigating the AWS Management Console and executing terminal commands.

Learning Objectives

By completing this lab, you will be able to:

  1. Enable and configure foundation model access in Amazon Bedrock.
  2. Invoke an Amazon Bedrock foundation model using both the AWS CLI and the AWS Management Console.
  3. Adjust inference parameters (like Temperature) to alter model creativity.
  4. Utilize Amazon Q Developer to ask AWS-specific architectural questions and generate code.

Architecture Overview

The following diagram illustrates the two distinct workflows you will execute in this lab:

Loading Diagram...

Step-by-Step Instructions

Step 1: Request Model Access in Amazon Bedrock

Before you can use any foundation model in Amazon Bedrock, you must explicitly request access to it. This is a one-time setup step per region.

📸 Screenshot: The "Model access" page in the Amazon Bedrock console, showing "Manage model access".

bash
# Check currently available foundation models in your region aws bedrock list-foundation-models --query "modelSummaries[*].modelId" --output table
Console alternative (Required for granting access)
  1. Log in to the AWS Management Console and search for Amazon Bedrock.
  2. In the left navigation pane, scroll down to Bedrock configurations and click Model access.
  3. Click the Manage model access button at the top right.
  4. Check the box next to Amazon Titan Text G1 - Lite (or similar available Titan Text model).
  5. Scroll to the bottom and click Save changes.
  6. Wait for the Access status to change to Access granted.

[!TIP] Model access is granted almost instantly for Amazon's own models (like Titan), but third-party models (like Anthropic Claude) may require submitting a use-case details form.

Step 2: Invoke a Model Using Amazon Bedrock

Now that you have access, we will send a prompt to the Amazon Titan model using the AWS CLI.

📸 Screenshot: Terminal window showing a successful JSON response from the Bedrock API.

bash
# Invoke the Titan Text Lite model aws bedrock-runtime invoke-model \ --model-id amazon.titan-text-lite-v1 \ --body '{"inputText": "Explain cloud computing in two sentences.", "textGenerationConfig": {"temperature": 0.0}}' \ --cli-binary-format raw-in-base64-out \ --accept application/json \ --content-type application/json \ response.json # View the output cat response.json
Console alternative
  1. In the Amazon Bedrock console, under Playgrounds in the left menu, select Text.
  2. Click Select model, choose Amazon, and select Titan Text G1 - Lite.
  3. Type Explain cloud computing in two sentences. in the prompt box.
  4. Click Run to generate the response.

Step 3: Experiment with Temperature Settings

In Amazon Bedrock, adjusting the temperature affects the randomness of the model's responses. A temperature of 0.0 makes responses more deterministic, while higher values (up to 1.0) increase creativity and randomness.

bash
# Invoke the model with a higher temperature for a more creative response aws bedrock-runtime invoke-model \ --model-id amazon.titan-text-lite-v1 \ --body '{"inputText": "Write a creative haiku about cloud computing.", "textGenerationConfig": {"temperature": 0.9}}' \ --cli-binary-format raw-in-base64-out \ --accept application/json \ --content-type application/json \ creative_response.json # View the creative output cat creative_response.json

Here is a visual representation of how temperature impacts token selection:

Loading Diagram...

Step 4: Interact with Amazon Q Developer

Amazon Q Developer is tightly integrated into the AWS Console to help you understand services, troubleshoot errors, and write code.

📸 Screenshot: The Amazon Q chat panel docked on the right side of the AWS Management Console.

  1. Open the AWS Management Console in your browser.
  2. On the right side of the screen, click the Amazon Q icon (a colorful letter Q).
  3. In the chat interface, type the following prompt:
text
What is Amazon EC2, and how does it work? Please list all my running EC2 instances in the us-east-1 region.

[!NOTE] Amazon Q can inspect your active AWS environment (if permissions allow) to answer specific questions about your running resources and costs.


Checkpoints

After completing the steps, verify your progress:

  1. Verify Bedrock CLI Access: Run aws bedrock list-foundation-models | grep amazon.titan-text-lite-v1. Expected Output: The console should return details of the Titan Text Lite model.

  2. Verify Bedrock Invocation: Run cat response.json. Expected Output: A JSON string containing a "results" array with the generated text about cloud computing.

  3. Verify Amazon Q Interaction: Expected Output: The Amazon Q side panel should provide an explanation of EC2 and a list/summary of your running instances.


Clean-Up / Teardown

While Amazon Bedrock charges on a pay-per-request basis (meaning no resources are actively left running), it is best practice to clean up local files. If you signed up for the Amazon Q Developer Pro tier ($19/month), remember to downgrade if you do not wish to be billed.

[!WARNING] Remember to run the teardown commands to avoid clutter and potential ongoing charges if premium subscriptions were activated.

bash
# Remove local output files generated during the lab rm response.json creative_response.json

To cancel Amazon Q Developer Pro (if enabled):

  1. Navigate to the Amazon Q Developer console.
  2. Select Subscriptions and choose to downgrade to the free tier.

Troubleshooting

Error MessageLikely CauseSolution
AccessDeniedExceptionIAM user lacks permissions, or Model Access was not granted in the Bedrock console.Complete Step 1 to request Model Access. Ensure your IAM user has bedrock:InvokeModel permissions.
ValidationExceptionThe JSON payload in the --body parameter is malformed.Check for missing quotes or brackets. Ensure you use --cli-binary-format raw-in-base64-out.
ThrottlingExceptionToo many API requests made in a short period.Wait a few seconds and retry the command.
UnrecognizedClientExceptionAWS CLI is not configured correctly.Run aws configure and provide your valid access keys and default region.

Ready to study AWS Certified AI Practitioner (AIF-C01)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free