This section guides you through trying out some common operations in Amazon Bedrock using the AWS CLI to test that your permissions and authentication are set up properly. Before you run the following examples, you should check that you have fulfilled the following prerequisites:
Prerequisites
-
You have an AWS account and a user or role with authentication set up and the necessary permissions for Amazon Bedrock. Otherwise, follow the steps at Getting started with the API.
-
You've requested access to the Amazon Titan Text G1 - Express model. Otherwise, follow the steps at Request access to an Amazon Bedrock foundation model.
-
You've installed and set up authentication for the AWS CLI. To install the CLI, follow the steps at Install or update to the latest version of the AWS CLI. Verify that you've set up your credentials to use the CLI by following the steps at Get credentials to grant programmatic access.
Test that your permissions are set up properly for Amazon Bedrock, using a user or role that you set up with the proper permissions.
Topics
List the foundation models that Amazon Bedrock has to offer
The following example runs the ListFoundationModels operation using an Amazon Bedrock endpoint. ListFoundationModels
lists the foundation models (FMs) that are available in Amazon Bedrock in your region. In a terminal, run the following command:
aws bedrock list-foundation-models --region us-east-1
If the command is successful, the response returns a list of foundation models that are available in Amazon Bedrock.
Submit a text prompt to a model and generate a text response with InvokeModel
The following example runs the InvokeModel operation using an Amazon Bedrock runtime endpoint. InvokeModel
lets you submit a prompt to generate a model response. In a terminal, run the following command:
aws bedrock-runtime invoke-model \
--model-id amazon.titan-text-express-v1 \
--body '{"inputText": "Describe the purpose of a \"hello world\" program in one line.", "textGenerationConfig" : {"maxTokenCount": 512, "temperature": 0.5, "topP": 0.9}}' \
--cli-binary-format raw-in-base64-out \
invoke-model-output-text.txt
If the command is successful, the response generated by the model is written to the invoke-model-output-text.txt
file. The text response is returned in the outputText
field, alongside accompanying information.
Submit a text prompt to a model and generate a text response with Converse
The following example runs the Converse operation using an Amazon Bedrock runtime endpoint. Converse
lets you submit a prompt to generate a model response. We recommend using Converse
operation over InvokeModel
when supported, because it unifies the inference request across Amazon Bedrock models and simplifies the management of multi-turn conversations. In a terminal, run the following command:
aws bedrock-runtime converse \
--model-id amazon.titan-text-express-v1 \
--messages '[{"role": "user", "content": [{"text": "Describe the purpose of a \"hello world\" program in one line."}]}]' \
--inference-config '{"maxTokens": 512, "temperature": 0.5, "topP": 0.9}'
If the command is successful, the response generated by the model is returned in the text
field, alongside accompanying information.