Open3
AWS CLI
概要
- AWSのリソースをコマンドで操作できるもの
- AmazonLinuxにはもともと入っている
- WindowsやMacOSにもインストール可能
- AWS CLI設定ファイルは/Users/<user>/.awsに保存される
- config
[default]
output = json
region = ap-northeast-1
- credentials
[default]
aws_access_key_id = XXXXXXXX
aws_secret_access_key = XXXXXXXX
コマンド概要
このコマンドで初期設定を行える
aws configure
初期設定後は.awsの下にconfigとcredentialsファイルが作成される
[root@ip-xxxxxxxxxxxxxxxxxxx ~]# ls -la .aws/
total 8
drwxr-xr-x 2 root root 39 Jul 10 06:26 .
dr-xr-x--- 4 root root 115 Jul 10 06:26 ..
-rw------- 1 root root 48 Jul 10 06:26 config
-rw------- 1 root root 62 Jul 10 06:26 credentials
describeコマンドで
[root@ip-xxxxxxxxxxxxxxxxxxx ~]# aws ec2 describe-vpcs --region ap-northeast-1
{
"Vpcs": [
{
"VpcId": "vpc-xxxxxxxxxxxxxxxxxxx",
"InstanceTenancy": "default",
"Tags": [
{
"Value": "MyVPC",
"Key": "Name"
}
],
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-xxxxxxxxxxxxxxxxxxx",
"CidrBlock": "10.0.0.0/21",
"CidrBlockState": {
"State": "associated"
}
}
],
"State": "available",
"DhcpOptionsId": "dopt-xxxxxxxxxxxxxxxxxxx",
"OwnerId": "294892136588",
"CidrBlock": "10.0.0.0/21",
"IsDefault": false
},
{
"VpcId": "vpc-xxxxxxxxxxxxxxxxxxx",
"InstanceTenancy": "default",
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-xxxxxxxxxxxxxxxxxxx",
"CidrBlock": "172.31.0.0/16",
"CidrBlockState": {
"State": "associated"
}
}
],
"State": "available",
"DhcpOptionsId": "dopt-xxxxxxxxxxxxxxxxxxx",
"OwnerId": "2xxxxxxxxxxxxxxxxxxx8",
"CidrBlock": "172.31.0.0/16",
"IsDefault": true
}
]
}
S3に対するコマンド
- mb (make backet)
aws s3 mb s3://<バケット名>
- cp
--recursiveで再帰的にもできる
# aws s3 cp test s3://xxxxxxxx
upload: ./test to s3://xxxxxxxx/test
- syncによる同期
aws s3 sync <同期元> <同期先>
例) /var/log/の下の.logという拡張子のファイルを同期する
aws s3 sync /var/log/ s3://xxxxxx/log --exclude "*" --include "*.log"
--dryrunでdryrunもできる
基本的には同期だが--deleteをつけると同期先と比べて、同期元に無いファイルを削除する