Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (58 sloc) 3 KB

CodeDeploy Scripts

Codeship Status for tqc/codedeploy-scripts

AWS CodeDeploy lifecycle scripts using ES6 to deploy a node app to EC2.

See for a minimal working example.


npm install codedeploy-scripts

In the app folder, you only need two simple files to handle the deployment.


This tells CodeDeploy to copy everything to /apps/appname and run deployment.js for all lifecycle events. ApplicationStop is omitted, but you can use it if you are extremely confident in the quality of your code, or just enjoy manually fixing broken servers.

version: 0.0
os: linux
    - source: /
      destination: /apps/appname
#  ApplicationStop:
#    - location: deployment.js
#      timeout: 180
    - location: deployment.js
      timeout: 180
    - location: deployment.js
      timeout: 180
    - location: deployment.js
      timeout: 180
    - location: deployment.js
      timeout: 180


Extends the deployment class with any custom actions needed on CodeDeploy lifecycle events. will call the appropriate method based on the LIFECYCLE_EVENT variable set by CodeDeploy.

The below code will run /apps/deploytest/server.js on port 5000, with nginx as a reverse proxy and serving static files on

#!/usr/bin/env node

var SimpleDeployment = require("codedeploy-scripts").SimpleDeployment;
var deployment = new SimpleDeployment({
    appName: "deploytest",
    nodePort: "5000",
    serverScript: "server.js",
    domains: "",
    // files in these folders will be served from nginx without calling the node server
    buildFolder: "build",
    staticFolder: "static",        
    // files in s3 my-secret-bucket/deploytest will be copied to /apps/deploytest; suitable for ssh keys and
    // config files which can't be part of the code deployment
    secretBucket: "my-secret-bucket",
    // if true, nginx will be set to serve https using /apps/deploytest/deploytest.[crt|key]
    useSSL: false

For more complex scenarios, just create a custom subclass based on the implementation of SimpleDeployment.


To keep things simple, the code makes a few assumptions.

  • The target is a standard Amazon Linux instance
  • node.js is installed
  • The app will be installed to /apps/appname

A userdata script that will sufficiently configure a standard Amazon Linux instance can be found at

Manual configuration is required for the security settings - the machine role will need the standard CodeDeploy access settings, plus access to the secrets bucket if used.