AWS Elastic Beanstalk: Add custom logs to CloudWatch?

后端 未结 4 472
心在旅途
心在旅途 2020-12-23 22:17

How to add custom logs to CloudWatch? Defaults logs are sent but how to add a custom one?

I already added a file like this: (in .ebextensions)

files         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 22:49

    The awslogs agent looks in the configuration file for the log files which it's supposed to send. There are some defaults in it. You need to edit it and specify the files.

    You can check and edit the configuration file located at:

    /etc/awslogs/awslogs.conf
    

    Make sure to restart the service:

    sudo service awslogs restart
    

    You can specify your own files there and create different groups and what not.

    Please refer to the following link and you'll be able to get your logs in no time.

    Resources:

    https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html

    Edit:

    As you don't want to edit the files on the instance, you can add the relevant code to the .ebextensions folder in the root of your code. For example, this is my 01_cloudwatch.config :

    packages:
      yum:
        awslogs: []
    
    container_commands:
      01_get_awscli_conf_file:
        command: "aws s3 cp s3://project/awscli.conf /etc/awslogs/awscli.conf"
      02_get_awslogs_conf_file:
        command: "aws s3 cp s3://project/awslogs.conf.${NODE_ENV} /etc/awslogs/awslogs.conf"
      03_restart_awslogs:
        command: "sudo service awslogs restart"
      04_start_awslogs_at_system_boot:
        command: "sudo chkconfig awslogs on"
    

    In this config, I am fetching the appropriate config file from a S3 bucket depending on the NODE_ENV. You can do anything you want in your config.

提交回复
热议问题