Setup virtual machine for Amazon Web Services CLI, Local DynamoDB and Serverless Framework

AWS Virtual Machine

If your host machine is not a linux-based OS, please download VirtualBox and Vagrant to setup a Virtual Linux Host OS.

This guide will be used to install and config docker on Macbook with a Virtual Linux Host OS of Ubuntu/trusty (VirtualBox+Vagrant). I suggest to use iTerm for terminal replacement.

Setup Virtual Machine

  • Step 1: Install Virtual Box - version 4.3.30 (https://www.virtualbox.org/wiki/Download_Old_Builds_4_3)

  • Step 2: Install Vagrant 1.7.4 (https://www.vagrantup.com/downloads.html)

  • Step 3: Create a folder for virtual machines
    mkdir ~/VMS
    mkdir ~/VMS/aws
    
  • Step 4: Create an Ubuntu virtual machine
cd VMS/aws
vagrant init ubuntu/trusty64; vagrant up --provider virtualbox
  • Step 5: Prepare folder structure
Source code on my laptop: ~/Source

DevOps on my laptop: ~/DevOps (please clone the source from https://github.com/nganhtuan63/DevOps)

Virtual Machines on my laptop: ~/VMS
  • Step 6: Edit the Vagrantfile to config virtual machine

Setup the IP Address for the guest VM. I will use the address 192.168.33.99

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"

Share additional folders to the guest VM

config.vm.synced_folder "~/Source", "/var/www/html", :mount_options => ['dmode=777', 'fmode=777']
config.vm.synced_folder "~/DevOps", "/Devops"

Increase memory for guest VM for 3GB Ram

config.vm.provider "virtualbox" do |vb|
  vb.memory = "3072"
end

Reload vagrant to apply new config

vagrant reload

Setup NodeJS, Java Runtime and AWS CLI

  • Step 1: Log in to the guest VM and switch to root user
cd ~/VMS/aws
vagrant up
vagrant ssh

When you are inside the virtual machine, switch to root user

sudo -s
  • Step 2: Install NodeJS and Java Runtime

Update Ubuntu

apt-get update

Install NodeJS

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

Install Java Runtime

sudo apt-get install default-jre
  • Step 3: Install PIP
cd /tmp
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
  • Step 4: Install AWS CLI
sudo pip install awscli
sudo pip install --upgrade awscli
  • Step 5: Setup default profile for AWS Cli
aws configure

If you want to configure for another profile, you should add this param to above command

aws configure --profile name_of_the_profile

You will be asked to supply your AWS Access Key ID and Secret Access Key. You need to create AWS user and assign role to that user in AWS Console online.

alt text

AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text

Note: Above info is just sample data.

Your AWS Credentials and Config are saved at ~/.aws/credentials and ~/.aws/config

Learn more at: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

AWS Security Best Practices: https://evidentio.squarespace.com/blog/2015/2/12/top-10-aws-security-best-practices-1-disable-root-account-api-access-key

Setup Local DynamoDB

  • Step 1: Download DynamoDB and Install DynamoDB run at port 6868
cd /bin
wget http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz
mkdir dynamodb
tar -xf dynamodb_local_latest.tar.gz -C dynamodb
cd dynamodb
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 6868

(You can set your own port to run local DynamoDB instead of above port)

  • Step 2: Check local DynamoDB work

Visit http://192.168.33.10:6868/shell (Use IP of your virtual machine)

alt text

Setup Serverless

  • Install NodeJS and NPM
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install npm

  • Install The Serverless Framework via npm: (requires Node V4)
npm install serverless -g

Setup Time for preventing issues with signatures of making requests to Amazon

sudo ntpdate time.nist.gov
  • Update the Serverless Framework to a verion (v0.5 for example)

If you don’t have git, install it first

apt-get update
apt-get install git
npm install -g git://github.com/serverless/serverless.git#v0.5

That’s it. Happy coding and Feel free to contact me.

Written on February 19, 2016