简体   繁体   中英

AWS CDK, ecs-patterns, ApplicationLoadBalancedFargateService, setting tags

New to CDK, deploying on an account with enforced resource tagging policy. How to set tags on resources? Specifically, how to pass tag values for the ALB created within ApplicationLoadBalancedFargateService construct?

 const service = new ecs_patterns.ApplicationLoadBalancedFargateService(this, "MyService", {
  cluster: cluster,
  cpu: 512,
  memoryLimitMiB: 2048,
  desiredCount: 1,
  publicLoadBalancer: true,
  taskImageOptions: {
    image: ecs.ContainerImage.fromAsset(path.join(__dirname, "..", "..", "docker-hello")),
  },
  propagateTags: PropagatedTagSource.SERVICE
});

Turns out you don't pass tags but add tags on constructs and reference to ALB construct is available as a property of service. And service property "propagateTags" set to SERVICE makes all underlying resources inherit tags. Brilliant.

Tags.of(service.loadBalancer).add("alb", "Special value");
Tags.of(service).add("common", "value");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM