Skip to content

Instantly share code, notes, and snippets.

@neilkuan
Last active August 10, 2021 13:25
Show Gist options
  • Select an option

  • Save neilkuan/1c906c933c5452f2633a8e9cb9631180 to your computer and use it in GitHub Desktop.

Select an option

Save neilkuan/1c906c933c5452f2633a8e9cb9631180 to your computer and use it in GitHub Desktop.
AWS CLI Tips notes.

IAM STS

$ aws sts get-caller-identity --query  Arn
"arn:aws:iam::123456789012:user/neilguan"
$ aws sts get-caller-identity --query  Arn --output text
arn:aws:iam::123456789012:user/neilguan
$ aws sts get-caller-identity --query  Account --output text
123456789012
$ aws sts get-caller-identity --query  UserId --output text
AIXXXXXXXXXXXXXXXXXXXG

EKS Cluster Arn

aws eks describe-cluster --name $EKS_CLUSTER_NAME --query cluster.arn --output text
arn:aws:eks:${EKS_EXIST_REGION}:123456789012:cluster/$EKS_CLUSTER_NAME

ECS

while true; do aws ecs list-tasks  --cluster ${ECS_CLUSTER_NAME} --query taskArns[*] --output text | \
xargs aws ecs describe-tasks --cluster ${ECS_CLUSTER_NAME} --query tasks[*].'capacityProviderName' --tasks && \
sleep 4 ;done
---
[
    "FARGATE_SPOT",
    "FARGATE_SPOT",
    "FARGATE_SPOT",
    "FARGATE",
    "FARGATE",
    "FARGATE_SPOT"
]

CONFIGURE

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                 PROFILENAME          manual    --profile
access_key     ****************QJNR shared-credentials-file    
secret_key     ****************N8gh shared-credentials-file    
    region           ap-northeast-1      config-file    ~/.aws/config

$ aws configure list-profiles
default
profile1
profile2

S3

# delete all object in bucket.
$ aws s3 rm s3://[bucket-name] --recursive

# delete bucket
$aws s3 rb s3://[bucket-name]

# presignUrl example.
aws s3 presign s3://awsexamplebucket/test2.txt --expires-in 604800

EC2

#!/bin/bash
aws ec2 describe-instances --filter "Name=tag:$1,Values=$2" 

query tips

 aws cloudformation describe-stacks --stack-name [stack-name] --output text --query 'Stacks[*].Outputs[?OutputKey=='outputkey...'].OutputValue'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment