From 0ba8fd465c843aed82d518599414e2fe8bc01936 Mon Sep 17 00:00:00 2001 From: Zach Bintliff Date: Tue, 8 Oct 2019 18:35:04 -0500 Subject: [PATCH 1/2] feat: changes for eventbusname on cloudwatch event (#1185) --- examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml | 1 + samtranslator/model/events.py | 1 + samtranslator/model/eventsources/push.py | 2 ++ samtranslator/validator/sam_schema/schema.json | 3 +++ tests/translator/input/cloudwatchevent.yaml | 1 + tests/translator/output/aws-cn/cloudwatchevent.json | 1 + tests/translator/output/aws-us-gov/cloudwatchevent.json | 1 + tests/translator/output/cloudwatchevent.json | 1 + versions/2016-10-31.md | 1 + 9 files changed, 12 insertions(+) diff --git a/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml b/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml index 6120d7346..b362a7843 100644 --- a/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml +++ b/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml @@ -45,6 +45,7 @@ Resources: Type: CloudWatchEvent Description: Detects EC2 Security Group Events to Send to Teams Properties: + EventBusName: default Pattern: source: - "aws.ec2" diff --git a/samtranslator/model/events.py b/samtranslator/model/events.py index e5c94208b..d5774446b 100644 --- a/samtranslator/model/events.py +++ b/samtranslator/model/events.py @@ -7,6 +7,7 @@ class EventsRule(Resource): resource_type = 'AWS::Events::Rule' property_types = { 'Description': PropertyType(False, is_str()), + 'EventBusName': PropertyType(False, is_str()), 'EventPattern': PropertyType(False, is_type(dict)), 'Name': PropertyType(False, is_str()), 'RoleArn': PropertyType(False, is_str()), diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 62341e983..a08392be5 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -143,6 +143,7 @@ class CloudWatchEvent(PushEventSource): resource_type = 'CloudWatchEvent' principal = 'events.amazonaws.com' property_types = { + 'EventBusName': PropertyType(False, is_str()), 'Pattern': PropertyType(False, is_type(dict)), 'Input': PropertyType(False, is_str()), 'InputPath': PropertyType(False, is_str()) @@ -164,6 +165,7 @@ def to_cloudformation(self, **kwargs): resources = [] events_rule = EventsRule(self.logical_id) + events_rule.EventBusName = self.EventBusName events_rule.EventPattern = self.Pattern events_rule.Targets = [self._construct_target(function)] if CONDITION in function.resource_attributes: diff --git a/samtranslator/validator/sam_schema/schema.json b/samtranslator/validator/sam_schema/schema.json index a07d5215a..c01534263 100644 --- a/samtranslator/validator/sam_schema/schema.json +++ b/samtranslator/validator/sam_schema/schema.json @@ -336,6 +336,9 @@ "AWS::Serverless::Function.CloudWatchEventEvent": { "additionalProperties": false, "properties": { + "EventBusName": { + "type": "string" + }, "Input": { "type": "string" }, diff --git a/tests/translator/input/cloudwatchevent.yaml b/tests/translator/input/cloudwatchevent.yaml index 28db31f84..f14ebcb40 100644 --- a/tests/translator/input/cloudwatchevent.yaml +++ b/tests/translator/input/cloudwatchevent.yaml @@ -20,6 +20,7 @@ Resources: OnTerminate: Type: CloudWatchEvent Properties: + EventBusName: ExternalEventBridge Pattern: detail: state: diff --git a/tests/translator/output/aws-cn/cloudwatchevent.json b/tests/translator/output/aws-cn/cloudwatchevent.json index 64003f557..a4d9169f4 100644 --- a/tests/translator/output/aws-cn/cloudwatchevent.json +++ b/tests/translator/output/aws-cn/cloudwatchevent.json @@ -90,6 +90,7 @@ ] } }, + "EventBusName": "ExternalEventBridge", "Targets": [ { "Id": "TriggeredFunctionOnTerminateLambdaTarget", diff --git a/tests/translator/output/aws-us-gov/cloudwatchevent.json b/tests/translator/output/aws-us-gov/cloudwatchevent.json index 75979c84b..62456632f 100644 --- a/tests/translator/output/aws-us-gov/cloudwatchevent.json +++ b/tests/translator/output/aws-us-gov/cloudwatchevent.json @@ -90,6 +90,7 @@ ] } }, + "EventBusName": "ExternalEventBridge", "Targets": [ { "Id": "TriggeredFunctionOnTerminateLambdaTarget", diff --git a/tests/translator/output/cloudwatchevent.json b/tests/translator/output/cloudwatchevent.json index 53b58bb37..0def3b60a 100644 --- a/tests/translator/output/cloudwatchevent.json +++ b/tests/translator/output/cloudwatchevent.json @@ -90,6 +90,7 @@ ] } }, + "EventBusName": "ExternalEventBridge", "Targets": [ { "Id": "TriggeredFunctionOnTerminateLambdaTarget", diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index 4cdf8a1e4..84bcbcdac 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -627,6 +627,7 @@ The object describing an event source with type `CloudWatchEvent`. Property Name | Type | Description ---|:---:|--- Pattern | [Event Pattern Object](http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html) | **Required.** Pattern describing which CloudWatch events trigger the function. Only matching events trigger the function. +EventBusName | `string` | The event bus to associate with this rule. If you omit this, the default event bus is used. Input | `string` | JSON-formatted string to pass to the function as the event body. This value overrides the matched event. InputPath | `string` | JSONPath describing the part of the event to pass to the function. From cf6313fb98d138aee76e651a0fa9363559bb2223 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 2 Dec 2019 09:45:18 -0800 Subject: [PATCH 2/2] chore: bump up translator version (#1279) --- examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml | 2 +- samtranslator/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml b/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml index b362a7843..96b51569f 100644 --- a/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml +++ b/examples/2016-10-31/cloudwatch-event-to-msteams/template.yaml @@ -45,7 +45,7 @@ Resources: Type: CloudWatchEvent Description: Detects EC2 Security Group Events to Send to Teams Properties: - EventBusName: default + EventBusName: event-bus-name Pattern: source: - "aws.ec2" diff --git a/samtranslator/__init__.py b/samtranslator/__init__.py index 20f9c7ea5..bac6c206f 100644 --- a/samtranslator/__init__.py +++ b/samtranslator/__init__.py @@ -1 +1 @@ -__version__ = '1.16.0' +__version__ = '1.17.0'