LoginSignup
0

AWS CLI or CloudShellで使用したコマンド達

Last updated at Posted at 2023-05-27

コマンドは使わないと忘れるんだ.....だからまとめておくんだ

AWS CLIの設定方法

AWS CLI の最新バージョンをインストールまたは更新します。

AWS CLI の設定、確認
  • IAMで発行できるアクセスキー、シークレットアクセスキー、及びリージョン、出力形式の設定が行えるコマンド
aws configure
AWS CLI のバージョン確認
aws --version

CloudShellの注意点

CloudShellはAWS CLIを設定しなくてもIAMに準ずる権限でAWSコマンドが叩ける便利な機能です。
検索バーで検索するか、フッター部分のCloudShellを押下すれば起動可能です。
WS000002.JPG
WS000005.JPG
東京リージョンで使うなら問題ないですが、現状大阪リージョンではCloudShellは使えません。
大阪リージョンを使用する場合はAWS CLIを設定しましょう。

WS000003.JPG
本文:
CloudShell is not available in the selected AWS Console region. CloudShell will run in Asia Pacific (Sydney) ap-southeast-2 and use the home directory in ap-southeast-2. To run commands on AWS resources in a different region, see Working in AWS Regions

訳:選択したAWS ConsoleのリージョンでCloudShellが利用できません。CloudShellはアジア太平洋(シドニー)ap-southeast-2で実行され、ap-southeast-2のホームディレクトリが使用されます。異なるリージョンのAWSリソースでコマンドを実行するには、「AWSリージョンでの作業」を参照してください。

その他、AWS CLI or CloudShellで使用したコマンド

特定のEC2インスタンスIDの情報を取得
aws ec2 describe-instances --instance-ids【 i-XXXXで始まるインスタンスID】
IAMロールの情報取得
aws iam get-role --role-name【IAMロール名】
IAMポリシーの情報取得
aws iam get-policy --policy-arn【IAMポリシーARN】
インスタンスプロファイルの一覧取得
aws iam list-instance-profiles | jq -r '.InstanceProfiles[] | [.Arn, .Roles[].RoleName] | @csv' | tee tmpRole.csv | cat
任意のインスタンスプロファイル情報取得
aws iam get-instance-profile --instance-profile-name【インスタンスプロファイル名】
EBSの一覧情報取得
aws ec2 describe-volumes --query "Volumes[].[Attachments[0].InstanceId,AvailabilityZone,Encrypted,Size,State,VolumeId,Iops,VolumeType]" --output text
キーペアの確認コマンド
aws ec2 describe-key-pairs --key-name【キーペアの名前】
securityhubのARNの取得
aws securityhub get-enabled-standards
S3バケットの一覧表示
aws s3 ls
ローカルPCからS3へファイルアップロード
aws s3 cp {ローカルPCファイルパス} s3://{バケット名}/{パス}
  • (例) WORKフォルダのsample01.txtをwork/Evidence/Testにアップロードしたい場合
aws s3 cp C:\WORK\sample01.txt s3://work/Evidence/Test/
S3からローカルPCへファイルコピー
aws s3 cp s3://{バケット名}/{パス} {ローカルPCファイルパス}
  • (例) S3のWORKフォルダのsample01.txtをローカルPCへダウンロードしたい場合
aws s3 cp C:\WORK\sample01.txt s3://work/Evidence/Test/

参照したもの

AWS CLI Command Reference
AWS CLIでS3を操作するコマンド一覧

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
What you can do with signing up
0