How to stream custom logs to CloudWatch using elastic beanstalk

0

I want to stream the custom logs into cloud watch when the application is deployed using elastic beanstalk.

1개 답변
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:

  1. Create a custom file in .ebextension/ in the root directory of your application
  2. 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
  1. Deploy the application.

You should see the logs in cloudwatch for the configured logs.

*Reference: https://github.com/awsdocs/elastic-beanstalk-samples/blob/main/configuration-files/aws-provided/instance-configuration/logs-streamtocloudwatch-linux.config *

답변함 9달 전
  • It seems it is deprecated in AL2023 as awslogs is not available in AL2023. Any updated approach to do this? Thanks.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠