Hello! I am having issues deploying a MySQL conta...
# getting-started
b
Hello! I am having issues deploying a MySQL container on ECS with EFS. I am running into an issue where either the ECS Task can't pull the image from Docker or it cannot find the EFS. Any suggestions on how to fix this? Maybe I am missing something. I attached my code as a reply to prevent chat hogging.
Copy code
const vpc = new awsx.ec2.Vpc(name + "-vpc", {
    cidrBlock: "10.0.0.0/16",
  });
  const securityGroup = new aws.ec2.SecurityGroup(name + "-sg", {
    vpcId: vpc.vpcId,
    egress: [
      {
        fromPort: 0,
        toPort: 0,
        protocol: "-1",
        cidrBlocks: ["0.0.0.0/0"],
        ipv6CidrBlocks: ["::/0"],
      },
    ]
  });
  const cluster = new aws.ecs.Cluster(name + "-cluster", {});

  const fileSystem = new aws.efs.FileSystem(
    name + "-efs",
    {
      encrypted: true,
    },
    {
      dependsOn: cluster,
    }
  );

  const mountTargets = vpc.subnets.apply((subNets) =>
    subNets.map(
      (vpc_subnet, i) => {
        const subnet = new aws.ec2.Subnet(name + "sb" + i, {
          vpcId: vpc.vpcId,
          availabilityZone: vpc_subnet.availabilityZone,
          cidrBlock: "10.0.1.0/24",
        });
        return new aws.efs.MountTarget(`${name}-mt${i}`, {
          fileSystemId: fileSystem.id,
          securityGroups: [securityGroup.id, vpc.vpc.defaultSecurityGroupId],
          subnetId: subnet.id,
        });
      },
      {
        dependsOn: fileSystem,
      }
    )
  );

  const service = new awsx.ecs.FargateService(
    name + "-service",
    {
      cluster: cluster.arn,
      networkConfiguration: {
        subnets: vpc.privateSubnetIds,
        securityGroups: [securityGroup.id, vpc.vpc.defaultSecurityGroupId],
      },
      desiredCount: 1,
      taskDefinitionArgs: {
        container: {
          image: "mysql:8",
          essential: true,
          mountPoints: [
            {
              sourceVolume: "mysql",
              containerPath: "/var/lib/mysql",
              readOnly: false,
            },
          ],
        },
        volumes: [
          {
            name: "mysql",
            efsVolumeConfiguration: {
              fileSystemId: fileSystem.id,
              transitEncryption: "ENABLED",
            },
          },
        ],
      },
    },
    {
      dependsOn: mountTargets,
    }
  );

  return {
    service_id: service.service.id,
  };