This is the first how-to part of a series that will culminate in setting up time series forecasting using AWS Fargate. The why’s and wherefore’s are discussed here.
This post will walk you through the basics of getting a simple time series analysis function running in AWS Fargate.
Here are a few things required:
- An AWS account
- Docker installed on your local machine
AWS Fargate uses docker containers to run on-demand compute processes. The first step is to create a docker image that can be used by Fargate.
Directory Structure Link to heading
There are two separate sets of code that will be used in this project. The first is the Docker build for Fargate and the next is the Lambda application that we will use to trigger the Fargate task.
So in the project directory go ahead and create 2 sub-directories, fargate
and lambda
.
Setting up the Dockfile Link to heading
First, create a Dockerfile which will be used to build the image to be uploaded to Fargate and paste the following code into the file.
FROM python:3.6
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt6
The first line, FROM python:3.6
tells docker that we want to use the python
docker image which comes with version 3.6.
WORKDIR /app
sets the working directory in the container, this will be where all the code that needs to be run will be placed.
COPY requirements.txt /app/requirements.txt
will copy the file requirements.txt
from the local machine into the container and put it in /app/requirements.txt
, we will create this file soon.
The next line tells the container to install the python libraries listed in requirements.txt
. These libraries will be installed in the container.
Defining the libraries needed Link to heading
In the same directory that Dockerfile
is, create a new file called requirements.txt
.
We will be using the statsmodels
library. It comes with the Holt-Winters
time series model which we will be using to generate forecasts.
We will also need pandas
, scipy
and boto3
. Add the three libraries on separate lines in requirements.txt
.