AnyCloud
Search…
Deploy a Node.js HTTP server to AWS
In this tutorial we will deploy the sample express Node.js HTTP server in your own AWS account with AnyCloud.
All the code can be found in this template repository which you can use to create a new repository for your AnyCloud project.

Enable programmatic AWS access to VMs for AnyCloud

1) Create a new IAM user in your AWS account using their console/UI as described here.
2) Create a new access key under that IAM user using their console/UI as described here.
3) Enable programmatic access for that IAM user, and attach the built-in AmazonEC2FullAccesspolicy to it as described here.
4) Take the accessKeyId and secretAccessKey from step 2 and create AWS Credentials stored locally at ~/.anycloud/credentials.json only.
You will need to pick a name or alias for the Credentials. The default value will be aws. In this example, we will call it mystartup-aws.
1
$ anycloud credentials new
2
? Pick cloud provider for the new credentials ›
3
❯ AWS
4
GCP
5
Azure
6
Name for new Credentials: mystartup-aws
7
AWS Access Key ID: ******************
8
AWS Secret Access Key: ******************
9
Successfully created "mystartup-aws" Credentials
Copied!

Configure your project

1) Initialize a git repository
1
git init
2
git add -A
3
git commit -m "Initial commit"
Copied!
2) Initialize your package.json and install express
1
npm init
2
npm install express --save
Copied!
3) Define an HTTP server listening on port 8088 in an index.js file
1
const express = require('express')
2
const app = express()
3
const port = 8088
4
5
app.get('/', (req, res) => {
6
res.send('Hello World!')
7
})
8
9
app.listen(port, () => {
10
console.log(`Example app listening at http://localhost:${port}`)
11
})
Copied!
4) Define the Dockerfile
1
FROM node:lts
2
3
COPY . .
4
5
RUN npm install
6
CMD node index.js
Copied!
5) Test the Dockerfile locally by installing Docker Desktop, building the Docker image and then running the server within the container
1
$ docker build -t anycloud/app .
2
$ docker run -p 8088:8088 -d anycloud/app:latest
3
$ curl localhost:8088
Copied!
Which should return Hello World!
6) Use the AnyCloud CLI to create an anycloud.json file in the project directory and define a Deploy Config.
You will need to pick a name, or alias, for the Deploy Config. The default value will be staging. You will also need to associate Credentials to this Deploy Config.
1
$ anycloud config new
2
? Name for new Deploy Config › staging
3
? Pick Credentials to use ›
4
❯ mystartup-aws
5
Create new Credentials
6
? Do you want to choose a specific region for this Deploy Config? › y
7
? Region name › us-east-1
8
? Do you want to select which virtual machine type to use for this Deploy Config? › y
9
? Virtual Machine Type › t2.micro
10
? Do you want to add another region to this Deploy Config? › n
11
? Minimum number of VMs per region or cloud › 1
12
? Would you like to define a maximum number of VMs? › n
13
Successfully created "staging" Deploy Config.
Copied!
7) Make sure all of the changes in the git repo are committed or they won't be deployed.

Deploy an App

1) Make sure you installed the AnyCloud CLI. Now deploy your server to your AWS account using the AnyCloud CLI.
1
$ anycloud new
2
? Pick Deploy Config for App ›
3
❯ staging
4
? Optional App name ›
5
▇ Creating new App
Copied!
It might take a few minutes for your App to start while the virtual machine is provisioned and upgraded.
2) Check the status of your App
1
$ anycloud list
2
Apps deployed:
3
4
┌────────────────┬────────────────────────────────────────┬───────────────┬──────┬────────┐
5
│ App ID │ Url │ Deploy Config │ Size │ Status │
6
├────────────────┼────────────────────────────────────────┼───────────────┼──────┼────────┤
7
│ crimson-tick-5 │ https://crimson-tick-5.anycloudapp.com │ staging │ 1 │ up │
8
└────────────────┴────────────────────────────────────────┴───────────────┴──────┴────────┘
9
10
Deploy Configs used:
11
12
┌───────────────┬───────────┬───────────┐
13
│ Deploy Config │ Region │ VM Type │
14
├───────────────┼───────────┼───────────┤
15
│ staging │ us-east-1 │ t2.micro │
16
└───────────────┴───────────┴───────────┘
Copied!
3) The size of your App represents the number of virtual machines used to back your App. Apps scale elastically based on request load automatically. Now curl your AnyCloud App!
1
$ curl https://crimson-tick-5.anycloudapp.com
Copied!
Which should return Hello World!
4) Terminate your AnyCloud App when you no longer need it
1
anycloud terminate
2
? Pick App to terminate ›
3
❯ crimson-tick-5
Copied!
Last modified 5mo ago