Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DLQ, RetryPolicy properties for EventBridgeRule,Schedule even…
…t sources (#1842) * Add DeadLetterConfig,RetryPolicy properties for EventBridgeRule,Schedule event sources * Minor fix,rename function argument * Update test class name * Combine dlq extraction/generation into the utility class * Remove unused import
- Loading branch information
Showing
60 changed files
with
3,283 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from samtranslator.model.sqs import SQSQueue, SQSQueuePolicy, SQSQueuePolicies | ||
from samtranslator.model.exceptions import InvalidEventException | ||
|
||
|
||
class EventBridgeRuleUtils: | ||
@staticmethod | ||
def create_dead_letter_queue_with_policy(rule_logical_id, rule_arn, queue_logical_id=None): | ||
resources = [] | ||
|
||
queue = SQSQueue(queue_logical_id or rule_logical_id + "Queue") | ||
dlq_queue_arn = queue.get_runtime_attr("arn") | ||
dlq_queue_url = queue.get_runtime_attr("queue_url") | ||
|
||
# grant necessary permission to Eventbridge Rule resource for sending messages to dead-letter queue | ||
policy = SQSQueuePolicy(rule_logical_id + "QueuePolicy") | ||
policy.PolicyDocument = SQSQueuePolicies.eventbridge_dlq_send_message_resource_based_policy( | ||
rule_arn, dlq_queue_arn | ||
) | ||
policy.Queues = [dlq_queue_url] | ||
|
||
resources.append(queue) | ||
resources.append(policy) | ||
|
||
return resources | ||
|
||
@staticmethod | ||
def validate_dlq_config(source_logical_id, dead_letter_config): | ||
supported_types = ["SQS"] | ||
is_arn_defined = "Arn" in dead_letter_config | ||
is_type_defined = "Type" in dead_letter_config | ||
if is_arn_defined and is_type_defined: | ||
raise InvalidEventException( | ||
source_logical_id, "You can either define 'Arn' or 'Type' property of DeadLetterConfig" | ||
) | ||
if is_type_defined and dead_letter_config.get("Type") not in supported_types: | ||
raise InvalidEventException( | ||
source_logical_id, | ||
"The only valid value for 'Type' property of DeadLetterConfig is 'SQS'", | ||
) | ||
if not is_arn_defined and not is_type_defined: | ||
raise InvalidEventException(source_logical_id, "No 'Arn' or 'Type' property provided for DeadLetterConfig") | ||
|
||
@staticmethod | ||
def get_dlq_queue_arn_and_resources(cw_event_source, source_arn): | ||
"""returns dlq queue arn and dlq_resources, assuming cw_event_source.DeadLetterConfig has been validated""" | ||
dlq_queue_arn = cw_event_source.DeadLetterConfig.get("Arn") | ||
if dlq_queue_arn is not None: | ||
return dlq_queue_arn, [] | ||
queue_logical_id = cw_event_source.DeadLetterConfig.get("QueueLogicalId") | ||
dlq_resources = EventBridgeRuleUtils.create_dead_letter_queue_with_policy( | ||
cw_event_source.logical_id, source_arn, queue_logical_id | ||
) | ||
dlq_queue_arn = dlq_resources[0].get_runtime_attr("arn") | ||
return dlq_queue_arn, dlq_resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.