-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Support DLQ, RetryPolicy properties for EventBridgeRule,Schedule event sources #1842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
281bc31
Add DeadLetterConfig,RetryPolicy properties for EventBridgeRule,Sched…
ejafarli 227eee6
Minor fix,rename function argument
ejafarli 7d7db21
Update test class name
ejafarli af05315
Combine dlq extraction/generation into the utility class
ejafarli c20bfd6
Remove unused import
ejafarli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.