Mastering AWS CLI is a Game-Changer

Ever faced a crisis where the AWS Console just won’t cut it? I once had to quickly download 50GB of critical S3 logs during an outage—the web UI kept timing out. The AWS CLI saved me with a single sync command. That’s the power of the command line: automation, speed, and reliability when you need it most. In this post, I’ll share essential CLI commands like downloading S3 buckets and disabling IAM users—the same tools that rescued me (and can save you too).

Essential AWS CLI Commands for S3 and IAM Management

AWS Command Line Interface (CLI) is a powerful tool that allows you to interact with AWS services directly from your terminal. In this post, I’ll cover some essential commands for working with S3 buckets and IAM user management.

Downloading Files from an S3 Bucket

Download a Single File

aws s3 cp s3://your-bucket-name/path/to/file.txt ./local-directory/

Download All Files from a Bucket

aws s3 sync s3://your-bucket-name ./local-directory/

Download Files with Specific Prefix

aws s3 cp s3://your-bucket-name/path/to/prefix/ . --recursive --exclude "*" --include "*.jpg"

Download with Exclusions

aws s3 sync s3://your-bucket-name ./local-directory/ --exclude "*.log" --exclude "temp/*"

Managing IAM Users

Disable an IAM User

aws iam update-login-profile --user-name USERNAME --no-password-enabled

Or to completely prevent access:

aws iam attach-user-policy --user-name USERNAME --policy-arn arn:aws:iam::aws:policy/AWSDenyAll

List All IAM Users

aws iam list-users

Get User Information

aws iam get-user --user-name USERNAME

List User’s Access Keys

aws iam list-access-keys --user-name USERNAME

Deactivate Access Key

aws iam update-access-key --user-name USERNAME --access-key-id KEYID --status Inactive

Delete Access Key

aws iam delete-access-key --user-name USERNAME --access-key-id KEYID

Tips for Secure AWS CLI Usage

  1. Use IAM roles instead of long-term access keys when possible
  2. Rotate credentials regularly
  3. Set up MFA for sensitive operations
  4. Limit permissions following the principle of least privilege
  5. Use AWS CLI profiles to manage multiple accounts securely

Remember to always review AWS CLI commands before executing them, especially those that modify or delete resources. The AWS CLI is a powerful tool that can make your cloud operations more efficient, but with great power comes great responsibility!

Leave a Reply

Your email address will not be published. Required fields are marked *