Skip to content

Commit df914bd

Browse files
committed
fix: propagate condition to sqs queue policy for sqssubscription
1 parent bb930cc commit df914bd

File tree

1 file changed

+8
-3
lines changed
  • samtranslator/model/eventsources

1 file changed

+8
-3
lines changed

samtranslator/model/eventsources/push.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def to_cloudformation(self, **kwargs):
407407
queue_arn = queue.get_runtime_attr("arn")
408408
queue_url = queue.get_runtime_attr("queue_url")
409409

410-
queue_policy = self._inject_sqs_queue_policy(self.Topic, queue_arn, queue_url)
410+
queue_policy = self._inject_sqs_queue_policy(self.Topic, queue_arn, queue_url, function.resource_attributes)
411411
subscription = self._inject_subscription(
412412
"sqs", queue_arn, self.Topic, self.Region, self.FilterPolicy, function.resource_attributes
413413
)
@@ -430,7 +430,9 @@ def to_cloudformation(self, **kwargs):
430430
batch_size = self.SqsSubscription.get("BatchSize", None)
431431
enabled = self.SqsSubscription.get("Enabled", None)
432432

433-
queue_policy = self._inject_sqs_queue_policy(self.Topic, queue_arn, queue_url, queue_policy_logical_id)
433+
queue_policy = self._inject_sqs_queue_policy(
434+
self.Topic, queue_arn, queue_url, function.resource_attributes, queue_policy_logical_id
435+
)
434436
subscription = self._inject_subscription(
435437
"sqs", queue_arn, self.Topic, self.Region, self.FilterPolicy, function.resource_attributes
436438
)
@@ -466,8 +468,11 @@ def _inject_sqs_event_source_mapping(self, function, role, queue_arn, batch_size
466468
event_source.Enabled = enabled or True
467469
return event_source.to_cloudformation(function=function, role=role)
468470

469-
def _inject_sqs_queue_policy(self, topic_arn, queue_arn, queue_url, logical_id=None):
471+
def _inject_sqs_queue_policy(self, topic_arn, queue_arn, queue_url, resource_attributes, logical_id=None):
470472
policy = SQSQueuePolicy(logical_id or self.logical_id + "QueuePolicy")
473+
if CONDITION in resource_attributes:
474+
policy.set_resource_attribute(CONDITION, resource_attributes[CONDITION])
475+
471476
policy.PolicyDocument = SQSQueuePolicies.sns_topic_send_message_role_policy(topic_arn, queue_arn)
472477
policy.Queues = [queue_url]
473478
return policy

0 commit comments

Comments
 (0)