使用Terraform-can连接的AWS Fargate上的EFS

发布于 2025-01-26 16:05:47 字数 2032 浏览 4 评论 0原文

美好的一天,

我从ECS Fargate连接到EFS模块时遇到了问题。一切都建在Terraform中。以下是相关文件:

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]
}

卷中的ECS TAK定义


  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"
    }
  }

任务定义:

 {
    "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": []
  },

是否有人遇到过此方法 /对如何解决的想法?在日志中,似乎我们的数据库无法连接,因此停止。

更新 具体问题:我们运行了3个parrall任务,其中只有一个要连接到ECS。我们没有从此特定任务中获得日志,从其他两个任务中,我们得到无法连接到Postgres DB,重试...

足够重试后,我们会得到错误: ResourceInitializationerror:无法调用EFS UTILS命令来设置EFS卷:STDERR:无法解决“ FS-0F2315B76C221163F.EFS.US-EATS.US-EATS-1.AMAZONAWS.COM.AMAZONAWS.COM” - 检查您的文件系统ID是否正确。有关更多详细信息,请参见https://docs.aws.amazon.com/console/efs/mount-dns-name。 :失败的EFS UTILS命令执行;代码:1

我不知道为什么我们不使用RDS;这是我吞噬的建筑,我是Infra游戏的新手。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文