1

I use aws-cdk-lib/aws-ecs-patterns/ApplicationLoadBalancedFargateService class to deploy ECS Service from CDK.

const service = new ecs_patterns.ApplicationLoadBalancedFargateService(this, `service-${envName}`, {
    serviceName: `svc-${this.envName}`,
    loadBalancerName: `svc-alb-${this.envName}`,
    targetProtocol: ApplicationProtocol.HTTP,
    protocol: ApplicationProtocol.HTTPS,
    domainName: "svc.example.com",
    redirectHTTP: true,
    domainZone: r53.HostedZone.fromHostedZoneAttributes(this, `svc-zone-${this.envName}`, { ... }),
    certificate: acm.Certificate.fromCertificateArn(this, `svc-cert-${this.envName}`, "arn:aws:acm:xxxxxx"),
    cluster: mainECSCluster,
    cpu: 512,
    memoryLimitMiB: 1024,
    desiredCount: 2,
    taskImageOptions: {
        containerName: `svc-web-${this.envName}`,
        containerPort: 80,
        image: ecs.ContainerImage.fromEcrRepository(repo),
        enableLogging: true,
        logDriver: ecs.LogDrivers.firelens({ ... }),
        secrets: this.buildAppEnvironment({ ... }),
    },
    publicLoadBalancer: true
});

All works well except I cannot unsee the task definition names: BlaBlaBlaCdkStackdevblablablaservicedevTaskDefA258F369

Monitoring dashboards look terrible with this trash.

Can you suggest how to set human-readable names for task definitions?

Andrew
  • 3,696
  • 3
  • 40
  • 71

1 Answers1

4

Found, use taskImageOptions.family string, this will set the task definition name.

        ...
        memoryLimitMiB: 1024,
        desiredCount: 2,
        taskImageOptions: {
            family: `svc-web-${this.envName}`,
            containerName: `svc-web-${this.envName}`,
            containerPort: 80,
        ...
Andrew
  • 3,696
  • 3
  • 40
  • 71