Skip to content
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

Try to get the queue before creating it to avoid the AccessDenied error #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions dramatiq_sqs/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,42 @@ def declare_queue(self, queue_name: str) -> None:
}

self.emit_before("declare_queue", queue_name)
self.queues[queue_name] = self.sqs.create_queue(
QueueName=prefixed_queue_name,
Attributes={
"MessageRetentionPeriod": self.retention,
}
)
if self.tags:
self.sqs.meta.client.tag_queue(
QueueUrl=self.queues[queue_name].url,
Tags=self.tags
)

if self.dead_letter:
dead_letter_queue_name = f"{prefixed_queue_name}_dlq"
dead_letter_queue = self.sqs.create_queue(
QueueName=dead_letter_queue_name
try:
self.queues[queue_name] = self.sqs.get_queue_by_name(
QueueName=prefixed_queue_name,
)
except self.sqs.meta.client.exceptions.QueueDoesNotExist:
self.queues[queue_name] = self.sqs.create_queue(
QueueName=prefixed_queue_name,
Attributes={
"MessageRetentionPeriod": self.retention,
}
)
if self.tags:
self.sqs.meta.client.tag_queue(
QueueUrl=dead_letter_queue.url,
QueueUrl=self.queues[queue_name].url,
Tags=self.tags
)
redrive_policy = {
"deadLetterTargetArn": dead_letter_queue.attributes["QueueArn"],
"maxReceiveCount": str(self.max_receives)
}
self.queues[queue_name].set_attributes(Attributes={
"RedrivePolicy": json.dumps(redrive_policy)
})

if self.dead_letter:
dead_letter_queue_name = f"{prefixed_queue_name}_dlq"
dead_letter_queue = self.sqs.create_queue(
QueueName=dead_letter_queue_name
)
if self.tags:
self.sqs.meta.client.tag_queue(
QueueUrl=dead_letter_queue.url,
Tags=self.tags
)
redrive_policy = {
"deadLetterTargetArn": dead_letter_queue.attributes["QueueArn"],
"maxReceiveCount": str(self.max_receives)
}
self.queues[queue_name].set_attributes(Attributes={
"RedrivePolicy": json.dumps(redrive_policy)
})

self.emit_after("declare_queue", queue_name)

def enqueue(self, message: dramatiq.Message, *, delay: Optional[int] = None) -> dramatiq.Message:
Expand Down