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
AdministratorAccessor 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) orus-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:
- Enable and configure foundation model access in Amazon Bedrock.
- Invoke an Amazon Bedrock foundation model using both the AWS CLI and the AWS Management Console.
- Adjust inference parameters (like Temperature) to alter model creativity.
- 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:
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".
# Check currently available foundation models in your region
aws bedrock list-foundation-models --query "modelSummaries[*].modelId" --output table▶Console alternative (Required for granting access)
- Log in to the AWS Management Console and search for Amazon Bedrock.
- In the left navigation pane, scroll down to Bedrock configurations and click Model access.
- Click the Manage model access button at the top right.
- Check the box next to Amazon Titan Text G1 - Lite (or similar available Titan Text model).
- Scroll to the bottom and click Save changes.
- 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.
# 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
- In the Amazon Bedrock console, under Playgrounds in the left menu, select Text.
- Click Select model, choose Amazon, and select Titan Text G1 - Lite.
- Type
Explain cloud computing in two sentences.in the prompt box. - 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.
# 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.jsonHere is a visual representation of how temperature impacts token selection:
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.
- Open the AWS Management Console in your browser.
- On the right side of the screen, click the Amazon Q icon (a colorful letter Q).
- In the chat interface, type the following prompt:
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:
-
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. -
Verify Bedrock Invocation: Run
cat response.json. Expected Output: A JSON string containing a"results"array with the generated text about cloud computing. -
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.
# Remove local output files generated during the lab
rm response.json creative_response.jsonTo cancel Amazon Q Developer Pro (if enabled):
- Navigate to the Amazon Q Developer console.
- Select Subscriptions and choose to downgrade to the free tier.
Troubleshooting
| Error Message | Likely Cause | Solution |
|---|---|---|
AccessDeniedException | IAM 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. |
ValidationException | The JSON payload in the --body parameter is malformed. | Check for missing quotes or brackets. Ensure you use --cli-binary-format raw-in-base64-out. |
ThrottlingException | Too many API requests made in a short period. | Wait a few seconds and retry the command. |
UnrecognizedClientException | AWS CLI is not configured correctly. | Run aws configure and provide your valid access keys and default region. |