1 Answer
- Newest
- Most votes
- Most comments
0
If we want to customize the logs from instance for Amazon Linux 2 platform when the application is deployed using elasticbeanstalk, we need to follow these steps:
- Create a custom file in .ebextension/ in the root directory of your application
- Copy the below code and save the file with any name but with .config extension For Eg: custom-logs.config The below code is to include /var/log/messages logs to be streamed to cloudwatch
packages:
yum:
awslogs: []
files:
"/etc/awslogs/awscli.conf" :
mode: "000600"
owner: root
group: root
content: |
[plugins]
cwlogs = cwlogs
[default]
region = `{"Ref":"AWS::Region"}`
"/etc/awslogs/awslogs.conf" :
mode: "000600"
owner: root
group: root
content: |
[general]
state_file = /var/lib/awslogs/agent-state
"/etc/awslogs/config/logs.conf" :
mode: "000600"
owner: root
group: root
content: |
[/var/log/messages]
log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/messages"]]}`
log_stream_name = {instance_id}
file = /var/log/messages
commands:
"01":
command: systemctl enable awslogsd.service
"02":
command: systemctl restart awslogsd
- Deploy the application.
You should see the logs in cloudwatch for the configured logs.
answered a year ago
Relevant content
- Accepted Answerasked 8 months ago
- Accepted Answerasked 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
It seems it is deprecated in AL2023 as awslogs is not available in AL2023. Any updated approach to do this? Thanks.