AWS CLI Beast Mode
Overview
Advanced AWS CLI patterns for speed, precision, and security-first automation. Covers JMESPath queries, bulk operations, waiters, cross-account access, and destructive operation safety.
When to Use
- Bulk operations across thousands of AWS resources
- Advanced JMESPath filtering and output transformation
- Automated scripts for AWS routines
- Multi-profile and multi-region management
- Security auditing and compliance checks
- CLI-driven infrastructure-as-code workflows
Instructions
Step 1: Categorize the Request
| Category |
Services |
Commands |
| Compute |
EC2, Lambda |
describe-instances, invoke, publish-version |
| Storage |
S3 |
sync, cp, mb, rb, presign |
| Database |
DynamoDB, RDS |
query, scan, batch-write-item |
| Networking |
VPC, Route53 |
describe-vpcs, describe-security-groups |
| Security |
IAM |
simulate-principal-policy, get-policy-version |
| Observability |
CloudWatch |
get-metric-statistics, filter-log-events |
Step 2: Apply Beast Mode Principles
- Dry-run first: Always validate with
--dryrun or --dry-run
- Query server-side: Use
--query with JMESPath to filter before transfer
- Batch intelligently: Paginate with
--max-results and parallelize with xargs
- Wait properly: Use built-in waiters or exponential backoff polling
- Switch contexts: Use
--profile and --region for multi-account operations
Step 3: Validate Destructive Operations
MANDATORY for any destructive operation:
# S3 sync with delete - MUST dry-run first
aws s3 sync s3://source/ s3://dest/ --delete --dryrun
# Review output, then remove --dryrun only if satisfied
# Bulk EC2 stop - validate targets first
aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=development" \
--query 'Reservations[].Instances[?State.Name==`running`].InstanceId' \
--output text
# Confirm list, then pipe to stop command
# IAM policy attachment - simulate first
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::123456789012:user/myuser \
--action-names s3:DeleteObject \
--resource-arns arn:aws:s3:::my-bucket/*
Step 4: Reference Detailed Guides
compute-mastery.md - EC2, Lambda, Spot Fleets, ASG
data-ops-beast.md - S3 multipart, DynamoDB batch, RDS snapshots
networking-security-hardened.md - VPC Flow Logs, IAM policies, security groups
automation-patterns.md - Shell aliases, JMESPath templates, CI/CD integration
Examples
Example 1: Bulk EC2 Stop
"Stop all development instances"
# 1. Dry-run: identify targets
aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=development" \
"Name=instance-state-name,Values=running" \
--query 'Reservations[].Instances[].InstanceId' \
--output text
# 2. Confirm IDs, then execute
aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=development" \
"Name=instance-state-name,Values=running" \
--query 'Reservations[].Instances[].InstanceId' \
--output text | xargs aws ec2 stop-instances --instance-ids
Example 2: S3 Migration with Encryption
"Migrate data between buckets with SSE"
# 1. Dry-run migration
aws s3 sync s3://source-bucket/ s3://dest-bucket/ \
--sse AES256 \
--storage-class GLACIER \
--exclude "*.tmp" \
--dryrun
# 2. Enable versioning on destination
aws s3api put-bucket-versioning \
--bucket dest-bucket \
--versioning-configuration Status=Enabled
# 3. Execute after review
aws s3 sync s3://source-bucket/ s3://dest-bucket/ \
--sse AES256 \
--storage-class GLACIER \
--exclude "*.tmp"
Example 3: IAM Security Audit
"Find overprivileged IAM users"
aws iam list-users --query 'Users[].UserName' --output text | \
while read user; do
echo "Checking $user..."
aws iam simulate-principal-policy \
--policy-source-arn "arn:aws:iam::123456789012:user/$user" \
--action-names DeleteItem,DeleteTable,DeleteFunction \
--resource-arns "*" \
--query 'EvaluationResults[?EvalDecision==`allowed`]'
done
Example 4: Multi-Region Lambda Deployment
"Deploy Lambda to all regions"
for region in us-east-1 us-west-2 eu-west-1; do
echo "Deploying to $region..."
aws lambda update-function-code \
--function-name my-function \
--zip-file fileb://function.zip \
--region $region \
--publish
aws lambda wait function-active \
--function-name my-function \
--region $region
done
Example 5: JMESPath Advanced Filtering
"Get running instances with specific tags as table"
aws ec2 describe-instances \
--query 'Reservations[].Instances[?State.Name==`running`].[InstanceId,Tags[?Key==`Name`].Value[0]|[0],PrivateIpAddress]' \
--output table
Best Practices
- Use
--output json for programmatic processing
- Filter with JMESPath server-side before transfer
- Implement retry logic with exponential backoff
- Use waiters instead of manual polling loops
- Tag all resources for cost allocation and automation
- Separate dev/staging/prod with AWS profiles
- Enable CloudTrail for audit compliance
- Validate IAM policies with simulate-principal-policy before attachment
- Use --dry-run on every state-modifying operation
- Enable MFA for security-sensitive operations
Constraints and Warnings
Rate Limiting
- AWS API throttling applies; use
--max-throttle and exponential backoff
- Check
aws service-quotas for current limits
Pagination
- Default page size is variable; use
--max-results for consistency
- Use
--no-paginate with jq for full dataset processing
Destructive Operations
- S3 sync --delete: Irreversibly removes files not in source
- EC2 terminate-instances: Cannot be undone; validate instance IDs first
- IAM detach/policy: May break existing access; simulate before applying
- RDS delete-db-instance: Snapshots do not protect all scenarios; verify retention
Security
- Never commit AWS credentials; use
aws configure or environment variables
- Rotate access keys regularly with
aws iam create-access-key
- Use least-privilege: simulate before granting permissions
1---
2name: aws-cli-beast
3description: Provides advanced AWS CLI patterns for managing EC2, Lambda, S3, DynamoDB, RDS, VPC, IAM, and CloudWatch. Generates bulk operation scripts, automates cross-service workflows, validates security configurations, and executes JMESPath queries for complex filtering. Triggers on "aws cli help", "aws command line", "aws scripting", "aws automation", "aws batch operations", "aws bulk operations", "aws cli pagination", "aws multi-region", "aws profiles", "aws cli troubleshooting".
4allowed-tools: Read, Write, Bash
5metadata:
6 source: https://skillmd.com/skills/aibot88/aws-cli-beast
7---
8
9# AWS CLI Beast Mode
10
11## Overview
12
13Advanced AWS CLI patterns for speed, precision, and security-first automation. Covers JMESPath queries, bulk operations, waiters, cross-account access, and destructive operation safety.
14
15## When to Use
16
17- Bulk operations across thousands of AWS resources
18- Advanced JMESPath filtering and output transformation
19- Automated scripts for AWS routines
20- Multi-profile and multi-region management
21- Security auditing and compliance checks
22- CLI-driven infrastructure-as-code workflows
23
24## Instructions
25
26### Step 1: Categorize the Request
27
28| Category | Services | Commands |
29|----------|----------|----------|
30| Compute | EC2, Lambda | describe-instances, invoke, publish-version |
31| Storage | S3 | sync, cp, mb, rb, presign |
32| Database | DynamoDB, RDS | query, scan, batch-write-item |
33| Networking | VPC, Route53 | describe-vpcs, describe-security-groups |
34| Security | IAM | simulate-principal-policy, get-policy-version |
35| Observability | CloudWatch | get-metric-statistics, filter-log-events |
36
37### Step 2: Apply Beast Mode Principles
38
391. **Dry-run first**: Always validate with `--dryrun` or `--dry-run`
402. **Query server-side**: Use `--query` with JMESPath to filter before transfer
413. **Batch intelligently**: Paginate with `--max-results` and parallelize with xargs
424. **Wait properly**: Use built-in waiters or exponential backoff polling
435. **Switch contexts**: Use `--profile` and `--region` for multi-account operations
44
45### Step 3: Validate Destructive Operations
46
47**MANDATORY** for any destructive operation:
48
49```bash
50# S3 sync with delete - MUST dry-run first
51aws s3 sync s3://source/ s3://dest/ --delete --dryrun
52# Review output, then remove --dryrun only if satisfied
53
54# Bulk EC2 stop - validate targets first
55aws ec2 describe-instances \
56 --filters "Name=tag:Environment,Values=development" \
57 --query 'Reservations[].Instances[?State.Name==`running`].InstanceId' \
58 --output text
59# Confirm list, then pipe to stop command
60
61# IAM policy attachment - simulate first
62aws iam simulate-principal-policy \
63 --policy-source-arn arn:aws:iam::123456789012:user/myuser \
64 --action-names s3:DeleteObject \
65 --resource-arns arn:aws:s3:::my-bucket/*
66```
67
68### Step 4: Reference Detailed Guides
69
70- `compute-mastery.md` - EC2, Lambda, Spot Fleets, ASG
71- `data-ops-beast.md` - S3 multipart, DynamoDB batch, RDS snapshots
72- `networking-security-hardened.md` - VPC Flow Logs, IAM policies, security groups
73- `automation-patterns.md` - Shell aliases, JMESPath templates, CI/CD integration
74
75## Examples
76
77### Example 1: Bulk EC2 Stop
78
79**"Stop all development instances"**
80
81```bash
82# 1. Dry-run: identify targets
83aws ec2 describe-instances \
84 --filters "Name=tag:Environment,Values=development" \
85 "Name=instance-state-name,Values=running" \
86 --query 'Reservations[].Instances[].InstanceId' \
87 --output text
88
89# 2. Confirm IDs, then execute
90aws ec2 describe-instances \
91 --filters "Name=tag:Environment,Values=development" \
92 "Name=instance-state-name,Values=running" \
93 --query 'Reservations[].Instances[].InstanceId' \
94 --output text | xargs aws ec2 stop-instances --instance-ids
95```
96
97### Example 2: S3 Migration with Encryption
98
99**"Migrate data between buckets with SSE"**
100
101```bash
102# 1. Dry-run migration
103aws s3 sync s3://source-bucket/ s3://dest-bucket/ \
104 --sse AES256 \
105 --storage-class GLACIER \
106 --exclude "*.tmp" \
107 --dryrun
108
109# 2. Enable versioning on destination
110aws s3api put-bucket-versioning \
111 --bucket dest-bucket \
112 --versioning-configuration Status=Enabled
113
114# 3. Execute after review
115aws s3 sync s3://source-bucket/ s3://dest-bucket/ \
116 --sse AES256 \
117 --storage-class GLACIER \
118 --exclude "*.tmp"
119```
120
121### Example 3: IAM Security Audit
122
123**"Find overprivileged IAM users"**
124
125```bash
126aws iam list-users --query 'Users[].UserName' --output text | \
127while read user; do
128 echo "Checking $user..."
129 aws iam simulate-principal-policy \
130 --policy-source-arn "arn:aws:iam::123456789012:user/$user" \
131 --action-names DeleteItem,DeleteTable,DeleteFunction \
132 --resource-arns "*" \
133 --query 'EvaluationResults[?EvalDecision==`allowed`]'
134done
135```
136
137### Example 4: Multi-Region Lambda Deployment
138
139**"Deploy Lambda to all regions"**
140
141```bash
142for region in us-east-1 us-west-2 eu-west-1; do
143 echo "Deploying to $region..."
144 aws lambda update-function-code \
145 --function-name my-function \
146 --zip-file fileb://function.zip \
147 --region $region \
148 --publish
149 aws lambda wait function-active \
150 --function-name my-function \
151 --region $region
152done
153```
154
155### Example 5: JMESPath Advanced Filtering
156
157**"Get running instances with specific tags as table"**
158
159```bash
160aws ec2 describe-instances \
161 --query 'Reservations[].Instances[?State.Name==`running`].[InstanceId,Tags[?Key==`Name`].Value[0]|[0],PrivateIpAddress]' \
162 --output table
163```
164
165## Best Practices
166
1671. Use `--output json` for programmatic processing
1682. Filter with JMESPath server-side before transfer
1693. Implement retry logic with exponential backoff
1704. Use waiters instead of manual polling loops
1715. Tag all resources for cost allocation and automation
1726. Separate dev/staging/prod with AWS profiles
1737. Enable CloudTrail for audit compliance
1748. Validate IAM policies with simulate-principal-policy before attachment
1759. Use --dry-run on every state-modifying operation
17610. Enable MFA for security-sensitive operations
177
178## Constraints and Warnings
179
180### Rate Limiting
181- AWS API throttling applies; use `--max-throttle` and exponential backoff
182- Check `aws service-quotas` for current limits
183
184### Pagination
185- Default page size is variable; use `--max-results` for consistency
186- Use `--no-paginate` with jq for full dataset processing
187
188### Destructive Operations
189- **S3 sync --delete**: Irreversibly removes files not in source
190- **EC2 terminate-instances**: Cannot be undone; validate instance IDs first
191- **IAM detach/policy**: May break existing access; simulate before applying
192- **RDS delete-db-instance**: Snapshots do not protect all scenarios; verify retention
193
194### Security
195- Never commit AWS credentials; use `aws configure` or environment variables
196- Rotate access keys regularly with `aws iam create-access-key`
197- Use least-privilege: simulate before granting permissions