Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python AWS CDK如何覆盖自动缩放组中的默认启动配置?_Python_Amazon Web Services_Autoscaling_Aws Cdk - Fatal编程技术网

Python AWS CDK如何覆盖自动缩放组中的默认启动配置?

Python AWS CDK如何覆盖自动缩放组中的默认启动配置?,python,amazon-web-services,autoscaling,aws-cdk,Python,Amazon Web Services,Autoscaling,Aws Cdk,嗨,我在AWS CDK上工作。我正在创建ECS。我已经创建了自动缩放组,如下所示 autoScallingGroup=asg.AutoScalingGroup(self, id = "auto scalling", vpc= vpc, machine_image=ecs.EcsOptimizedImage.amazon_linux(), desired_capacity=1, key_name="mws-location", max_capacity=1, min_capacity=1, ins

嗨,我在AWS CDK上工作。我正在创建ECS。我已经创建了自动缩放组,如下所示

autoScallingGroup=asg.AutoScalingGroup(self, id = "auto scalling", vpc= vpc, machine_image=ecs.EcsOptimizedImage.amazon_linux(), desired_capacity=1, key_name="mws-location", max_capacity=1, min_capacity=1, instance_type=ec2.InstanceType("t2.xlarge"))
这也将生成默认的启动配置。我想为这个自动缩放组编写我自己的启动配置


有人能帮我修一下吗?任何帮助都将不胜感激。谢谢

在CDK中没有创建启动配置的特定构造。但是,您可以通过将参数传递给aws_autoscaling.AutoScalingGroup构造函数来构造一个

您需要指定AutoScalingGroup类的以下属性:

  • 角色
  • 实例类型
  • 关键字名称
  • 机器图像
  • 用户数据
  • 关联\u公共\u ip\u地址
  • 块设备
您还可以使用
add\u security\u group()
函数添加安全组

例如,如果要将用户数据添加到LaunchConfig:

userdata = ec2.UserData.for_linux(shebang="#!/bin/bash -xe")
userdata.add_commands(
         "echo '======================================================='",
         "echo \"ECS_CLUSTER=${MWSServiceCluster}\" >> /etc/ecs/ecs.config"
)

asg = autoscaling.AutoScalingGroup(
        self,
        "asg-identifier",
        ...
        user_data=userdata,
)

谢谢如何指定用户数据?我有这样的userdata='Fn::Base64:!潜艇|#!/bin/bash-xe echo“=========================================================================================================================================================echo ECS_CLUSTER=${mwservicecluster}>/etc/ECS/ECS.config'我需要创建aws_cdk.aws_ec2.UserData结构吗?是的,我已经用我拥有的示例配置数据更新了我的答案。ImageHi(当我写云形成时)。这里我如何指定?machine\u image=ec2.AmazonLinuxImage()。查看模块文档中的一些示例: