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

add region and endpoint for creating session also for localstack #50

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
10 changes: 8 additions & 2 deletions sqs_launcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class for running sqs message launcher

class SqsLauncher(object):

def __init__(self, queue=None, queue_url=None, create_queue=False, visibility_timeout='600'):
def __init__(self, queue=None, queue_url=None, create_queue=False, visibility_timeout='600', **kwargs):
"""
:param queue: (str) name of queue to listen to
:param queue_url: (str) url of queue to listen to
Expand All @@ -37,6 +37,7 @@ def __init__(self, queue=None, queue_url=None, create_queue=False, visibility_ti
Typically this should reflect the maximum amount of time your handler method will take
to finish execution. See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
for more information
:param kwargs: options for fine tuning. see below
"""
if not any(queue, queue_url):
raise ValueError('Either `queue` or `queue_url` should be provided.')
Expand All @@ -45,10 +46,15 @@ def __init__(self, queue=None, queue_url=None, create_queue=False, visibility_ti
raise EnvironmentError('Environment variable `AWS_ACCOUNT_ID` not set and no role found.')
# new session for each instantiation
self._session = boto3.session.Session()
self._client = self._session.client('sqs')

self._queue_name = queue
self._queue_url = queue_url
self._endpoint_name = kwargs.get('endpoint_name', None)
self._region_name = kwargs.get('region_name', self._session.region_name)
if self._region_name and self._endpoint_name:
self._client = self._session.client('sqs', region_name=self._region_name, endpoint_url=self._endpoint_name)
else:
self._client = self._session.client('sqs')
if not queue_url:
queues = self._client.list_queues(QueueNamePrefix=self._queue_name)
exists = False
Expand Down