Setting up Docker and Serverless Development Environment in 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.

sudo apt-get update
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.

sudo npm install -g serverless

(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 update
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.

sudo docker run hello-world

(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.

sudo apt-get install python-pip
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.

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'
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.

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
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

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …