In Part 2, set up the Docker image. In this part we will deploy the docker image to AWS and run a time series analysis on it.
Deployment Link to heading
Create teh S3 Bucket Link to heading
Before we can go ahead and run the image, create the S3 bucket called ecsforecast
.
Navigate to the IAM console and create a role called ecsTaskExecutionRole
if it does not yet exist.
Add the AmazonECSTaskExecutionRolePolicy
.
Add another policy that gives the role access to the S3 buckets and execution of the Fargate tasks.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::farcaster*/*"
},
{
"Effect": "Allow",
"Action": [
"ecs:DiscoverPollEndpoint",
"ecs:CreateCluster",
"ecs:DeleteService",
"ecs:DescribeTaskDefinition",
"ecs:ListServices",
"ecs:DeregisterTaskDefinition",
"ecs:UpdateService",
"ecs:CreateService",
"ecs:ListTaskDefinitionFamilies",
"ecs:RegisterTaskDefinition",
"ecs:DescribeServices",
"ecs:ListTaskDefinitions",
"ecs:ListClusters"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ecs:*",
"Resource": [
"arn:aws:ecs:::cluster/*",
"arn:aws:ecs:*:*:task-definition/*:*",
"arn:aws:ecs:*:*:task/*",
"arn:aws:ecs:*:*:container-instance/*"
]
}
]
}
Create ECR Link to heading
In order for the tasks to run, AWS needs to be able to access the docker image built previously.
Navigate to the ECS console, and go to Repositories.
Create a repository called ecsforecast
.
Navigate into the repository, follow the instructions to push you docker image to the repository. There will be a button called View push commands
on the top right corner. Once done you should have your image in the ECR repository.
Note down the Image URL
, we will need it later.
Create Task Definition Link to heading
In the ECS Console, navigate to Task Definitions.
Click Create new Task Definition
.
Select Fargate
as the launch type configuration and click next.
Fill in a name for the task definition, it should be ecsforecast
. Select the role created earlier for the Task Role
and Task Execution Role
options.
Set the memory and vCPU configurations as you see fit. The lowest options should be enough.
Click Add Container
in the Container Definitions section.
Give the container a name and paste the image URL for the image pushed to ECR earlier.
Use the rest of the default settings and click Add
Leave the default settings for the rest of the task definition and click Create
.
Create the Cluster Link to heading
Navigate to Clusters
and click Create Cluster
.
The cluster template should be Networking Only
.
Give the cluster a name, ecsforecast
and create it.
You should now be able to run the task from the console.
Assuming that you have a file called <some path>/input.json
in the S3 bucket, go to the task definition and run the task.
Select the cluster, subnet and VPC, and change the Container Overrides with the relevant ENV variables, then run the task.
It will take a short time for AWS to spin up the container and run the task. Once done, you will have a file in the same S3 bucket called <some path>/output.json
.