Making changes to CodeDeploy to better handle logging

We will first make CodeDeploy generate the version file. To do that, we will open the appspec.ymlfile at the root of the helloworld application directory.

At the bottom of the file, after the ValidateService hook, we will use a new hook to trigger our setversion script. This operation will need to happen after the helloworld application is installed. As such, we will want to add the following hook:

  AfterInstall: 
    - location: scripts/setversion.sh 
      timeout: 180 

We now need to handle our new files. The first one is the logrotate configuration. In the files section at the top of our appsec file, add the following:

  - source: conf/logrotate 
    destination: /etc/logrotate.d/helloworld 

Lastly, we need to handle the installation of our libraries now that we have some extra dependencies. There are a few ways to deal with dependencies. The most obvious one is to run npm install during the deployment. This allows you to keep your code base small and light. The downside is that you now rely on https://www.npmjs.com/ to be working to get a deployment out, which can be risky. Imagine the scenario where you have to deploy a fix for a major bug but can't because the installation of your dependencies is failing. To avoid this, it is best practice to also commit the node_modules directory with your code.

After the previous configuration to deploy the logrotate configuration, add the following:

  - source: node_modules 
    destination: /usr/local/helloworld/node_modules 

Your new appsec file should look like this: http://bit.ly/2uI4BvE.

We can now commit all the changes:

$ git add helloworld.js node_modules package.json conf scripts/setversion.sh appsec.yml scripts/helloworld.conf
$ git commit -m "Adding logging to helloworld"
$ git push  

Thanks to our pipelines, those changes will be deployed to our EC2 instances, and, in no time, we will start seeing logs populated on the hosts.

We will now add metrics and events to our application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset