.ebextensions
。01_cloudwatch.config
。"Resources": {
"AWSEBAutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"Tags": [
{
"Key": "Name",
"Value": "aws-elasticbeanstalk-instance",
"PropagateAtLaunch": true
}
]
}
}
},
"files": {
"/etc/awslogs/config/cloudwatchlogs.conf": {
"content": {
"file": "/var/app/current/log/*",
"datetime_format": "%Y-%m-%d %H:%M:%S",
"log_stream_name": "{instance_id}",
"timezone": "UTC",
"initial_position": "start_of_file",
"buffer_duration": 5000,
"batch_count": 1000,
"batch_size": 1024,
"log_group_name": "YOUR_LOG_GROUP_NAME"
},
"mode": "000644",
"owner": "root",
"group": "root"
}
},
"services": {
"syslog": {
"enabled": "true",
"ensureRunning": "true",
"files": [
"/etc/awslogs/config/cloudwatchlogs.conf"
]
}
}
确保将 YOUR_LOG_GROUP_NAME
替换为您的 CloudWatch 日志组的名称。
4. 将此文件添加到您的代码库并推送到 Elastic Beanstalk。
5. 在 Elastic Beanstalk 控制台中导航到应用程序的环境。
6. 单击 Configuration
,然后单击 Edit
。
7. 在 Software
部分中,单击 Modify
。
8. 在 Elastic Beanstalk log options
部分中,选择 Stream logs to Amazon CloudWatch Logs
。
9. 单击 Save
以更新 Elastic Beanstalk 环境。
10. 现在应该可以在 CloudWatch 中看到您的应用程序的日志了。