如何使用ApplicationloadBalancedFargatesErvice CDK构造为负载平衡器启用删除保护

发布于 2025-01-23 19:30:04 字数 305 浏览 3 评论 0原文

我使用ApplicationLoadalanced FargatesErvice CDK构建体上的ECS群集上创建了一个运行的Fargate服务。

  cluster,
  memoryLimitMiB: 1024,
  desiredCount: 1,
  cpu: 512,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
  },
});

没有实现删除保护的道具。谁能从他的经验中学到?

I have created a Fargate service running on an ECS cluster fronted by an application load balancer using the ApplicationLoadBalancedFargateService CDK construct.

  cluster,
  memoryLimitMiB: 1024,
  desiredCount: 1,
  cpu: 512,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
  },
});

There are no Props for enabling deletion protection. Can anyone tell from his experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2025-01-30 19:30:04

CDK提供的逃生舱口功能是使用Clouformation Drop,如果任何高级构造没有参数。

import { CfnLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";

// Create a load-balanced Fargate service and make it public
var loadBalancedService =
  new ecs_patterns.ApplicationLoadBalancedFargateService(
    this,
    `MyService`,
    {
      cluster: cluster,
      taskImageOptions: {
        image: ecs.ContainerImage.fromRegistry("image"),
        environment: {},
      },
      assignPublicIp: true,
    },
  );

// Get the CloudFormation resource
const cfnLB = loadBalancedService.loadBalancer.node
  .defaultChild as CfnLoadBalancer;
cfnLB.loadBalancerAttributes = [
  {
    key: "deletion_protection.enabled",
    value: "true",
  },

CDK offers the Escape Hatches feature to use Clouformation Props if any High-level construct does not have parameters.

import { CfnLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";

// Create a load-balanced Fargate service and make it public
var loadBalancedService =
  new ecs_patterns.ApplicationLoadBalancedFargateService(
    this,
    `MyService`,
    {
      cluster: cluster,
      taskImageOptions: {
        image: ecs.ContainerImage.fromRegistry("image"),
        environment: {},
      },
      assignPublicIp: true,
    },
  );

// Get the CloudFormation resource
const cfnLB = loadBalancedService.loadBalancer.node
  .defaultChild as CfnLoadBalancer;
cfnLB.loadBalancerAttributes = [
  {
    key: "deletion_protection.enabled",
    value: "true",
  },
紧拥背影 2025-01-30 19:30:04

这相当于 @umeshtyagi在python cdk中的答案:

cfn_lb = self.fargate_service.load_balancer.node.default_child
cfn_lb.load_balancer_attributes = [{"key": "deletion_protection.enabled", "value": "true"}]

This is the equivalent to @UmeshTyagi's answer in Python CDK:

cfn_lb = self.fargate_service.load_balancer.node.default_child
cfn_lb.load_balancer_attributes = [{"key": "deletion_protection.enabled", "value": "true"}]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文