rackerlabs / lambda-uploader

Helps package and upload Python lambda functions to AWS
Apache License 2.0
270 stars 56 forks source link

Support subscription to SNS Topic and CloudWatch Event Rule #115

Open brandond opened 7 years ago

brandond commented 7 years ago

It would be nice if the lambda config could be extended to automatically register the Lambda with a SNS Topic, CloudWatch Event Rule, etc.

This would add two properties (events and topics) to the root JSON object, both of which should be lists:

{
  "name": "Example_Lambda",
  "description": "This is a lambda",
  "region": "us-west-2",
  "handler": "function.lambda_handler",
  "role": "arn:aws:iam::0123456789012:role/LambdaRole",
  "timeout": 30,
  "memory": 128,
  "ignore": [
    "/*.pyc",
    "lambda.json"
  ],
  "events": [
    {
      "State": "ENABLED",
      "EventPattern": "{\"detail-type\":[\"AWS API Call via CloudTrail\"],\"detail\":{\"eventSource\":[\"ec2.amazonaws.com\"],\"eventName\":[\"StartInstances\",\"RunInstances\",\"RunScheduledInstances\"]}}",
      "Name": "Example-Lambda-Trigger",
      "Description": "Triggers lambda execution"
    }
  ],
  "topics": [
    "arn:aws:sns:us-west-2:0123456789012:Example-Lambda-Topic"
  ]
}

For both use cases, the object should be created if it does not exist, and permissions should be granted as necessary to allow invocation of the lambda by the calling service.