如何在 AWS CDK 中为 ECS 任务定义指定人类可读的名称?

How to specify human readable name for ECS Task Definition in AWS CDK?

我使用 aws-cdk-lib/aws-ecs-patterns/ApplicationLoadBalancedFargateService class 从 CDK 部署 ECS 服务。

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
});

一切正常,除了我无法取消任务定义名称: BlaBlaBlaCdkStackdevblablablaservicedevTaskDefA258F369

这个垃圾监控仪表板看起来很糟糕。

您能否建议如何为任务定义设置人类可读的名称?

找到,使用taskImageOptions.family字符串,这将设置任务定义名称。

        ...
        memoryLimitMiB: 1024,
        desiredCount: 2,
        taskImageOptions: {
            family: `svc-web-${this.envName}`,
            containerName: `svc-web-${this.envName}`,
            containerPort: 80,
        ...