Skip to content

Commit

Permalink
cloud watch event subscriber, terraform packaging support
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilt committed Aug 21, 2019
1 parent 56d897e commit 2fd2c47
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,17 @@ def _generate_snslambdasubscription(self, resource, template):
'source_arn': topic_arn
}

def _generate_cloudwatchevent(self, resource, template):
# type: (models.CloudWatchEvent, Dict[str, Any]) -> None

template['resource'].setdefault(
'aws_cloudwatch_event_rule', {})[
resource.resource_name] = {
'name': resource.resource_name,
'event_pattern': resource.event_pattern
}
self._cwe_helper(resource, template)

def _generate_scheduledevent(self, resource, template):
# type: (models.ScheduledEvent, Dict[str, Any]) -> None

Expand All @@ -745,6 +756,10 @@ def _generate_scheduledevent(self, resource, template):
'name': resource.resource_name,
'schedule_expression': resource.schedule_expression
}
self._cwe_helper(resource, template)

def _cwe_helper(self, resource, template):
# type: (models.CloudWatchEventBase, Dict[str, Any]) -> None
template['resource'].setdefault(
'aws_cloudwatch_event_target', {})[
resource.resource_name] = {
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,30 @@ def test_adds_reserved_concurrency_when_provided(self, sample_app):
tf_resource = self.get_function(template)
assert tf_resource['reserved_concurrent_executions'] == 5

def test_can_generate_cloud_watch_event(self):
function = self.lambda_function()
event = models.CloudWatchEvent(
resource_name='foo-event',
rule_name='myrule',
event_pattern='{"source": ["aws.ec2"]}',
lambda_function=function,
)
template = self.template_gen.generate(
[function, event]
)
rule = template['resource'][
'aws_cloudwatch_event_rule'][event.resource_name]
assert rule == {
'name': event.resource_name,
'event_pattern': event.event_pattern}
target = template['resource'][
'aws_cloudwatch_event_target'][event.resource_name]
assert target == {
'target_id': 'foo-event',
'rule': '${aws_cloudwatch_event_rule.foo-event.name}',
'arn': '${aws_lambda_function.foo.arn}'
}

def test_can_generate_scheduled_event(self):
function = self.lambda_function()
event = models.ScheduledEvent(
Expand Down

0 comments on commit 2fd2c47

Please sign in to comment.