sparse-intern-71089
05/05/2023, 7:37 AMbrainy-xylophone-11424
05/05/2023, 7:38 AMconst 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,
};