Skip to main content
This lesson demonstrates how to access Amazon Bedrock from the command line and run inference using the AWS CLI. Examples show a Windows Subsystem for Linux (WSL) environment on Windows 11, but the same commands work in macOS and Linux terminals.

Verify the AWS CLI is available

Run aws to confirm the CLI is installed. A minimal invocation without arguments returns usage help and an error about missing subcommands:
A quick check that the CLI can call AWS APIs: 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.
Here is a quick comparison to help choose:

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:
Call the Bedrock runtime with 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:
Inspect the generated JSON result:

converse example (higher-level, message-based JSON)

converse-payload.json expresses the user message using the standardized message array:
Invoke the converse subcommand and request plain text output. The CLI returns the assistant message plus additional metrics and usage lines:
Note that 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.
List existing CLI profiles:
Create (or update) a named profile. You will be prompted for keys and defaults:
Verify the profile was added:
To use a specific profile when invoking Bedrock, include --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-model for precise, model-specific inputs and converse for 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 --profile to isolate credentials per task.
A "Results" slide showing four numbered dark-blue panels. Each panel lists a developer/operator capability: authenticate securely with the AWS CLI, access Amazon Bedrock from the terminal, invoke foundation models without the console, and quickly test prompts and model responses.
That concludes this lesson. A related short but important topic is inference profiles, which can affect how you interact with foundation models.

Watch Video