Skip to content

Instantly share code, notes, and snippets.

@mogproject
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogproject/6ce5c6cd4ea5bdf4b54d to your computer and use it in GitHub Desktop.
Save mogproject/6ce5c6cd4ea5bdf4b54d to your computer and use it in GitHub Desktop.
AWS CLI Cheat Sheat

対話的な config 設定

$ aws configure
AWS Access Key ID [None]: XXXXXX
AWS Secret Access Key [None]: XXXXXX
Default region name [None]: ap-northeast-1
Default output format [None]:

または

  • ~/.aws/credentials
[your_profile_name]
aws_access_key_id = XXXXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • ~/.aws/config
[profile your_profile_name]
region = ap-northeast-1

Name と プライベートIPアドレスの表示

Name昇順にソートし、かつName未指定のものを除外する例

$ aws ec2 describe-instances --output text --query 'sort_by(Reservations[].Instances[?not_null(Tags[?Key==`Name`].Value)][].[PrivateIpAddress,Tags[?Key==`Name`].Value|[0]], &[1])'
172.31.xxx.xxx   aaa-01
172.31.xxx.xxx   aaa-02
172.31.xxx.xxx   bbb-01

起動中のインスタンスのみを表示

$ aws ec2 describe-instances --output text --query 'sort_by(Reservations[].Instances[?State.Name==`running`][].[PrivateIpAddress,Tags[?Key==`Name`].Value|[0]], &[1])'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment