Skip to content
CLI tool · Cloud & deploy

AWS CLI for AI agents

The AWS CLI for coding agents: check identity, list S3, tail CloudWatch logs, and dry-run syncs, with read-only IAM and pager tips for agents.

awsby Amazon Web ServicesOfficial MCP option
What it is

What AWS CLI does for an agent

The AWS Command Line Interface is Amazon's official tool for every AWS service API. Version 2 is the current major version and ships as a self-contained installer.

Agents get the most from it with structured output (--output json) and JMESPath filters (--query), and the least risk from a read-only IAM role or SSO permission set.

Official site: aws.amazon.com/cli

Install

Install AWS CLI

The install commands from the official docs. Check it worked with aws --version.

Linux x86_64 (official installer)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install
macOS (official package)
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" && sudo installer -pkg AWSCLIV2.pkg -target /
Auth

Signing in AWS CLI for an agent

Prefer IAM Identity Center (SSO) profiles that a human signs in to, with short-lived credentials. In CI, use role-based credentials; the standard environment variables are read by every AWS SDK and the CLI.

Check the sign-in (read-only)
aws sts get-caller-identity
Configure an SSO profile (human)
aws configure sso
Refresh an SSO session (human)
aws sso login --profile my-profile

Environment variables: AWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN. Set them in the agent's environment; never paste values into prompts or commit them.

Common agent tasks

What agents use AWS CLI for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Check which account and role are active

    aws
    aws sts get-caller-identity
  2. List objects under an S3 prefix

    aws
    aws s3 ls s3://my-bucket/reports/
  3. Tail a Lambda function's logs

    aws
    aws logs tail /aws/lambda/my-function --since 1h
  4. Preview an S3 sync

    aws
    aws s3 sync ./dist s3://my-bucket --dryrun

    Prints what would be uploaded or deleted without doing it.

  5. List running EC2 instance IDs

    aws
    aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].InstanceId" --output text
Safety

Safety rules for agents

Safe to run without asking

  • aws sts get-caller-identity
  • aws s3 ls
  • aws logs tail
  • aws <service> describe-* / list-* / get-*

Ask a human first

  • aws s3 sync / cp / rm (without --dryrun)
  • aws s3 rm --recursive
  • aws <service> create-* / update-* / put-* / delete-*
  • aws ec2 terminate-instances
  • aws cloudformation deploy
  • Run under a read-only role or permission set; ask a human to switch roles for any change.
  • Check aws sts get-caller-identity before every session so the agent knows which account it is in.
  • Set AWS_PAGER="" (or pass --no-cli-pager) so output is never piped into an interactive pager that hangs the agent.
  • Use --dryrun on s3 commands and --dry-run on EC2 API calls before any real change.
Agent instructions

AGENTS.md or CLAUDE.md snippet

Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.

AGENTS.md
## AWS CLI (aws)

Use `aws` for reading AWS resources, logs, and S3 objects, and preparing changes for review.

- Check it is installed with `aws --version`. If it is missing, ask before installing it.
- Auth: a human signs aws in. Check with `aws sts get-caller-identity`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens (AWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN).
- Run without asking (read-only): `aws sts get-caller-identity`, `aws s3 ls`, `aws logs tail`, `aws <service> describe-* / list-* / get-*`.
- Ask a human first (changes or deletes things): `aws s3 sync / cp / rm (without --dryrun)`, `aws s3 rm --recursive`, `aws <service> create-* / update-* / put-* / delete-*`, `aws ec2 terminate-instances`, `aws cloudformation deploy`.
- Run under a read-only role or permission set; ask a human to switch roles for any change.
- Check aws sts get-caller-identity before every session so the agent knows which account it is in.
- Set AWS_PAGER="" (or pass --no-cli-pager) so output is never piped into an interactive pager that hangs the agent.
- Use --dryrun on s3 commands and --dry-run on EC2 API calls before any real change.
- Prefer JSON output where the command supports it, and keep output short.
CLI or MCP server?

AWS CLI or an MCP server?

An official MCP option exists. AWS Labs publishes a collection of official open-source MCP servers for AWS documentation, pricing, and individual services. Use them when you want narrower, tool-shaped access; the CLI covers every API with one binary.

Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.

Same category
All Cloud & deploy tools
FAQ

AWS CLI questions

How do I install AWS CLI?

Linux x86_64 (official installer): curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install. Other official options: macOS (official package). Check the install with aws --version, and see the Amazon Web Services docs for other platforms.

How does an AI agent authenticate AWS CLI?

Prefer IAM Identity Center (SSO) profiles that a human signs in to, with short-lived credentials. In CI, use role-based credentials; the standard environment variables are read by every AWS SDK and the CLI. The agent can check the sign-in with aws sts get-caller-identity and should stop and ask if it fails.

Which AWS CLI commands are safe for an agent to run?

Commands that only read state are safe to run without asking: aws sts get-caller-identity; aws s3 ls; aws logs tail; aws <service> describe-* / list-* / get-*. Ask a human before anything that changes or deletes something: aws s3 sync / cp / rm (without --dryrun); aws s3 rm --recursive; aws <service> create-* / update-* / put-* / delete-*; aws ec2 terminate-instances; aws cloudformation deploy.

Is there an MCP server for AWS CLI?

AWS Labs publishes a collection of official open-source MCP servers for AWS documentation, pricing, and individual services. Use them when you want narrower, tool-shaped access; the CLI covers every API with one binary.