Ejemplo n.º 1
0
    def to_cloudformation(self, resource, **kwargs):
        """Returns the CloudWatch Events/EventBridge Rule and IAM Role to which this
        CloudWatch Events/EventBridge event source corresponds.

        :param dict kwargs: no existing resources need to be modified
        :returns: a list of vanilla CloudFormation Resources, to which this CloudWatch Events/EventBridge event expands
        :rtype: list
        """
        resources = []

        permissions_boundary = kwargs.get("permissions_boundary")

        events_rule = EventsRule(self.logical_id)
        events_rule.EventBusName = self.EventBusName
        events_rule.EventPattern = self.Pattern
        if CONDITION in resource.resource_attributes:
            events_rule.set_resource_attribute(
                CONDITION, resource.resource_attributes[CONDITION])

        resources.append(events_rule)

        role = self._construct_role(resource, permissions_boundary)
        resources.append(role)
        events_rule.Targets = [self._construct_target(resource, role)]

        return resources
Ejemplo n.º 2
0
    def to_cloudformation(self, **kwargs):
        """Returns the CloudWatch Events Rule and Lambda Permission to which this CloudWatch Events event source
        corresponds.

        :param dict kwargs: no existing resources need to be modified
        :returns: a list of vanilla CloudFormation Resources, to which this CloudWatch Events event expands
        :rtype: list
        """
        function = kwargs.get('function')

        if not function:
            raise TypeError("Missing required keyword argument: function")

        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:
            events_rule.set_resource_attribute(CONDITION, function.resource_attributes[CONDITION])

        resources.append(events_rule)

        source_arn = events_rule.get_runtime_attr("arn")
        resources.append(self._construct_permission(function, source_arn=source_arn))

        return resources
Ejemplo n.º 3
0
    def to_cloudformation(self, resource, **kwargs):
        """Returns the CloudWatch Events/EventBridge Rule and IAM Role to which this
        CloudWatch Events/EventBridge event source corresponds.

        :param dict kwargs: no existing resources need to be modified
        :returns: a list of vanilla CloudFormation Resources, to which this CloudWatch Events/EventBridge event expands
        :rtype: list
        """
        resources = []

        permissions_boundary = kwargs.get("permissions_boundary")

        events_rule = EventsRule(self.logical_id)
        events_rule.EventBusName = self.EventBusName
        events_rule.EventPattern = self.Pattern
        if CONDITION in resource.resource_attributes:
            events_rule.set_resource_attribute(
                CONDITION, resource.resource_attributes[CONDITION])

        resources.append(events_rule)

        role = self._construct_role(resource, permissions_boundary)
        resources.append(role)

        source_arn = events_rule.get_runtime_attr("arn")
        dlq_queue_arn = None
        if self.DeadLetterConfig is not None:
            EventBridgeRuleUtils.validate_dlq_config(self.logical_id,
                                                     self.DeadLetterConfig)
            dlq_queue_arn, dlq_resources = EventBridgeRuleUtils.get_dlq_queue_arn_and_resources(
                self, source_arn)
            resources.extend(dlq_resources)

        events_rule.Targets = [
            self._construct_target(resource, role, dlq_queue_arn)
        ]

        return resources