gpt4 book ai didi

amazon-web-services - 如何使用 CloudFormation 设置 EC2 实例 Connect?

转载 作者:行者123 更新时间:2023-12-03 07:13:11 24 4
gpt4 key购买 nike

我正在尝试为 EC2 实例设置 EC2 Instance Connect:

AWSTemplateFormatVersion: 2010-09-09
Description: Part 1 - Spawn Ec2 instance with CloudFormation

Resources:
WebAppInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-2a
ImageId: ami-074cce78125f09d61
InstanceType: t2.micro

虽然上面的模板允许我创建 EC2 实例,但它不允许我使用 EC2 Instance Connect 访问它。

enter image description here

如何在 CloudFormation 模板中配置 EC2 Instance Connect?

解决方案

AWSTemplateFormatVersion: 2010-09-09
Description: Part 1 - Build a webapp stack with CloudFormation

Resources:
WebAppInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-2a
ImageId: ami-074cce78125f09d61
InstanceType: t2.micro
SecurityGroupIds:
- !Ref WebAppSecurityGroup

WebAppSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Join ["-", [webapp-security-group, dev]]
GroupDescription: "Allow HTTP/HTTPS and SSH inbound and outbound traffic"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0

WebAppEIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
InstanceId: !Ref WebAppInstance
Tags:
- Key: Name
Value: !Join ["-", [webapp-eip, dev]]

Outputs:
WebsiteURL:
Value: !Sub http://${WebAppEIP}
Description: WebApp URL

最佳答案

Amazon Linux 2(任何版本)Ubuntu 16.04 或更高版本 上,EC2 Instance Connect 为 installed and working 默认。因此您无需执行任何操作。

对于其他 AMI,您必须使用 user_data install and setup连接自己。

关于amazon-web-services - 如何使用 CloudFormation 设置 EC2 实例 Connect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69795733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com