aws s3 ls s3://<バケット>/<パス>/
aws s3 cp <ファイル> s3://<バケット>/<パス>/
aws s3 sync <ディレクトリ> s3://<バケット>/<パス>/
aws s3 rm s3://<バケット>/<パス>/<ファイル>
aws ec2 describe-instances --profile=taro --region us-east-1
aws ec2 run-instances --dry-run --region us-east-1 \
--image-id ami-12345678901234567 --count 1 \
--instance-type t3a.nano --key-name HogeKey \
--subnet-id subnet-12345678 \
--security-group-ids sg-12345678901234567 \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=hoge},{Key=id,Value=123}]" \
"ResourceType=volume,Tags=[{Key=Name,Value=hoge},{Key=id,Value=123}]" \
--credit-specification CpuCredits=standard \
--associate-public-ip-address \
--block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":10,"DeleteOnTermination":true}}]' \
--profile=otp-mfa-acc
“VolumeSize”:10: ボリュームサイズ 10GB
otp-mfa-acc: 後述の認証で取得した情報をセットしたプロファイル名。インスタスン作成に必要な権限を持つアカウントを使って実行する場合は不要。
aws ec2 create-image --profile=taro --instance-id i-1234567890abcdefg --name "hoge" --tag-specifications 'ResourceType=image,Tags=[{Key=Name,Value=hoge},{Key=env,Value=prod}]' 'ResourceType=snapshot,Tags=[{Key=Name,Value=hoge},{Key=env,Value=prod}]'
aws ec2 describe-images --owner-ids self --filters 'Name=tag:Name,Values=hoge*' --profile taro --region us-east-1
aws ec2 modify-image-attribute --profile=taro --image-id ami-1234567890abcdefg --launch-permission "Add=[{UserId=123456789012}]"
aws ec2 copy-image --source-image-id ami-1234567890abcdefg --source-region us-east-1 --region us-east-1 --name "aminame" --profile taro
aws ec2 describe-snapshots --owner-ids self --filters 'Name=tag:Name,Values=hoge*' --profile taro --region us-east-1
aws ec2 modify-snapshot-attribute --snapshot-id snap-1234xxx --attribute createVolumePermission --operation-type add --user-ids 123456789012 --profile taro --region us-east-1
[mfa-acc]
aws_access_key_id = ABCxxx
aws_secret_access_key = abcxxx
--serial-number
には IAM の「セキュリティ認証情報」タブの「多要素認証(MFA)」に表示されている識別子を指定。
aws sts get-session-token --profile mfa-acc --serial-number arn:aws:iam::12345678:mfa/username --token-code <OTP>
結果例
{
"Credentials": {
"AccessKeyId": "ABCxxx",
"SecretAccessKey": "abcxxx",
"SessionToken": "xxx...",
"Expiration": "2024-01-10T00:15:30+00:00"
}
}
[otp-mfa-acc]
aws_access_key_id = ABCxxx
aws_secret_access_key = abcxxx
aws_session_token = xxx...
aws ec2 describe-instances --profile=otp-mfa-acc
aws sts get-caller-identity
lsblk
nvme0n1 259:0 0 5G 0 disk
└─nvme0n1p1 259:1 0 3G 0 part /
sudo growpart /dev/nvme0n1 1
df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p1 xfs 3.0G 2.3G 745M 76% /
xfs_growfs がインストールされていない場合は、xfsprogs をインストール。
sudo xfs_growfs -d /
S3コンソールの「アクセス許可」- 「バケットポリシー」で次のように設定
{
"Version": "2012-10-17",
"Id": "Policy1234567890123",
"Statement": [
{
"Sid": "AllowVpc20201015",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/hoge"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::bucket-hoge",
"arn:aws:s3:::bucket-hoge/*"
],
"Condition": {
"StringEquals": {
"aws:sourceVpc": "vpc-12345678"
}
}
},
{
"Sid": "AllowIp20201015",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:user/hoge"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::bucket-hoge",
"arn:aws:s3:::bucket-hoge/*"
],
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"1.2.3.4/32",
"2.3.4.0/24"
]
}
}
}
]
}