'EFS on AWS fargate using Terraform- Can't connected

Good day,

I'm having issues connecting to my EFS module from ECS fargate. Everything is built in Terraform. Here are the relevent files:

efs.tf

resource "aws_efs_file_system" "efs" {
    creation_token = "meltano-efs-file-system"
    tags = {
        Name = "meltano-efs-file-system"
    }
}

resource "aws_efs_mount_target" "mount" {
  count           = length(data.aws_subnet_ids.private.ids)
  file_system_id  = aws_efs_file_system.efs.id
  subnet_id       = tolist(data.aws_subnet_ids.private.ids)[count.index]
  security_groups = [data.aws_security_group.default.id]
}

Volume in ecs tak definitions


  volume {
    name = "meltano-system-db-volume"
    efs_volume_configuration {
      file_system_id     = aws_efs_file_system.efs.id
      root_directory     = "/meltano-system-db"
      transit_encryption = "ENABLED"
    }
  }

Task definition:

 {
    "name": "meltano-system-db",
    "image": "postgres",
    "cpu": XXX,
    "memory": XXX,
    "essential": true,
    "portMappings": [
      {
        "hostPort": XXX,
        "protocol": "XXX",
        "containerPort": XXX
      }
    ]
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "${aws_cloudwatch_meltano_system_db_log_group_name}",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "ecs"
      }
    },
    "mountPoints": [
      {
        "sourceVolume": "meltano-system-db-volume",
        "containerPath": "/var/lib/postgresql/data"
      }
    ],
    "volumesFrom": []
  },

Has anyone ever encountered this / have any ideas on how to solve? In the logs, it simply seems like our database can't connect, so it stops.

Update Specific issue: We have 3 parralel tasks running, only one of which we want to connect to ECS. We get no logs from this specific task, and from the other 2 we get could not connect to postgres db, retrying ...

After enough retries, we would get the error: ResourceInitializationError: failed to invoke EFS utils commands to set up EFS volumes: stderr: Failed to resolve "fs-0f2315b76c221163f.efs.us-east-1.amazonaws.com" - check that your file system ID is correct. See https://docs.aws.amazon.com/console/efs/mount-dns-name for more detail. : unsuccessful EFS utils command execution; code: 1

I don't know why we are not using RDS; this is an architecture that I inherted, and I'm quite new to the infra game.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source