def get_SQSqueue(): sqsregioninfo = SQSRegionInfo(name='localhost_region', endpoint='localhost') connection = sqsregioninfo.connect( port=8001, aws_access_key_id='id', aws_secret_access_key='secret', is_secure=False ) return connection.get_queue('test_queue')
def setUp(self): sqsregioninfo = SQSRegionInfo(name='localhost_region', endpoint='localhost') self.connection = sqsregioninfo.connect( port=8001, aws_access_key_id='id', aws_secret_access_key='secret', is_secure=False ) self.queue = self.connection.create_queue('test_queue') client = StatsClient(host='localhost', port=8125, prefix=None, maxudpsize=512) self.statsd = client.pipeline()
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, debug=0, https_connection_factory=None, region=None, path='/', security_token=None): if not region: region = SQSRegionInfo(self, self.DefaultRegionName, self.DefaultRegionEndpoint) self.region = region AWSQueryConnection.__init__(self, aws_access_key_id, aws_secret_access_key, is_secure, port, proxy, proxy_port, proxy_user, proxy_pass, self.region.endpoint, debug, https_connection_factory, path, security_token=security_token)
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, debug=0, https_connection_factory=None, region=None, path='/', security_token=None, validate_certs=True): if not region: region = SQSRegionInfo(self, self.DefaultRegionName, self.DefaultRegionEndpoint) self.region = region super(SQSConnection, self).__init__(aws_access_key_id, aws_secret_access_key, is_secure, port, proxy, proxy_port, proxy_user, proxy_pass, self.region.endpoint, debug, https_connection_factory, path, security_token=security_token, validate_certs=validate_certs) self.auth_region_name = self.region.name
def wait_sqs(host="localhost", port=9324, **kwargs): """"Wait for sqs to be up. Args: host (Optional[str]): Host name. Default to "localhost". port (Optional[int]): sqs port. Defaults to 8000. Keyword Args: fake_region (str): The fake region for you local sqs region (str): The region for the aws sqs secure (bool): The communication is secure, default value False aws_access_key_id (str): Access key for aws (boto), default value foo aws_secret_access_key (str): Secret key for aws (boto), default value bar Returns: bool: True if it is ready, False if something went wrong """ if "fake_region" in kwargs: fake_region = SQSRegionInfo(name=kwargs.get("fake_region", "loktar"), endpoint=host) client = fake_region.connect(port=port, is_secure=kwargs.get("secure", False), aws_access_key_id=kwargs.get("aws_access_key_id", "foo"), aws_secret_access_key=kwargs.get("aws_secret_access_key", "bar")) else: client = sqs_connect_to_region(kwargs.get("region", "eu-west-1"), port=port, is_secure=kwargs.get("secure", False), aws_access_key_id=kwargs.get("aws_access_key_id", "foo"), aws_secret_access_key=kwargs.get("aws_secret_access_key", "bar")) try: logger.info("Waiting sqs (5min max internal boto retry)") client.get_all_queues() except socket.gaierror: logger.error("Cannot connect to sqs.") logger.error("Aborting") return False logger.info("sqs is ready") return True
def test_profile_name_gets_passed(self): region = SQSRegionInfo(name='us-west-2', endpoint='us-west-2.queue.amazonaws.com') self.service_connection = SQSConnection( https_connection_factory=self.https_connection_factory, region=region, profile_name=self.profile_name) self.initialize_service_connection() self.set_http_response(status_code=200) self.assertEquals(self.service_connection.profile_name, self.profile_name)
def test_auth_region_name_is_automatically_updated(self): region = SQSRegionInfo(name='us-west-2', endpoint='us-west-2.queue.amazonaws.com') self.service_connection = SQSConnection( https_connection_factory=self.https_connection_factory, aws_access_key_id='aws_access_key_id', aws_secret_access_key='aws_secret_access_key', region=region) self.initialize_service_connection() self.set_http_response(status_code=200) self.service_connection.create_queue('my_queue') # Note the region name below is 'us-west-2'. self.assertIn('us-west-2/sqs/aws4_request', self.actual_request.headers['Authorization'])