0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS CLI よく使うコマンド集【忘備録】

Posted at

aws cli でよく使うコマンドのサンプルを掲載しています。随時アップデートしていきます。

EC2の情報取得

# 一覧表示
aws ec2 describe-instances \
  --query 'Reservations[].Instances[].{dns:PublicDnsName, name:Tags[?Key==`Name`] | [0].Value}' \
  --output table
----------------------------------------------------------------------------------------------------------------
|                                               DescribeInstances                                              |
+--------------------------------------------------------------+----------------------+----------+-------------+
|                             Name                             |         id           | status   |    type     |
+--------------------------------------------------------------+----------------------+----------+-------------+
|  aws-cloud9-handson-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |  i-xxxxxxxxxxxxxxxxx |  stopped |  t3.small   |
|  aws-cloud9-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                 |  i-xxxxxxxxxxxxxxxxx |  running |  t3a.small  |
+--------------------------------------------------------------+----------------------+----------+-------------+

# 詳細表示
 aws ec2 describe-instances --instance-ids i-xxxxxxxxxxxxx --output json

CloudFrontの情報取得

# cloudfrontの情報を表組みして表示
aws cloudfront list-distributions \
  --query 'DistributionList.Items[].{ID:Id, DomainName:DomainName, URL: Aliases.Items[0]}' \
  --output table
---------------------------------------------------------------------------------------------
|                                     ListDistributions                                     |
+--------------------------------+-----------------+----------------------------------------+
|           DomainName           |       ID        |                  URL                   |
+--------------------------------+-----------------+----------------------------------------+
|  xxxxxxxxxxxxxx.cloudfront.net |  xxxxxxxxxxxxx  |  xxxxx.example.jp                      |
+--------------------------------+-----------------+----------------------------------------+

# 詳細表示
aws cloudfront get-distribution --id xxxxxxxxxxxxx

S3の情報取得

ダウンロードせずに内容を出力する方法

# 通常のテキストファイルの出力
aws s3 cp s3://[bucket_name]/path/to/textfile.txt -
# 圧縮ファイルの出力
aws s3 cp s3://[bucket_name]/path/to/access_log.gz - | zcat

比較

diff -u <(aws s3 cp s3://[bucket_name]/path/to/textfile.txt -) path/to/file

参考

AWS CLI 出力をフィルタリングする
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-usage-filter.html

JMESPath is a query language for JSON.
https://jmespath.org/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?