EBS Volume for ECS Service Container for Google Lighthouse Server

0

Good day.

I hope you all are having a good day.

We run all of our workloads in a ECS cluster on containers, backed my EC2 instances in an Auto Scaling Group. Now I need to deploy a new service - a Google Lighthouse server and that's fine, but we need persistent storage to store the reports.

I run all of our deployments and manage the infrastructure with Terraform. The challenge I have is that I want to deploy a standalone EBS volume that needs to be used by the new ECS service container. I've been following this guide here - https://rewind.com/blog/ebs-volumes-with-ecs-terraform/ - and I've been battling with this for more than a month now. I just cannot get it to work.

When I create the EBS volume and I try to deploy the task definition referencing that volume, Terraform simply tells me "ClientException: Unknown volume 'ecs-ebs-volume'" even though an EBS volume with that name exists.

My Auto Scaling Group does have the permissions for EBS management.

Please see below my ECS service block and task definition (some details have been changed for privacy reasons):

ECS Services Array...
{
      name = "lighthouse"
      security_groups = ["${module.auto_scaling_group.auto_scaling_group_security_group_id}"]
      vpc_subnets = module.vpc.vpc_public_subnets
      assign_public_ip = false
      memory_target_metric = 90
      deployment_maximum_percent = 200
      deployment_minimum_healthy_percent = 100
      autoscaling_min_capacity = 1
      desired_count = 1
      autoscaling_max_capacity = 2
      target_group_arn = module.application_load_balancer.target_group_arn[6]
      enable_execute_command = true
      tasks = {
        family         = "lighthouse-staging"
        containerPort  = 9001
        hostPort       = var.host_service_port["lighthouse"]
        source_volume  = "ecs-ebs-volume"
        container_path = "/mnt/ecs-ebs-volume"
        container_definitions = templatefile("../modules/task-definitions/lighthouse.json.tpl", {
          hostPort       = var.host_service_port["lighthouse"]
          source_volume  = "ecs-ebs-volume"
          container_path = "/mnt/ecs-ebs-volume"
        })
      }
    }
[
  {
    "name": "lighthouse-staging",
    "image": "account-id.dkr.ecr.region.amazonaws.com/lighthouse:staging",
    "cpu": 0,
    "memory": 1024,
    "essential": true,
    "portMappings": [
        {
        "name"          : "lighthouse-staging-9001-tcp",
        "containerPort" : 9001,
        "hostPort"      : ${hostPort}, 
        "protocol"      : "tcp"
        }
    ],
    "mountPoints": [
      {
        "sourceVolume": "${source_volume}",
        "containerPath": "${container_path}"
      }
    ],
    "volume": {
      "name": "ecs_ebs_volume",
      "docker_volume_configuration": {
        "scope": "shared",
        "autoprovision": true,
        "driver": "rexray/ebs",
        "driver_opts": {
          "volumetype": "gp3",
          "size": 20
        }
      }
    },
    "environment": [],
    "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/lighthouse-staging",
          "awslogs-region": "region",
          "awslogs-stream-prefix": "ecs"
        }
    }
  }
]

Please forgive me if anything looks wrong or off. I'm still a Terraform novice.

I'd appreciate any suggestions or feedback immensely.

Thank you in advance, Nic

2 Answers
1
Accepted Answer

Hello,

As far the blog post is concerned, I believe it's quite outdated. AWS announced in January that Amazon ECS supports an integration with Amazon Elastic Block Store (Amazon EBS), allowing you to easily provision and attach EBS volumes to Amazon ECS tasks running on both AWS Fargate and Amazon Elastic Cloud Compute (EC2) using Amazon ECS APIs.

Blog Post

Announcement

There is open issue in Terraform GitHub to release this feature:

https://discuss.hashicorp.com/t/ebs-volume-integration-with-ecs-fargate/66385/2

https://github.com/hashicorp/terraform-provider-aws/issues/35279

https://github.com/hashicorp/terraform-provider-aws/pull/37019

Meanwhile you could use AWS Cloudformation to provision Cluster, Task definition, and service that is mounted with EBS volumes. Specify Amazon EBS volume configuration at deployment

Here are few documentation that might be helpful.

  1. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specify-ebs-config.html
  2. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-volume.html
  3. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-servicevolumeconfiguration.html
profile picture
EXPERT
answered 5 months ago
profile pictureAWS
EXPERT
iBehr
reviewed 5 months ago
0

Thank you for the suggestions.

Nic
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions