1

I have a Tomcat app on Elastic Beanstalk, and I want to send logs to Cloudwatch Logs. To that end, I set up log4j to write to file, and in .ebextension, amazon-cloudwatch-agent is installed and run.

commands:
#  00_download_and_install:
#    command: rpm --upgrade --force https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
  01_start:
    command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
packages:
  yum:
    amazon-cloudwatch-agent: []
files:
  "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json":
    content: |
       {...
       }

Unfortunately, every time I deploy the app to Elastic Beanstalk, the agent shuts down, and I have to restart it manually via ssh.

f.khantsis
  • 319
  • 1
  • 5
  • 13

1 Answers1

1

If you set default log streaming to disabled in the environment configuration, then Beanstalk is stopping the cloudwatch agent during deployment. Unfortunately it does that shortly after the ebextension command for starting the agent is executed.

To solve this issue I used a platform postdeploy hook, which is executed after the deployment and thus overriding the agent shutdown from the beanstalk default.

Simply put a shell script containing the start command in ./platform/hooks/postdeploy/ in your application bundle.

Florian K.
  • 11
  • 3