LoginSignup
19
18

More than 5 years have passed since last update.

[AWS 3]AWSの作業ログを採れ!AWS CloudTrailの設定だ!

Last updated at Posted at 2014-08-22

2014/8/22現在でβサービスではありますが、AWS API の呼び出しを記録し、ログファイルを送信するウェブサービスがあります。
これを設定しておかない手はないでしょう。

AWS CLIが動作する環境だと思いますので、aws-cliで実施します。
AWS CLI設定:http://bit.ly/1pcLfYw

1.ログ保存先S3バケット作成

ログの保存先を作成します。
command:
$ aws s3 mb s3://バケット名

result:
make_bucket: s3://バケット名/

2.bucket policy設定

作成したバケットにポリシー設定します。

jsonファイル作成

ローカルに設定するポリシーファイルを置きます。
今回は、マネージメントコンソールで作成する時にできるポリシーとします。

ファイル名:trail.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck20131101",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::903692715234:root",
"arn:aws:iam::859597730677:root",
"arn:aws:iam::814480443879:root",
"arn:aws:iam::216624486486:root",
"arn:aws:iam::086441151436:root",
"arn:aws:iam::388731089494:root",
"arn:aws:iam::284668455005:root",
"arn:aws:iam::113285607260:root"
]
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::hn-trail"
},
{
"Sid": "AWSCloudTrailWrite20131101",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::903692715234:root",
"arn:aws:iam::859597730677:root",
"arn:aws:iam::814480443879:root",
"arn:aws:iam::216624486486:root",
"arn:aws:iam::086441151436:root",
"arn:aws:iam::388731089494:root",
"arn:aws:iam::284668455005:root",
"arn:aws:iam::113285607260:root"
]
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::hn-trail/AWSLogs/376390722258/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}

3.バケットにポリシーを適用

command:
$ aws s3api put-bucket-policy --bucket バケット名 --policy file://trail.json

result:
{
"IncludeGlobalServiceEvents": true,
"Name": "Default",
"S3BucketName": "バケット名"
}

4.CloudTrailの設定

command:
$ aws cloudtrail create-trail --name Default --s3-bucket-name バケット名

Trailの名前は、"Default"のようです。

result:
{
"IncludeGlobalServiceEvents": true,
"Name": "Default",
"S3BucketName": "hn-trail"
}

5.設定確認

command:
$ aws cloudtrail describe-trails

result:
{
"trailList": [
{
"IncludeGlobalServiceEvents": true,
"Name": "Default",
"S3BucketName": "バケット名"
}
]
}

以上で終わりです。

S3を覗いてみましょう!
APIログが記録されているはずです!

--
20140822 initial

19
18
0

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
  3. You can use dark theme
What you can do with signing up
19
18