CloudWatch Logs の設定手順

(1) IAM ロールに CloudWatch Logs へのアクセス権限を追加します。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:*"
      ],
      "Resource": [
        "arn:aws:logs:*:*:*"
      ]
    }
  ]
}

(2) AWS CLI ( awslogs ) をインストールします。

yum install awslogs

vi /etc/awslogs/awscli.conf
[plugins]
cwlogs = cwlogs
[default]
region = ap-northeast-1
aws_access_key_id = 
aws_secret_access_key = 

(3) エージェントの設定を行います。

(参考) http://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/DeveloperGuide/AgentReference.html

vi /etc/awslogs/awslogs.conf

datetime_format = %Y-%m-%d %H:%M:%S
file = /var/log/tomcat7/all.log*
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /var/log/tomcat7/all.log

(4) エージェントを起動します。

service awslogs start
chkconfig awslogs on