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 Antwort
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 *

beantwortet vor 9 Monaten
  • It seems it is deprecated in AL2023 as awslogs is not available in AL2023. Any updated approach to do this? Thanks.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen