mrm-task-npm-aws
MRM task to configure your npm projects with scripts to accomplish blue-green deployments on AWS ECS
These are generic npm scripts that you can configure your package.json
with and get access to convinience scripts to upload and release your Docker images in spectacular, no-downtime, blue-green fashion.
How to Use
npm i -g mrm-task-npm-aws
npx mrm npm-aws
Looking for npm scripts for Docker? Go here! Don't know how to create your own AWS ECS Cluster? Go here.
Watch the video: Do More With Less JavaScript
Docker Containers for Static or Angular/React/Vue/etc SPA Websites
docker pull duluca/minimal-nginx-web-server
- Documentation: https://hub.docker.com/r/duluca/minimal-nginx-web-server/
docker pull duluca/minimal-node-web-server
- Documentation: https://hub.docker.com/r/duluca/minimal-node-web-server/
Features
- Cross-Platform: Works on Windows 10 and macOS.
aws:login
: Using your AWS credentials, gets the Docker for your ECS Container Repository and configures your Docker CLI instance to point at your private repository.aws:deploy
: Kicks-off the blue-green deployment your already published image.aws:release
: Points Docker to your private ECS repository, publishes your latest build image and then kicks-off deployment.
Pre-Requisites
- A correctly configured AWS ECS Cluster. Instructions are here.
- On your project, first setup npm scripts for Docker and then come back here.
- Create
.env
file and setAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
- Sample
.env
file:
AWS_ACCESS_KEY_ID=your_own_key_idAWS_SECRET_ACCESS_KEY=your_own_secret_key - Sample
- Install AWS CLI
- Mac:
brew install awscli
- Win:
choco install awscli
- Mac:
- Log in to AWS CLI with your credentials
- Run
aws configure
- You'll need your Access Key ID and Secret Access Key
- Default region name:
us-east-1
- Run
Configuring Package.json in 2-steps
Step 1
Make sure to update
package.json
from when you configured npm scripts for Docker, so that theimageRepo
property has the address of your new ECS repository. In yourpackage.json
file, under the config property, add three new properties using your own values, as shown below:
... "config": , ...
Step 2
Copy & paste these new scripts under the scripts
property in package.json
:
"scripts": ,
Note the duluca/ecs-deploy-fargate blue-green deployment script is a fork of the original silintl/ecs-deploy image with AWS ECS Fargate support with this PR https://github.com/silinternational/ecs-deploy/pull/129 integrated. Once silintl/ecs-deploy merges this change, I recommend using silintl/ecs-deploy for your blue-green deployments.
Running
You're done. Now run your scripts. To build and publish an image you only need to use two of the commands frequently.
npm run docker:debug
: [Test], Build, Tag, Run, Tail and launch your app in a browser to test.npm run aws:release
: Configure Docker with AWS, publish your latest image build and release it on ECS.
Be patient! Things won't work right away. AWS is a complicated beast, however once everything is configured correctly, it is an immensely powerful tool. Go through AWS ECS setup instructions here.
AWS ECS Deploy Permissions
In order to be able to deploy using the scripts provided by npm scripts for AWS ECS
make sure your user is part of an IAM Group that has the following inline policy applied to it.
Note: This may not be complete.