2

コンテナー データを永続化するために、Docker コンテナーで EFS を使用したいと考えています。ECS タスクの起動タイプは fargate です。タスクを起動すると、次のエラーが表示されます。

ResourceInitializationError: EFS ユーティリティ コマンドを呼び出して EFS ボリュームをセットアップできませんでした: stderr: "fs-xxxxxx.efs.eu-central-1.amazonaws.com" を解決できませんでした - ファイル システム ID が正しいことを確認してください。

私のタスク定義は次のようになります。

locals {
  username = jsondecode(data.aws_secretsmanager_secret_version.wordpress.secret_string)["username"]
  password = jsondecode(data.aws_secretsmanager_secret_version.wordpress.secret_string)["password"]
}

resource "aws_cloudwatch_log_group" "main" {
  name = "/ecs/wordpress-task"
}


resource "aws_ecs_task_definition" "wordpress" {
  family = "wordpress"

  volume {
    name = "wp"
    efs_volume_configuration {
      file_system_id = aws_efs_file_system.wordpress.id
      root_directory = "/wp"
      transit_encryption = "DISABLED"
    }
  }

  volume {
    name = "db"
    efs_volume_configuration {
      file_system_id = aws_efs_file_system.wordpress.id
      root_directory = "/db"
      transit_encryption = "DISABLED"
    }
  }

  network_mode = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  execution_role_arn =  aws_iam_role.ecs_task_execution_role.arn
  task_role_arn = aws_iam_role.ecs_task_role.arn
  cpu = 1024
  memory = 3072

  container_definitions = jsonencode([{
    name = "wordpress"
    image = "wordpress"
    essential = true
    cpu = 256
    memory = 512
    entryPoint = [ "sh", "-c"]
    command = ["ls -la /var/www/html"]
    mountPoints = [{
      sourceVolume = "wp"
      containerPath = "/var/www/html"
      readOnly = false
    }]
    environment = [{
      name = "WORDPRESS_DB_HOST"
      value = "127.0.0.1"}, 
    {
      name = "WORDPRESS_DB_USER"
      value = local.username
    },
    { 
      name = "WORDPRESS_DB_PASSWORD"
      value = local.password
    },
    {
      name = "WORDPRESS_DB_NAME"
      value = "wordpressdb"
    }]
    portMappings = [{
      protocol = "tcp"
      containerPort = 80
      hostPort = 80
    }]
    logConfiguration = {
      logDriver = "awslogs"
      options = {
        awslogs-group         = aws_cloudwatch_log_group.main.name
        awslogs-stream-prefix = "ecs"
        awslogs-region        = "eu-central-1"
      }}
  },
  {
    name = "db"
    image = "mysql"
    cpu = 256
    memory = 512
    essential = true
    environment = [{
      name = "MYSQL_DATABASE"
      value = "wordpressdb"}, 
    {
      name = "MYSQL_USER"
      value = local.username
    },
    {
      name = "MYSQL_PASSWORD"
      value = local.password
    }, 
    {
      name = "MYSQL_RANDOM_ROOT_PASSWORD"
      value = "1"
    }]
    mountPoints = [{
      sourceVolume = "db"
      containerPath = "/var/lib/mysql"
      readOnly = false
    }]
    portMappings = [{
      containerPort = 3306
      hostPort = 3306
    }]
    logConfiguration = {
      logDriver = "awslogs"
      options = {
        awslogs-group         = aws_cloudwatch_log_group.main.name
        awslogs-stream-prefix = "ecs"
        awslogs-region        = "eu-central-1"
      }
  }}
  ])
}

efs システムは eu-central-1 にあり、次のように定義されています。

resource "aws_efs_file_system" "wordpress" {
    creation_token = "wordpress"
}

この問題に関するオンライン リソースは非常にあいまいです。

4

1 に答える 1