CloudWatch>ロググループ>ライブテールでリアルタイムに参照することを考えると
特定のロググループは意味のある単位(まとめて時系列を追いたい単位)でまとめるのが良いと想像できる。
参考にさせていただいた記事
テスト用の設定ファイル
# cat /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
{
"agent": {
"run_as_user": "root"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/work/sample.log",
"log_group_class": "STANDARD",
"log_group_name": "sample.log",
"log_stream_name": "{instance_id}",
"retention_in_days": 1
},
{
"file_path": "/var/work/sample_2025-10-26_15-25-50.log",
"log_group_class": "STANDARD",
"log_group_name": "sample.log",
"log_stream_name": "{instance_id}_2",
"retention_in_days": 1
}
]
}
}
}
}
EC2にアタッチしたマネージドポリシー(組み込みポリシー)
CloudWatchAgentServerPolicy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CWACloudWatchServerPermissions",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeVolumes",
"ec2:DescribeTags",
"logs:PutLogEvents",
"logs:PutRetentionPolicy",
"logs:DescribeLogStreams",
"logs:DescribeLogGroups",
"logs:CreateLogStream",
"logs:CreateLogGroup",
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries"
],
"Resource": "*"
},
{
"Sid": "CWASSMServerPermissions",
"Effect": "Allow",
"Action": [
"ssm:GetParameter"
],
"Resource": "arn:aws:ssm:*:*:parameter/AmazonCloudWatch-*"
}
]
}