Setting up Docker and Serverless Development Environment in Ubuntu
- By : Mydatahack
- Category : Infrastructure, Installation and Configuration
- Tags: AWS Lambda, Docker, Linux, Node.js, Python, Serverless, Ubuntu
Docker and Serverless do not work well with Windows. I have tried so many different ways to make them work, to no avail. My solution is to use an Ubuntu virtual machine. I primarily use those frameworks for AWS lambda developments with both Python and Node.js. Here is how I set up my environment with Ubuntu 16.0.4 LTS.
(1) Install Python 3.6
You first need to install Python 3.6 for your user. I create virtual environment for each function depending on what libraries are needed. We covered this step in the previous post. Here is the instruction: How to Install Python 3 and Create Virtual Environment in Ubuntu.
(2) Install Node.js 8
Execute the commands below. Make sure that you have sudo access.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install npm --global
(3) Install serverless
Serverless works on Node. Installation is simple. See further information here.
(4) Install Docker
Using Docker with Linux and Mac is far easier than Windows. Once you install it, there is no hustle. It just works. See further information here.
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
Make sure that your Docker is running by executing the hello world container.
(5) Install AWS CLI and Configure it
Serverless uses the credentials configured in AWS CLI. To install AWS CLI, you should use the OS python. You first need to install and upgrade pip as AWS CLI installation for Linux uses pip. See here for details.
pip install –-upgrade pip
pip install awscli --upgrade --user
aws configure
Setting Up Development Environment
To have a good development environment for Python and Node, let’s install Visual Studio Code and Google Chrome.
Install Visual Studio Code
Once it is installed, type code in the terminal to start it.
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
Install Google Chrome
Once it is installed, type google-chrome in the terminal to start the browser.
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update
sudo apt-get install google-chrome-stable
Next Step
Your environment is ready now. Let’s try to do the deployment exercise: How to Deploy Python Lambda Function with Serverless in AWS