EFS on ECS Fargate

Background

  • 10 GB of Docker layer storage
  • An additional 4 GB for volume mounts

Usage

Terraform Example

locals {
# Common tags to be assigned to all resources for this exercise
common_tags = {
Project = "Medium"
Env = terraform.workspace
}
}
resource "aws_efs_file_system" "influxdb" {
tags = merge(local.common_tags, {
Name = "Example-${terraform.workspace}-influxdb"
})
}
resource "aws_efs_mount_target" "influxdb" {
count = length(aws_subnet.public)
file_system_id = aws_efs_file_system.influxdb.id
subnet_id = aws_subnet._[count.index].id
security_groups = [aws_security_group.efs_influxdb_access.id]
}
resource "aws_security_group" "efs_influxdb_access" {
name = "Example-${terraform.workspace}-EFS-influxdb-access"
description = "Allow access to the Influxdb EFS"
vpc_id = aws_vpc._.id
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
security_groups = [ aws_security_group.influxdb_access.id ]
}
tags = local.common_tags
}
resource "aws_ecs_service" "influxdb" {
name = "influxdb"
cluster = aws_ecs_cluster._.id
task_definition = aws_ecs_task_definition.influxdb.arn
desired_count = 1
launch_type = "FARGATE"
platform_version = "1.4.0"
network_configuration {
security_groups = [aws_security_group.influxdb_access.id]
assign_public_ip = true
subnets = aws_subnet._.*.id
}
tags = local.common_tags
}

The secret sauce

resource "aws_ecs_task_definition" "influxdb" {
family = "Example-${terraform.workspace}-influxdb"
container_definitions = data.template_file.influxdb.rendered
task_role_arn = aws_iam_role.influxdb.arn
execution_role_arn = aws_iam_role.influxdb_execution.arn
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = var.influxdb_cpu
memory = var.influxdb_memory
volume {
name = "influxdb-storage"
efs_volume_configuration {
file_system_id = aws_efs_file_system.influxdb.id
}
}
tags = local.common_tags
}
data "template_file" "influxdb" {
template = file("task-definitions/influxdb.tpl")
vars = {
cpu = var.influxdb_cpu
memory = var.influxdb_memory
region = var.aws_region
log_group = aws_cloudwatch_log_group.influxdb.name
}
}
[{
"name": "influxdb",
"image": "influxdb:1.6",
"essential": true,
"cpu": ${cpu},
"memory": ${memory},
"portMappings": [{
"containerPort": 8086,
"hostPort": 8086
}],
"mountPoints": [{
"containerPath": "/var/lib/influxdb",
"sourceVolume": "influxdb-storage"
}],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${log_group}",
"awslogs-region": "${region}",
"awslogs-stream-prefix": "ecs"
}
}
}]

Appendix

--

--

--

CloudSpout.io serves to channel the power of the Cloud for today’s business & tomorrow’s growth.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

WMI Event Consumers: What Are You Missing?

Resolution of Apt-Key Error

Why you should be using Differential Evolution for your optimization problems.

The Beginners Guide To Django User Management and User Authentication Using AllAuth

How to extend Zimbra MailboxListener for an Extension

Implement Type 2 Slowly changing dimension using Apache Nifi

CS373 Fall 2021, Week 9: Nitin Jain

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CloudSpout

CloudSpout

CloudSpout.io serves to channel the power of the Cloud for today’s business & tomorrow’s growth.

More from Medium

Holistic Backend/Cloud Dev

Automation with github actions

GitLab — Taming an Unpleasant one

Github Workflow | How powerful it can get! :P