Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.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.AWS_ECS:EC2启动类型配置错误的群集容器实例_Python_Amazon Web Services_Amazon Ec2_Amazon Ecs_Aws Cdk - Fatal编程技术网

Python AWS_CDK.AWS_ECS:EC2启动类型配置错误的群集容器实例

Python AWS_CDK.AWS_ECS:EC2启动类型配置错误的群集容器实例,python,amazon-web-services,amazon-ec2,amazon-ecs,aws-cdk,Python,Amazon Web Services,Amazon Ec2,Amazon Ecs,Aws Cdk,我需要使用下面的代码创建EC2启动类型ecs class ECSStack(cdk.Stack): def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None: super().__init__( scope, construct_id, env=cdk.Environment(

我需要使用下面的代码创建EC2启动类型ecs

class ECSStack(cdk.Stack):

    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(
            scope,
            construct_id,
            env=cdk.Environment(
                account=<MY_ACCOUNT_NO>,
                region=<MY_REGION>
            )
        )

        self.vpc = Vpc.from_lookup(
            self,
            "lookup-vpc",
            vpc_id="vpc-0fd27cbc0cb8c8ed1"
        )
        self.security_group = SecurityGroup.from_lookup(
            self,
            "lookup-security-group",
            security_group_id="sg-0ba340103bfb50fa1"
        )
        self.subnet = Subnet.from_subnet_attributes(
            self,
            "lookup-subnet",
            subnet_id="subnet-0fb04718abce46fe0"
        )

        self.create_cluster()


    def create_cluster(self) -> None:
            self.cluster = Cluster(
                self,
                config.CLUSTER_ID,
                vpc=self.vpc
            )
            Cluster.from_cluster_attributes(
                self,
                "plts-production-cluster_attributes",
                cluster_name=config.CLUSTER_CAPACITY_ID,
                security_groups=[self.security_group],
                vpc=self.vpc
            )
            self.cluster.add_capacity(
                config.CLUSTER_CAPACITY_ID,
                instance_type=InstanceType(config.CLUSTER_CAPACITY_INSTANCE_TYPE),
                key_name=config.SSH_KEY_NAME
            )
环境 CDK CLI版本:1.98.0 模块版本:1.98.0 Node.js版本:12.19.0 操作系统:Windows 10
语言(版本):Python 3.8.2

请不要将代码或错误消息作为截图发布,而是将代码块正确格式化。删除截图并添加代码块
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
cluster = ecs.Cluster(self, "Cluster",
    vpc=vpc
)

# Either add default capacity
cluster.add_capacity("DefaultAutoScalingGroupCapacity",
    instance_type=ec2.InstanceType("t2.xlarge"),
    desired_capacity=3
)

# Or add customized capacity. Be sure to start the Amazon ECS-optimized AMI.
auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    instance_type=ec2.InstanceType("t2.xlarge"),
    machine_image=EcsOptimizedImage.amazon_linux(),
    # Or use Amazon ECS-Optimized Amazon Linux 2 AMI
    # machineImage: EcsOptimizedImage.amazonLinux2(),
    desired_capacity=3
)

cluster.add_auto_scaling_group(auto_scaling_group)
```

If you omit the property `vpc`, the construct will create a new VPC with two AZs.