我是无服务器框架和aws的新手,我需要在python上创建一个lambda函数,该函数将在ec2关闭时发送电子邮件,但我真的不知道如何使用无服务器。因此,如果有人可以帮助我做到这一点,或者至少给我一些帮助,请开始。
最佳答案
使用无服务器,您可以像这样为您的函数定义事件触发器...
functions:
shutdownEmailer:
handler: shutdownEmailer.handler
events:
- cloudwatchEvent:
event:
source:
- "aws.ec2"
detail-type:
- "EC2 Instance State-change Notification"
detail:
state:
- shutting down
enabled: true
然后,您可以期望每次事件发生时都会调用您的lambda。