Grunt tasks to create, terminate, and deploy to AWS EC2 instances
Grunt tasks to create, terminate, and deploy Node applications to AWS EC2 instances, then proxy with nginx
Abstracts away aws-cli allowing you to easily launch, terminate, and deploy to AWS EC2 instances.
Note: This is a very, very opinionated package. You're invited to fork it and produce your own flow, and definitely encouraged to create pull requests with your awesome improvements.
Jump to the task reference to see what it can do.
This is pretty feature packed
pm2to deploy and do hot code swaps!
nginxproxy server in front of Node
npm install --save-dev grunt-ec2
For every task in this document, you'll need to set up the AWS configuration for the project. You'll also need to have a Security Group set up on AWS. Make sure to enable rules for inbound SSH (port 22) and HTTP (port 80) traffic.
The first time around, you'll need to get
pip to be able to deploy.
Once you installed
pip, you can install the
pip install awscli --upgrade
gruntinitConfigpkg: gruntfilereadJSON'package.json'ec2: 'path/to/whatever.json';gruntloadNpmTasks'grunt-ec2';
Then, in your
You'll need to get an access key pair for AWS, as well as create a security group on AWS by hand. Creating security groups through the CLI is not supported by this package yet.
package.json entry is used to take the
version number when deploying.
ec2 configuration, I don't take an object directly to encourage hiding away the deployment variables, granting them only to people who can actually perform deploys. You could provide an object directly, but it's strongly discouraged.
If you're confident enough, you can use the tool with just those options. Here is the full set of options and their defaults.
|Passed to the CLI directly, defaults to |
|Used when creating a new instance with the |
|The magnitude for our instance. Defaults to |
|The security group used for new instances. You'll have to create this one yourself.|
|The user used to SSH into the instance when setting it up for the first time, after creating it.|
|The user to SSH into the instance when deploying through |
|The relative path to a folder where you want to use with tasks that create SSH key-pairs. It doesn't need to exist, |
|Just an identifier for your project, in case you're hosting multiple ones, for some stupid reason, in the same instance. Defaults to |
|An array of file patterns to explicitly exclude during deploys. The |
|Relative path to an rsync exclusion patterns file. These are used to exclude files from being uploaded to the server during |
|An array of file patterns to explicitly include during deploys. The |
|Relative path to an rsync inclusion patterns file. These are used to include files for upload to the server during |
|The path to your script. Defaults to |
|Whether to install and use |
|This is the port where |
|The server name for your static server, for example: |
|The relative path to your static folder root, for example: |
|The relative path to your error HTML views folder root. For example |
|The user to configure and run |
|The amount of workers processes used by |
|Enables SSL configuration on |
|Relative path to your unified SSL certificate.|
|Relative path to your private certificate key.|
|Whether to send a |
|If provided, will run Google PageSpeed insights on every deployment. Get an API Key here. Requires you to setup |
|Assign an AWS Elastic IP to new instances, and release it when terminating them. Defaults to |
|Provided as a JSON object. Variables to set in the local environment before the app starts. Useful for setting up DB credentials for example.|
|Determines the output verbosity for |
|Determines the output verbosity for |
Although this package exposes quite a few different tasks, here are the ones you'll want to be using directly.
Launches an instance and sets it up.
Terminates an instance and deletes related objects
Returns a JSON list of running EC2 instances. Defaults to filtering by
running state. You can use
ec2_list:all to remove the filter, or pick another
instance-state-name to filter by.
ec2_list, but lets you get the properties of an instance by name, rather than state. Try it with
Gives you a command you can copy and paste to connect to an EC2 instance through SSH. Useful to get down and dirty.
Deploys to a running EC2 instance using
rsync over SSH.
rsyncfolder such as
pkg.version, creates a folder with the newest version, like
Reboots the instance by the specified name.
|Task and Target(s)||Purpose|
|Allocates an IP and assigns it to your instance|
|Generates an RSA key pair and uploads the public key to AWS|
|Tags an instance with the provided name|
|Removes the remote and the local copies of the RSA key|
|Deletes the associated name tag for an instance|
|Deploys to the instance using |
|Creates a new instance, giving it a key-pair, a name tag, and an IP. Then sets it up|
|Lists instances filtered by state. Defaults to |
|Gets instance filtered by name tag|
|Returns output for |
|Reloads app using |
|Restarts app using |
|Starts app using parameterized |
|Stops app using |
|Requests the Google PageSpeed API, prints insights|
|Reboots the EC2 instance|
|Releases an IP address|
|Spins up an EC2 instance, gives a name tag and assigns an IP|
|Sets up port forwarding, installs |
|Terminates an instance, deleting its associated key-pair, IP address, and name tag|
|Displays a verbose command with which you can establish an |
|Terminates an instance|
|Get the version number currently deployed to EC2|
|Waits for an instance to report a public DNS and be accessible through |
Enjoy it. Submit any issues you encounter, and send any feedback you might have my way.