Tuesday, 6 August 2013

a nodes journey into the amazon


Node.js + Coffee + Amazon

Here I'm going to run through hosting your Node server on the Elastic Beanstalk

A super quick intro to Elastic Beanstalk: 
Amazon's Elastic Beanstalk is a deployment service that allows you to encapsulate different amazon services to provide a specific server and resource configuration based on your requirements. + There is no extra cost for this service. To find out more read Amazon's AWS Elastic Beanstalk Components

*Note: Beanstalk refers to each service collection as an "Application".

In this "Application", beanstalk will pull in 
Lets get started! ^_^


I am going to uses a directory called "aws" and I will use my Git basics as my server code. This is important as we will be using git to upload our code to beanstalk! In your command-line, go to this "awsdirectory. but we will also need a "package.json" file to tell our node server about our coffee source.

File: package.json
{
"name": "AmazonCoffee",
"version": "0.0.1",
"description": "An example of a nofe.js running CoffeeScript source",
"homepage": "http://www.codemeasandwich.com/2013/08/a-nodes-journey-into-amazon.html",
"scripts": {
   "start": "coffee index.coffee"
 },
"dependencies": {
    "coffee-script": "*"
  }
}

Console ~ Lets stage our files. 
 git add . 

Next we commit our staged file.
Console
 git commit -m "added configuration file "package.json" for Node to run index.coffee" 
You should get something like the following:
 [master (root-commit) 950b29badded configuration file "package.json" for Node to run index.coffee
 1 file changed, 19 insertions(+)

Next comes the real juicy bit! Deploying to AWS Elastic Beanstalk

You will now need to download & install the Elastic Beanstalk Command Line Tool 

Once you have downloaded the zip file. Extract it to your node directory.

Next you will need to add to your systems environmental variables.

Console - Linux: *Remember to match the python folder version with the version of python that you have installed
 export PATH=$PATH:node/AWS-ElasticBeanstalk-CLI-2.5.1/eb/linux/python2.7
On windows you will need to add ";c:\node\AWS-ElasticBeanstalk-CLI-2.5.1\eb\windows\" to your PATH in your Environment Variables. A good step by step can be found at How to set the path and environment variables in Windows

Back in our server AWS folder lets run.

Console
 eb init 
Next you will get:
 Enter your AWS Access Key ID: 
To get your key you can follow my Coffee and S3 tutorial.

With your ID and key in hand, enter your ID.
 Enter your AWS Secret Access Key: 
Now you can pick a region to setup you server
 Select an AWS Elastic Beanstalk service region. 
For me I picked 4) EU West.. just cos!

Next;
 Enter an AWS Elastic Beanstalk application name (auto-generated value is "aws"): 
and

 Enter an AWS Elastic Beanstalk environment name (auto-generated value is "aws-env"): 
Here you can just hit enter and it will use the defaults based on your working directory(highlighted in yellow). 

 Select a solution stack. 
 Available solution stacks are:  
 5) 32bit Amazon Linux running Node.js 
For this I went with option 5. You could pick 6, if you want a 64bit version
Next you will be asked what type of "environment" you want?
 Select an environment type.
 Available environment types are:
 1) LoadBalanced
 2) SingleInstance 

You're best off picking 2) 'Single Instance' as you will only need to 'Load Balanced' with a live site.
 Create an RDS DB Instance? [y/n]: 
We don't need a database right now, so "n"
Next pick a profile.
 Attach an instance profile
1) [Create a default instance profile]
2) [Other instance profile]
or hit enter and lets go with the default. 1

* You can change you Beanstalk configuration, by running the init command again.
For each setting you can just hit Enter to use the previous settings.

lets deploy our server ^_^

 eb start 
 Starting application "aws".
 Would you like to deploy the latest Git commit to your  environment? [y/n]: 
Lets go with "y".. This will take a while.. but you should be getting updates while(Really!) its deploying.

After it's done you'll be given a URL to access your node server. 
 Application is available at " ... .elasticbeanstalk.com". 
If you have any problems let me know ;)

No comments:

Post a comment