Verify the AWS CLI is available
Runaws to confirm the CLI is installed. A minimal invocation without arguments returns usage help and an error about missing subcommands:
ec2 describe-instances returns JSON describing your EC2 instances (truncated here):
Bedrock runtime: invoke-model vs converse
Two primary Bedrock runtime subcommands are useful from the CLI:invoke-model— low-level call where you format the payload to match the model’s expected input.converse— higher-level, message-based interface that standardizes chat-style inputs and is better for multi-turn conversations.
Use
invoke-model when you need fine-grained control over exact tokenization, markers, or model-specific input formats. Use converse for portable, standardized messages and when building chat flows or multi-turn interactions.Files used in the demo
Listing the working directory shows two payload files and an output file:invoke-model example (low-level JSON payload)
invoke-payload.json contains a model-specific prompt and generation settings:
invoke-model. Use --model-id for the catalog name, --body fileb://... to supply the binary JSON payload, and --accept application/json to request JSON output written to output.json:
converse example (higher-level, message-based JSON)
converse-payload.json expresses the user message using the standardized message array:
converse subcommand and request plain text output. The CLI returns the assistant message plus additional metrics and usage lines:
converse includes METRICS and USAGE lines that are useful for logging, debugging, and cost monitoring.
Authentication and AWS CLI profiles
This guide shows examples using locally configured long-lived credentials. For production or shared environments, prefer temporary credentials using AWS SSO, IAM roles, or other secure methods.Avoid committing long-lived AWS access keys into source control or sharing them. Use temporary credentials (for example,
aws sso login, sts assume-role) or properly scoped IAM roles wherever possible.--profile my-new-profile in the AWS CLI command. This helps manage multiple credential sets, roles, or environments.
Summary
- You can access Amazon Bedrock runtime endpoints directly from any terminal with the AWS CLI.
- Choose
invoke-modelfor precise, model-specific inputs andconversefor standardized chat-style message flows and multi-turn interactions. - Both subcommands return useful metadata (metrics, usage, token counts) that help with logging and cost monitoring.
- Manage credentials carefully: prefer temporary credentials and profiles; pass
--profileto isolate credentials per task.
