コンテンツにスキップ

AWS CLI

Amazon Web Servicesのインフラストラクチャを管理するための、EC2、S3、Lambdaなどを含む包括的なAWS CLIコマンドとワークフロー。

インストールと設定

コマンド説明
aws configureAWS認証情報とリージョンを設定
aws configure list現在の設定を表示
aws configure set region us-west-2デフォルトリージョンを設定
aws configure set output json出力形式を設定
aws sts get-caller-identity現在のアイデンティティを確認
aws configure list-profiles設定されているすべてのプロファイルを一覧表示
aws configure --profile myprofile名前付きプロファイルを設定

EC2 (Elastic Compute Cloud)

インスタンス管理

コマンド説明
aws ec2 describe-instancesすべてのインスタンスを一覧表示
aws ec2 run-instances --image-id ami-12345 --instance-type t2.microインスタンスを起動
aws ec2 start-instances --instance-ids i-1234567890abcdef0インスタンスを起動
aws ec2 stop-instances --instance-ids i-1234567890abcdef0インスタンスを停止
aws ec2 terminate-instances --instance-ids i-1234567890abcdef0インスタンスを終了
aws ec2 reboot-instances --instance-ids i-1234567890abcdef0インスタンスを再起動

セキュリティグループ

コマンド説明
aws ec2 describe-security-groupsセキュリティグループを一覧表示
aws ec2 create-security-group --group-name MySecurityGroup --description "My security group"セキュリティグループを作成
aws ec2 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 80 --cidr 0.0.0.0/0受信ルールを追加
aws ec2 revoke-security-group-ingress --group-id sg-12345 --protocol tcp --port 80 --cidr 0.0.0.0/0受信ルールを削除

キーペア

コマンド説明
aws ec2 describe-key-pairsキーペアをリスト表示
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pemキーペアを作成
aws ec2 delete-key-pair --key-name MyKeyPairキーペアを削除

S3 (Simple Storage Service)

バケット操作

コマンド説明
aws s3 lsすべてのバケットをリスト表示
aws s3 mb s3://my-bucketバケットを作成
aws s3 rb s3://my-bucket空のバケットを削除
aws s3 rb s3://my-bucket --forceバケットとすべてのコンテンツを削除
aws s3 ls s3://my-bucketバケット内のオブジェクトをリスト
aws s3 ls s3://my-bucket --recursiveオブジェクトを再帰的にすべてリストする

ファイル操作

コマンド説明
aws s3 cp file.txt s3://my-bucket/ファイルをアップロード
aws s3 cp s3://my-bucket/file.txt .ファイルをダウンロード
aws s3 sync ./local-folder s3://my-bucket/ローカルフォルダをS3に同期
aws s3 sync s3://my-bucket/ ./local-folderS3 をローカルフォルダと同期
aws s3 rm s3://my-bucket/file.txtファイルを削除
aws s3 rm s3://my-bucket/ --recursiveバケット内のすべてのファイルを削除

高度なS3操作

コマンド説明
aws s3api get-bucket-versioning --bucket my-bucketバージョニングステータスを確認
aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabledバージョニングを有効にする
aws s3api get-bucket-encryption --bucket my-bucket暗号化を確認
aws s3api put-bucket-encryption --bucket my-bucket --server-side-encryption-configuration file://encryption.json暗号化を有効にする

Lambda

関数管理

コマンド説明
aws lambda list-functionsすべての関数を一覧表示
aws lambda create-function --function-name my-function --runtime python3.9 --role arn:aws:iam::123456789012:role/lambda-role --handler lambda_function.lambda_handler --zip-file fileb://function.zip関数を作成する
aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip関数コードを更新
aws lambda invoke --function-name my-function output.txt関数を呼び出す
aws lambda delete-function --function-name my-function削除関数

関数設定

コマンド説明
aws lambda get-function --function-name my-function関数の詳細を取得
aws lambda update-function-configuration --function-name my-function --timeout 30タイムアウトを更新
aws lambda update-function-configuration --function-name my-function --memory-size 256メモリを更新
aws lambda put-function-event-invoke-config --function-name my-function --maximum-retry-attempts 1リトライを設定

IAM (Identity and Access Management)

ユーザー管理

コマンド説明
aws iam list-usersすべてのユーザーを一覧表示
aws iam create-user --user-name myuserユーザーを作成
aws iam delete-user --user-name myuserユーザーを削除
aws iam get-user --user-name myuserユーザーの詳細を取得
aws iam create-access-key --user-name myuserアクセスキーを作成
aws iam delete-access-key --user-name myuser --access-key-id AKIAIOSFODNN7EXAMPLEアクセスキーを削除

ロール管理

コマンド説明
aws iam list-rolesすべての役割を一覧表示
aws iam create-role --role-name MyRole --assume-role-policy-document file://trust-policy.jsonロールを作成
aws iam attach-role-policy --role-name MyRole --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccessロールにポリシーをアタッチする
aws iam detach-role-policy --role-name MyRole --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccessロールからポリシーを切り離す

ポリシー管理

コマンド説明
aws iam list-policiesすべてのポリシーを一覧表示
aws iam create-policy --policy-name MyPolicy --policy-document file://policy.jsonポリシーを作成
aws iam delete-policy --policy-arn arn:aws:iam::123456789012:policy/MyPolicy削除ポリシー
aws iam get-policy --policy-arn arn:aws:iam::123456789012:policy/MyPolicyポリシーの詳細を取得

CloudFormation

スタック管理

コマンド説明
aws cloudformation list-stacksすべてのスタックを一覧表示
aws cloudformation create-stack --stack-name my-stack --template-body file://template.yamlスタックを作成
aws cloudformation update-stack --stack-name my-stack --template-body file://template.yamlスタックを更新
aws cloudformation delete-stack --stack-name my-stackスタックを削除
aws cloudformation describe-stacks --stack-name my-stackスタックの詳細を取得
aws cloudformation describe-stack-events --stack-name my-stackスタックイベントを取得

テンプレート操作

コマンド説明
aws cloudformation validate-template --template-body file://template.yamlテンプレートを検証
aws cloudformation estimate-template-cost --template-body file://template.yamlコストを見積もる
aws cloudformation get-template --stack-name my-stackスタックテンプレートを取得

RDS (Relational Database Service)

データベースインスタンス管理

コマンド説明
aws rds describe-db-instancesすべてのDBインスタンスを一覧表示
aws rds create-db-instance --db-instance-identifier mydb --db-instance-class db.t3.micro --engine mysql --master-username admin --master-user-password mypassword --allocated-storage 20DBインスタンスを作成
aws rds start-db-instance --db-instance-identifier mydbDBインスタンスを起動
aws rds stop-db-instance --db-instance-identifier mydbDBインスタンスを停止
aws rds delete-db-instance --db-instance-identifier mydb --skip-final-snapshotDBインスタンスを削除

データベーススナップショット

コマンド説明
aws rds describe-db-snapshotsすべてのスナップショットを一覧表示
aws rds create-db-snapshot --db-instance-identifier mydb --db-snapshot-identifier mydb-snapshotスナップショットを作成
aws rds restore-db-instance-from-db-snapshot --db-instance-identifier mydb-restored --db-snapshot-identifier mydb-snapshotスナップショットから復元
aws rds delete-db-snapshot --db-snapshot-identifier mydb-snapshotスナップショットを削除

VPC (Virtual Private Cloud)

VPC管理

コマンド説明
aws ec2 describe-vpcsすべてのVPCをリスト表示
aws ec2 create-vpc --cidr-block 10.0.0.0/16VPCを作成
aws ec2 delete-vpc --vpc-id vpc-12345678VPCを削除
aws ec2 describe-subnetsすべてのサブネットを一覧表示
aws ec2 create-subnet --vpc-id vpc-12345678 --cidr-block 10.0.1.0/24サブネットを作成

ルートテーブル

コマンド説明
aws ec2 describe-route-tablesルートテーブルを一覧表示
aws ec2 create-route-table --vpc-id vpc-12345678ルートテーブルを作成
aws ec2 create-route --route-table-id rtb-12345678 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-12345678ルートを追加
aws ec2 associate-route-table --subnet-id subnet-12345678 --route-table-id rtb-12345678ルートテーブルを関連付ける

CloudWatch

メトリクスとアラーム

Would you like me to continue with the remaining translations or provide placeholders for the numbered sections?

コマンド説明
aws cloudwatch list-metricsすべてのメトリクスを一覧表示
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-1234567890abcdef0 --statistics Average --start-time 2023-01-01T00:00:00Z --end-time 2023-01-02T00:00:00Z --period 3600メトリック統計を取得
aws cloudwatch describe-alarmsすべてのアラームを一覧表示
aws cloudwatch put-metric-alarm --alarm-name cpu-mon --alarm-description "Alarm when CPU exceeds 70%" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70.0 --comparison-operator GreaterThanThresholdアラームを作成

ログ

コマンド説明
aws logs describe-log-groupsログロググループをリスト
aws logs create-log-group --log-group-name my-log-groupログググループを作成
aws logs describe-log-streams --log-group-name my-log-groupログストリームを一覧表示
aws logs get-log-events --log-group-name my-log-group --log-stream-name my-log-streamログイベントを取得

ベストプラクティス

セキュリティ