【发布时间】:2020-08-14 15:32:01
【问题描述】:
在我的 CloudFormation 文件中,我创建了一个实例、一个启动配置和一个 Auto Scaling 组。
LogstashInstance:
Type: AWS::EC2::Instance
Properties:
IamInstanceProfile:
Ref: LogstashInstanceProfile
InstanceType: t2.micro
KeyName: chuongtest
ImageId: ami-0cd31be676780afa7
UserData:
SecurityGroupIds:
- Ref: LogstashSecurityGroup
SubnetId: subnet-0e5691582096fe1e6
Tags:
- Key: Name
Value: Logstash Instance
LogstashLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
EbsOptimized: false
IamInstanceProfile:
Ref: LogstashInstanceProfile
ImageId: ami-0cd31be676780afa7
InstanceMonitoring: true
InstanceType: t2.micro
KeyName: chuongtest
LaunchConfigurationName: LogstashLaunchConfiguration
SecurityGroups:
- Ref: LogstashSecurityGroup
UserData:
LogstashAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: LogstashAutoScalingGroup
AvailabilityZones:
- ap-southeast-1b
DesiredCapacity: 1
LaunchConfigurationName:
Ref: LogstashLaunchConfiguration
MaxSize: 1
MinSize: 1
Tags:
- Key: Name
PropagateAtLaunch: "false"
Value: Logstash ASG
- Key: Instances
PropagateAtLaunch: "true"
Value: Logstash
我的想法是创建一个实例,将其附加到 ASG 并使用 ASG 保持工作继续进行。 但此代码将启动 2 个实例。
第一个实例的用户数据与后面的实例不同,因此我无法删除该实例。
我查看了文档,但找不到任何有意义的东西。有没有办法在模板中配置,还是只有脚本?
【问题讨论】:
-
您不能将实例“附加”到 ASG。您需要在 AWS::AutoScaling::LaunchConfiguration 中构建它。如果服务器上有您不能丢失的数据,您可以创建原始服务器的 AMI,在启动配置中使用该 AMI,然后在部署后删除 LogstashInstance。
-
link 我看到有一种方法可以将实例附加到 ASG,我可以从该实例创建 ASG。但我在 cloudformation 中找不到方法
标签: amazon-web-services amazon-ec2 amazon-cloudformation