Amazon Web Servicesのインフラストラクチャを管理するための、EC2、S3、Lambdaなどを含む包括的なAWS CLIコマンドとワークフロー。
インストールと設定
| コマンド | 説明 |
|---|
aws configure | AWS認証情報とリージョンを設定 |
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-folder | S3 をローカルフォルダと同期 |
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 | ポリシーの詳細を取得 |
スタック管理
| コマンド | 説明 |
|---|
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 20 | DBインスタンスを作成 |
aws rds start-db-instance --db-instance-identifier mydb | DBインスタンスを起動 |
aws rds stop-db-instance --db-instance-identifier mydb | DBインスタンスを停止 |
aws rds delete-db-instance --db-instance-identifier mydb --skip-final-snapshot | DBインスタンスを削除 |
データベーススナップショット
| コマンド | 説明 |
|---|
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/16 | VPCを作成 |
aws ec2 delete-vpc --vpc-id vpc-12345678 | VPCを削除 |
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 | ログイベントを取得 |
ベストプラクティス
セキュリティ