cloudmason
v1.0.10
Published
Set up an AWS organization from scratch and deploy a static site or AMI-based EC2 application in just 4 commands.
Downloads
293
Readme
Set up an AWS organization from scratch and deploy a static site or AMI-based EC2 application in just 4 commands.
The tool will handle everything from obtaining ACM certificates to building AMIs and deploying cloudformation stacks.
Can be used as a command line tool, or in a CI/CD pipeline.
Contents
Installation
Be sure to use the -g flag to install globally.
npm install -g cloudmason
Quick Start
Get an Ec2 nodejs app up and running in 4 commands.
- Prereqs
- Open an AWS account
- Download and set up the AWS CLI (or just set your AWS credentials with enviroment variables)
- Ensure you have a domain to deploy apps to
- Make sure you have nodejs version 18+ installed
- Install the cloudmason CLI
npm install -g cloudmason
- Run the following command to set up your org:
mason init-org -name MyOrg -region us-east-1
- Set up a Local App Template
- Get a sample nodejs app template:
mason starter -p ./myDesktop/MyFirstApp -type asg -l node
- Get a sample nodejs app template:
- Add an App
mason new-app -name MyFirstApp -type asg
mason new-instance -app MyFirstApp -domain myfirstapp.com -region us-east-2 -admin [email protected]
mason update-app -app MyFirstApp -v 1.0 -path ./myDesktop/HelloWorld
mason list-apps
- Launch it
mason launch -app MyFirstApp -v 1.0 -domain myfirstapp.com
mason inspect -app MyFirstApp -domain myfirstapp.com -boot
- Review It
- Visit the domain you specified. You'll see a login page.
- Check the email address you specified for a temp password. Use it to log in.
- After logging in, you'll see a "Hello World" page.
All Together
npm install -g cloudmason
mason init-org -name MyOrg -region us-east-1
mason starter -p ./myDesktop/MyFirstApp -type asg -l node
mason new-app -name MyFirstApp -type asg
mason new-instance -app MyFirstApp -domain myfirstapp.com -region us-east-2 -admin [email protected]
mason update-app -app MyFirstApp -v 1.0 -path ./myDesktop/MyFirstApp
mason launch -app MyFirstApp -v 1.0 -domain myfirstapp.com
mason inspect -app MyFirstApp -domain myfirstapp.com -boot
IMPORTANT!!!
- THIS APP DEPLOYS EC2 INSTANCES THAT ARE NOT FREE! IT WILL RESULT IN AWS CHARGES!
- Make sure to run
delete-instance
when you're done to avoid major surprises - update-app will build an AMI, which may not be immediately available. Leave a few minutes between running update-app and launch
- Your web application must serve on localhost:8080
- Use
inspect
! It will return all console output of your application - very useful for debugging
Commands
Run mason [command] -<options>
| Command | Description | | ---------------------------- | ------------------------------ | | init-org | Set up a new organization | | set-org | Set default org to an existing org | | new-app | Create a new application | | new-instance | Create a new instance of an application | | update-app | Update the code and/or stack of an app version | | launch | Deploy an app version to an instance | | inspect | Get cloudformation stack status and boot logs for an instance | | starter | Get a starter template for a specified architecture type | | delete-instance | Delete an instance | | delete-app | Delete an app | | update-stack | Update cloudformation stack | | list-apps | List all apps |
init-org
mason init-org -name -domain -region
Sets up base infrastructure in a new AWS organization. This command should only be run once. To set up the tool with an existing org, use set-org.
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | name | Y | String | Unique org Name. Letters only, no spaces | | domain | Y | Valid domain | A base domain to use for core resources (e.g., cmason.io) | | region | Y | AWS Region | Default AWS region for core resources (e.g., us-east-1) |
What it does
- Retrieves the default VPC ID
- Deploys a basic org infra stack
- S3 Bucket + policies for infra resources at
infra.[domain]
- IAM Role, Instance Profile, and Security Group for Ec2 build agent
- SSM Parameters for oprg name, domain, instance profile, and security group
- S3 Bucket + policies for infra resources at
new-app
mason new-app -name -type -node -py
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | name | Y | String | Application name. Letters only | | type | Y | Application Type | (Application architecture)[##Architectures]. See below for options. | | node | n | Number | Version of nodejs to install on the base AMI. If set, app will run using nodejs | | py | n | Number | Version of python to install on the base AMI. If set, app will run using python |
Architecture Options
- asg: autoscaling group
- static: static site
Examples
mason new-app -name MyFirstApp -type asg -node
What it does
- Builds a cloudformation stack with the appropriate boot script for nodejs or python
- Uploads the cloudformation template to the S3 infrastructure bucket
- Records the app name, type, and other key detail in SSM params
new-instance
mason new-instance -app -name -domain -region -admin -max -ins -env
Creates a new instance in a specified region. An instance is a deployment of an application. For example, MyFirstApp could have a test, UAT, and prod instance in us-east-1,us-east-2,and us-west-1.
Use -admin to specify the first admin user who will have access to set up other users.
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | app | Y | string | Name of existing application | | name | Y | string | Instance name (ex., test, uat, etc). Letters only | | domain | Y | string | Name of a subdomain or domain to deploy behind | | region | Y | AWS region | region to deploy the instance in | | admin | Y | email | email adress of first admin user | | max | N | int | Maximum number of Ec2 instance to allow in the ASG. Higher number will result in better performance but possibly higher charges. Minimum is 2 to allow for proper refresh. | | ins | N | string | Ec2 instance type. Default is t3.small | | env | N | string | Enviroment (dev,test,prod). This value will be passed to the application. |
Examples
mason new-app -name MyFirstApp -type asg -node
mason new-instance -app MyFirstApp -name uat -domain test.cmason.io -region us-east-2
mason new-instance -app MyFirstApp -name beta -domain beta.cmason.io -region us-west-1
What it does
- Requests an ACM certificate for the domain if none exists (for HTTPS)
- Gets the default VPC ID and Subnets for the target region
- Saves deployment params to SSM for use when deploying the cloud formation template:
- ACM Certificate ID
- VPC Id
- Subnets and hosted zone ID
update-app
mason update -app -v -path
Updates the code for the specified application. This command will build a new AMI and update cloudformation stacks to point to the new AMI. Path must lead to the root folder of your application. The bootscript will run with that directory as the root.
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | app | Y | string | Name of the existing app to update | | v | Y | number | Version number to update | | path | Y | Path to a folder or zip file containing the updated app code |
Examples
mason update -app MyFirstApp -v 1.1 -path ./myfirstapp/src -stack ./myfirstapp/stack.json
What it does
- Zips the folder (if not already zipped)
- Updates the cloudformation stack.yml file and uploads to S3
- Identifies the appropriate AWS Linux AMI ID for the base region
- Launches an EC2 instance, waits until it's ready, and then builds an AMI with the updated code package
- Terminates the EC2 instance
- Updates SSM with the updated AMI ID and build number
launch
mason launch -app -v -i
Launches a specific version of an application to an instance. For example, launch (deploy) MyFirstApp version 1.2 to test.cmason.io.
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | app | Y | string | Name of existing application to launch | | v | Y | number | Version of the app to launch | | i | Y | string | Name of the instance to deploy to |
Examples
mason new-instance -app MyFirstApp -name uat -domain test.cmason.io -region us-east-2
mason update -app MyFirstApp -v 1.1 -path ./myfirstapp/src -stack ./myfirstapp/stack.jso
mason launch -app MyFirstApp -v 1.1 -i uat
What it does
- Copies the AMI version created in the
update
command to the instance region - Deploys the updated cloudformation stack
update-stack
mason update-stack -app -v -default -stack
Updates the default cloudformation template, or updates the template for a specific version.
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | app | Y | string | Name of the app to update | | stack | Y | path | File path to updated cloudformation template | | -v | N | number | Version number to update. Leave blank to update the default template | | -default | flag | Include this flag to update the default cloudformation template for the app |
Examples
Update version 5 with a new stack
mason update-stack -app MyFirstApp -v 1.0 -stack ../myfirstapp/stack.json
Update the default cloduformation template for all future versions
mason update-stack -app MyFirstApp -default -stack ../myfirstapp/stack.json
What it does
- Uploads the specified stack file to S3
inspect
mason inspect -app -domain [-run or -boot]
Get stack status and EC2 console logs for an instance. Useful for debugging issues with application boot up. Console output will
To get run logs, the application must write logs to S3 in the logs/run folder. See the starter nodejs app for an example.
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | -app | Y | string | App name | | -domain | Y | string | Domain to inspect | | -boot | N | null | If included, returns logs from the instance start up | | -run | N | null | If included, returns run logs stored by the application in the s3 bucket at logs/run/* |
Examples
mason inspect -app MyFirstApp -domain myfirstapp.com
starter
mason starter -type -l -path
Sets up a starter application template for the specified architecture and language
Params
| Parameter | Required | Type | Description | | -------------- | ------------ | ---------------- | ---------------------------- | | -type | Y | string | Architecture of the application (asg, static, etc) | | -p | Y | string | Path to output the project to | | -l | Y | string | Language. py or node |
Examples
mason starter -type asg -l node -path ../myfirstapp