我正在尝试创建一个 SNS 主题并在 ASG 中引用该主题以在实例启动或终止时获取通知。这是我正在使用的对流层代码的一部分:
email_topic = self.template.add_resource(Topic(
'ec2_lauch_termination',
Subscription=[
Subscription(
Endpoint=Ref(alarm_email),
Protocol="email"
),
],
))
self.template.add_output(Output(
"TopicArn",
Value=GetAtt(email_topic, "Arn"),
Description="ARN of email topic",
))
for i in range(0, self.subnet_count):
asg_name = "autoScalingGroup" + str(i)
asg = self.template.add_resource(AutoScalingGroup(
asg_name,
DesiredCapacity=Ref(self.desired_capacity),
HealthCheckType="EC2",
LaunchConfigurationName=Ref(launch_config),
MinSize=Ref(self.min_size),
MaxSize=Ref(self.max_size),
VPCZoneIdentifier=[Select(i, Ref(self.instance_subnets))],
Tags=[
Tag("Name", Join("-", [Ref(self.resource_name), Ref(self.env_tag), Ref(self.vpc_short_name), "pdx"]), True),
Tag("Name", "XXXX", True),
Tag("Service", Ref(self.service_tag), True),
Tag("Environment", Ref(self.env_tag), True),
Tag("Address", Ref(self.address_tag), True)
],
NotificationConfigurations=[
NotificationConfigurations(
TopicARN=GetAtt(email_topic, "Arn"),
NotificationTypes=[
'autoscaling:EC2_INSTANCE_LAUNCH',
'autoscaling:EC2_INSTANCE_LAUNCH_ERROR',
'autoscaling:EC2_INSTANCE_TERMINATE',
'autoscaling:EC2_INSTANCE_TERMINATE_ERROR',
],
),
],
))
我已经提取了主题的 ARN,并将其作为 ASG 中 NotificationConfigurations 的“TopicARN”的值,但此代码不输出 CF 模板。我在这里遗漏了什么还是有更好的方法来实现这一点?
提前感谢您的帮助!
谢谢!