首页 文章

AWS Beanstalk - 在创建新环境时向Lambda发送SNS通知

提问于
浏览
1

我使用CF模板来创建Beanstalk环境 . 我希望在创建环境时通过SNS触发Lambda代码,这样我就可以使用lambda来触发jenkins作业,并为新环境进行集成测试 .

在Beanstalk中成功创建env后,有没有办法发送SNS消息?我已经定义了lambda代码订阅的主题 .

beanstalk API允许您定义通知 endpoints . http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.sns.html

但是如果我只能指定一个电子邮件地址并且我必须确认订阅呢?如何使用它自动触发SNS消息?

{
        "OptionName": "Notification Endpoint",
        "Namespace": "aws:elasticbeanstalk:sns:topics",
        "Value": "no-reply@example.com"
      },
      {
        "OptionName": "Notification Protocol",
        "Namespace": "aws:elasticbeanstalk:sns:topics",
        "Value": "email"
      },

我找到的解决方法有点黑客 . 我在堆栈创建过程结束时创建EC2实例,并运行一些AWS命令以通过 UserData shell发送SNS通知 . 这是唯一的方法吗?

2 回答

  • 2

    虽然Configuring Notifications with Elastic Beanstalk没有提供发送Amazon SNS通知的具体示例,但 email 只是resp的默认值 . AWS Elastic Beanstalk选项设置,您还可以为大多数/所有其他协议创建订阅,请参阅选项aws:elasticbeanstalk:sns:topics

    • Valid Valueshttp https email email-json sqs

    显然AWS Lambda还没有在那里被引用,但它只是另一个SNS protocol,所以我会假设/希望该表尚未更新,并且类似下面的内容应该正常工作(尽管我自己还没试过):

    {
        "OptionName": "Notification Endpoint",
        "Namespace": "aws:elasticbeanstalk:sns:topics",
        "Value": "<Your Lambda function ARN>"
      },
      {
        "OptionName": "Notification Protocol",
        "Namespace": "aws:elasticbeanstalk:sns:topics",
        "Value": "lambda"
      },
    
  • 0

    我正在回答我自己的问题 . 我设法弄清楚如何在创建新的Beanstalk env后使用SNS触发lambda代码 .

    我创建了一个sns主题 service-configurator

    并将其ARN和名称添加到模板中 .

    {
          "OptionName": "Notification Topic ARN",
          "Namespace": "aws:elasticbeanstalk:sns:topics",
          "Value": "arn:aws:sns:us-east-1:273218181234:service-configurator"
        },
        {
          "OptionName": "Notification Topic Name",
          "Namespace": "aws:elasticbeanstalk:sns:topics",
          "Value": "service-configurator"
        }
    

    接下来,我将sns主题设置为我的lambda代码的事件源 .

    现在,每当环境发生某些事件(添加/删除实例,创建env等)时,就会触发lambda .

相关问题