通过CDK配置EC2实例连接

0

【以下的问题经过翻译处理】 我有一个包括Elastic Beanstalk环境的CDK部署。我想将Beanstalk ASG中的EC2实例移动到私有子网,同时允许通过EC2实例连接进行SSH。我知道这是可能的,基于此AWS博客条目和这个LinkedIn文章,但我很难正确配置事物。

我的VPC定义如下:

vpc = aws_ec2.Vpc(
    self,
    "Vpc",
    vpc_name="vpc_name",
    max_azs=4,
    subnet_configuration=[
        aws_ec2.SubnetConfiguration(
            name="Public",
            subnet_type=aws_ec2.SubnetType.PUBLIC,
        ),
        aws_ec2.SubnetConfiguration(
            name="Egress",
            subnet_type=aws_ec2.SubnetType.PRIVATE_WITH_EGRESS,
        ),
        aws_ec2.SubnetConfiguration(
            name="Isolated",
            subnet_type=aws_ec2.SubnetType.PRIVATE_ISOLATED,
        ),
    ],
)

我有一个安全组看起来像这样:

self.eb_security_group = aws_ec2.SecurityGroup(
    scope,
    "SecurityGroup",
    vpc=self.vpc,
)
self.eb_security_group.add_ingress_rule(peer=aws_ec2.Peer.ipv4("0.0.0.0/0"), connection=aws_ec2.Port.tcp(22))

该安全组与Auto Scaling Group中的EC2实例关联。当我配置Elastic Beanstalk环境时,我包括以下内容:

"aws:autoscaling:launchconfiguration": {
    "InstanceType": "t3.medium",
    "IamInstanceProfile": instance_profile.ref,
    "SecurityGroups": vpc_resources.eb_security_group.security_group_id,
},
"aws:ec2:vpc": {
    "VPCId": vpc_resources.vpc.vpc_id,
    "Subnets": ",".join([subnet.sub
profile picture
专家
已提问 5 个月前52 查看次数
1 回答
0

【以下的回答经过翻译处理】 实际上,我发现Session Manager可能是我更好的解决方案。我所需要做的就是将“AmazonSSMManagedInstanceCore”受管理策略添加到我的实例配置文件中,就可以在私有子网中使用它,无需进一步的配置。

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则