Skip to content

Commands: Cloud CLI

AWS, Azure and GCP CLI commands.

Index
  • #aws
  • #azure
  • #gcp
  • #cloud
Updated

Also:aws cli · az cli · gcloud · cloud cli

21 items

AWS12

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

Azure4

Azure: Log in and select a subscription

Safe

Interactive login, then pin the subscription for following commands.

az login && az account set --subscription "<subscription>"
What each part does
  1. az loginsign in via the browser (or device code)
  2. &&run the next command only if login succeeded
  3. az account setchange the active subscription for later az commands
  4. --subscription "<subscription>"subscription name or ID

Also known as: az login · azure subscription

Azure: Get AKS cluster credentials

Safe

Merge the AKS cluster into ~/.kube/config.

az aks get-credentials -g <resource-group> -n <cluster>
What each part does
  1. az aks get-credentialsmerge the AKS cluster into ~/.kube/config and switch to it
  2. -g <resource-group>resource group that holds the cluster
  3. -n <cluster>the cluster name

Also known as: aks kubeconfig · az aks

Azure: Stream App Service logs

Safe

Live application and web server logs from an App Service.

az webapp log tail -g <resource-group> -n <app>
What each part does
  1. az webapp log tailstream live logs from an App Service app
  2. -g <resource-group>resource group of the app
  3. -n <app>the web app name; app logging must be enabled (az webapp log config)

Also known as: webapp logs · app service logs

Azure: Read a Key Vault secret

Caution

Prints a secret's current value.

az keyvault secret show --vault-name <vault> -n <secret-name> --query value -o tsv
What each part does
  1. az keyvault secret showread the current version of a Key Vault secret
  2. --vault-name <vault>the Key Vault name
  3. -n <secret-name>the secret name
  4. --query valueJMESPath: keep only the secret value
  5. -o tsvplain text output without JSON quotes

Also known as: key vault · keyvault

GCP5

GCP: Log in and set the project

Safe

Authenticate the CLI and set the default project.

gcloud auth login && gcloud config set project <project-id>
What each part does
  1. gcloud auth loginsign in via the browser
  2. &&continue only if login succeeded
  3. gcloud config set project <project-id>default project for later gcloud commands

Also known as: gcloud login · gcloud project

GCP: Get GKE cluster credentials

Safe

Adds the GKE cluster context to ~/.kube/config.

gcloud container clusters get-credentials <cluster> --region <region>
What each part does
  1. gcloud container clusters get-credentials <cluster>write the GKE cluster into ~/.kube/config and switch to it
  2. --region <region>for regional clusters; use --zone for zonal ones

Also known as: gke kubeconfig

GCP: Read recent error logs

Safe

Errors from Cloud Logging in the last hour across the project.

gcloud logging read 'severity>=ERROR' --freshness=1h --limit=50
What each part does
  1. gcloud logging readquery Cloud Logging
  2. 'severity>=ERROR'filter: ERROR, CRITICAL, ALERT, EMERGENCY
  3. --freshness=1honly entries from the last hour
  4. --limit=50return at most 50 entries

Also known as: stackdriver · cloud logging

GCP: Deploy a Cloud Run revision

Safe

Deploy a new image as a new revision and shift 100% traffic to it.

gcloud run deploy <service> --image <image> --region <region>
What each part does
  1. gcloud run deploy <service>create a new revision of the service (creates the service if missing)
  2. --image <image>container image, e.g. europe-docker.pkg.dev/proj/repo/app:1.4
  3. --region <region>region of the service

Also known as: cloud run deploy

GCP: Roll back Cloud Run traffic to a revision

Caution

Send all traffic back to a known good revision.

gcloud run services update-traffic <service> --to-revisions <revision>=100 --region <region>
What each part does
  1. gcloud run services update-traffic <service>change which revisions get traffic (no new deploy)
  2. --to-revisions <revision>=100send 100% of traffic to that revision
  3. --region <region>region of the service

Also known as: cloud run rollback

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/…