Skip to content

Cloud CLI: AWS

AWS commands from the Cloud CLI folder.

Index
12 items

AWS: Tail a CloudWatch log group

Safe

Stream CloudWatch Logs like tail -f. Add --filter-pattern "ERROR" to narrow.

aws logs tail <log-group> --follow --since 15m --region <region>
What each part does
  1. aws logs tailprint log events from a CloudWatch log group
  2. <log-group>the group name, e.g. /aws/lambda/orders-api
  3. --followkeep streaming new events (like tail -f)
  4. --since 15mstart 15 minutes back (s, m, h, d, w)
  5. --region <region>region of the log group, overrides the profile default
Example
$ aws logs tail /aws/lambda/orders-api --follow --since 15m --region eu-west-1

Also known as: cloudwatch logs · aws logs tail · lambda logs

AWS: Check which identity you are using

Safe

Account, ARN and user/role the CLI is authenticated as.

aws sts get-caller-identity
What each part does
  1. aws stsSecurity Token Service commands
  2. get-caller-identityprint the account ID, user/role ARN and user ID of the current credentials; needs no permissions

Also known as: whoami aws · AccessDenied · ExpiredToken

AWS: Log in with an SSO profile

Safe

Opens the browser for IAM Identity Center login and caches the token.

aws sso login --profile <profile>
What each part does
  1. aws sso loginopen the browser to sign in via IAM Identity Center and cache a token
  2. --profile <profile>the profile in ~/.aws/config that holds sso_start_url / sso_session

Also known as: aws sso · The SSO session associated with this profile has expired

AWS: Update kubeconfig for an EKS cluster

Safe

Adds/refreshes the EKS cluster context in ~/.kube/config.

aws eks update-kubeconfig --name <cluster> --region <region> --alias <alias>
What each part does
  1. aws eks update-kubeconfigadd or update the cluster entry in ~/.kube/config and make it current
  2. --name <cluster>the EKS cluster name
  3. --region <region>region the cluster runs in
  4. --alias <alias>short context name instead of the long cluster ARN

Also known as: eks kubeconfig · You must be logged in to the server (Unauthorized)

AWS: Start an SSM session on an instance

Safe

Shell on an EC2 instance without SSH keys or open port 22.

aws ssm start-session --target <instance-id>
What each part does
  1. aws ssm start-sessionopen a shell on an instance through Systems Manager (no SSH, no open port)
  2. --target <instance-id>the instance, e.g. i-0abc123; needs the SSM agent + Session Manager plugin

Also known as: session manager · ssm shell · ssh alternative

AWS: Read a Secrets Manager secret

Caution

Prints the secret value. Mind your terminal history and screen sharing.

aws secretsmanager get-secret-value --secret-id <secret-name> --query SecretString --output text
What each part does
  1. aws secretsmanager get-secret-valuefetch the current version of a secret
  2. --secret-id <secret-name>secret name or full ARN
  3. --query SecretStringJMESPath: keep only the secret payload, drop the metadata
  4. --output textprint it raw, without JSON quotes

Also known as: secrets manager · get secret

AWS: Show ECR scan findings for an image

Safe

Vulnerability counts per severity for an image in ECR. Drop --query to see each finding.

aws ecr describe-image-scan-findings --repository-name <repo> --image-id imageTag=<tag> --query 'imageScanFindings.findingSeverityCounts'
What each part does
  1. describe-image-scan-findingsresults of the last ECR / Inspector scan
  2. --repository-name <repo>ECR repository
  3. --image-id imageTag=<tag>which image
  4. --query ...only the CRITICAL/HIGH/... counts
  • #aws
  • #patching
  • #vulnerabilities

Also known as: ecr scan results · ecr vulnerabilities · inspector findings

AWS: Rescan an image in ECR

Safe

Re-run a basic ECR scan after pushing a patched image. (Enhanced / Inspector scanning rescans on its own.)

aws ecr start-image-scan --repository-name <repo> --image-id imageTag=<tag>
What each part does
  1. start-image-scanstart a basic scan
  2. --repository-name <repo>ECR repository
  3. --image-id imageTag=<tag>which image
  • #aws
  • #patching
  • #vulnerabilities

Also known as: ecr rescan · ecr scan image

AWS: Get the latest ECS-optimized AMI ID

Safe

ECS hosts (kernel, docker, containerd, nvidia toolkit) are patched by rolling to the newest AMI.

aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id --query 'Parameters[0].Value' --output text
What each part does
  1. ssm get-parametersread a public AWS parameter
  2. /aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_idlatest AL2023 ECS AMI (…/amazon-linux-2023/gpu/… for GPU hosts)
  3. --query 'Parameters[0].Value' --output textprint only the AMI ID

My note Put the ID in the launch template, then refresh the Auto Scaling group: aws autoscaling start-instance-refresh --auto-scaling-group-name <asg>

  • #aws
  • #patching
  • #kernel

Also known as: ecs ami · latest ami · ecs optimized ami · patch ecs host

AWS: Scan instances for missing patches with SSM

Safe

Reports missing patches without installing anything. Works on many instances at once (Key=tag:<name>,Values=<value>).

aws ssm send-command --document-name AWS-RunPatchBaseline --targets Key=InstanceIds,Values=<instance-id> --parameters Operation=Scan
What each part does
  1. send-command --document-name AWS-RunPatchBaselinerun the AWS patching document
  2. --targets Key=InstanceIds,Values=<instance-id>which instances (comma-separated, or use tags)
  3. Operation=Scanreport only
  • #aws
  • #patching

Also known as: patch manager scan · ssm patch scan · missing patches

AWS: Install patches with SSM and reboot if needed

Caution

Patches the instances from the patch baseline and reboots them only if a patch requires it.

aws ssm send-command --document-name AWS-RunPatchBaseline --targets Key=InstanceIds,Values=<instance-id> --parameters Operation=Install,RebootOption=RebootIfNeeded
What each part does
  1. AWS-RunPatchBaselineAWS patching document (Linux and Windows)
  2. Operation=Installinstall missing patches
  3. RebootOption=RebootIfNeededreboot only when needed (NoReboot to skip)
  • #aws
  • #patching
  • #kernel

Also known as: patch manager install · ssm patch · patch fleet · patch windows

AWS: Check the patch state of an instance

Safe

Installed, missing and failed patch counts, plus when the last scan or install ran.

aws ssm describe-instance-patch-states --instance-ids <instance-id>
What each part does
  1. describe-instance-patch-statespatch compliance summary
  2. --instance-ids <instance-id>one or more instances
  • #aws
  • #patching

Also known as: patch compliance · patch status · missing patch count

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…