云形成完成后如何发送SNS通知?

How to send SNS notification after cloud formation is completed?

是否可以在 AWS 中完成 CFT 后发送 SNS 通知?有什么办法可以得到在AWS上启动CFT的进度。

使用 CF 模板创建资源时,“选项”菜单中有“高级”部分。从那里您可以使用 SNS 和主题设置通知选项。

当您启动 CF 进程时,您还可以查看状态,重要的是模板可能失败的位置。

您不能通过 CloudFormation 模板本身指定通知 ARN。如果您使用控制台创建堆栈创建,则可以指定它们。但是,一旦创建了堆栈,您就无法使用控制台更新 ARN。但是,您可以使用 aws-cli 在堆栈创建后使用通知 ARN 更新堆栈,例如:

aws cloudformation update-stack --stack-name stack-name --use-previous-template --notification-arns "arn:aws:sns:us-east-1:${ACCOUNT_ID}:${TOPIC_NAME}"

将变量 ${VARIABLE} 替换为您帐户中的文字值。

可以 欺骗 CloudFormation 从模板内部发送 SNS 消息:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

Custom resources enable you to write custom provisioning logic in templates that AWS CloudFormation runs anytime you create, update (if you changed the custom resource), or delete stacks. For example, you might want to include resources that aren't available as AWS CloudFormation resource types. You can include those resources by using custom resources. That way you can still manage all your related resources in a single stack.

Use the AWS::CloudFormation::CustomResource or Custom::String resource type to define custom resources in your templates. Custom resources require one property: the service token, which specifies where AWS CloudFormation sends requests to, such as an Amazon SNS topic.

还有来自 AWS 的 knowledge center article,您可以在其中将 ROLLBACK_IN_PROGRESS 语句替换为 CloudFormation 的任何其他状态以获取 SNS 通知。