def __init__(self, *args, **kwargs): """Constructor. :raises: exceptions.ImproperlyConfiguredException: Raised if the settings are not adequately configured. """ if not settings.PROPERLY_CONFIGURED: raise exceptions.ImproperlyConfiguredException( 'Settings are not properly configured.') aws_region = None if settings.AWS_REGION != '': aws_region = settings.AWS_REGION aws_access_key_id = None if settings.AWS_ACCESS_KEY_ID != '': aws_access_key_id = settings.AWS_ACCESS_KEY_ID aws_secret_access_key = None if settings.AWS_SECRET_ACCESS_KEY != '': aws_secret_access_key = settings.AWS_SECRET_ACCESS_KEY # If None is passed, Boto3 uses its default behavior to determine the URL endpoint_url = None if settings.MESSAGE_QUEUE_ENDPOINT_URL: endpoint_url = settings.MESSAGE_QUEUE_ENDPOINT_URL self._session = boto3.Session( region_name=aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) self._client = self._session.client('sqs', endpoint_url=endpoint_url) self._sqs = self._session.resource('sqs', endpoint_url=endpoint_url)
def __init__(self, *args, **kwargs): """Constructor. :raises: exceptions.ImproperlyConfiguredException: Raised if the settings are not adequately configured. """ if not settings.PROPERLY_CONFIGURED: raise exceptions.ImproperlyConfiguredException( 'Settings are not properly configured.') aws_region = settings.AWS_REGION aws_access_key_id = settings.AWS_ACCESS_KEY_ID aws_secret_access_key = settings.AWS_SECRET_ACCESS_KEY conn_str = '%s:%s:%s' % (aws_region, aws_access_key_id, aws_secret_access_key) if conn_str not in self._connections: if settings.MESSAGE_QUEUE_USE_PROXY: # Used only in Dev environment which uses ElasticMQ instead of # SQS. Hence it uses a different boto api to connect to a proxy conn = boto.sqs.connection self._connections[conn_str] = conn.SQSConnection( proxy_port=settings.MESSAGE_QUEUE_PROXY_PORT, proxy=settings.MESSAGE_QUEUE_PROXY_HOST, is_secure=False, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) else: # Used in staging and production if aws_access_key_id and aws_secret_access_key: self._connections[conn_str] = boto.sqs.connect_to_region( aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key) else: self._connections[conn_str] = boto.sqs.connect_to_region( aws_region) self._connection = self._connections[conn_str]