Exemplo n.º 1
0
    def test_invoke_sns_sqs_integration_using_edge_port(self):
        edge_port = config.get_edge_port_http()
        region_original = os.environ.get("DEFAULT_REGION")
        os.environ["DEFAULT_REGION"] = "us-southeast-2"
        edge_url = "%s://localhost:%s" % (get_service_protocol(), edge_port)
        sns_client = aws_stack.connect_to_service("sns", endpoint_url=edge_url)
        sqs_client = aws_stack.connect_to_service("sqs", endpoint_url=edge_url)

        topic = sns_client.create_topic(Name="test_topic3")
        topic_arn = topic["TopicArn"]
        test_queue = sqs_client.create_queue(QueueName="test_queue3")

        queue_url = test_queue["QueueUrl"]
        sqs_client.get_queue_attributes(QueueUrl=queue_url,
                                        AttributeNames=["QueueArn"])
        sns_client.subscribe(TopicArn=topic_arn,
                             Protocol="sqs",
                             Endpoint=queue_url)
        sns_client.publish(TargetArn=topic_arn, Message="Test msg")

        response = sqs_client.receive_message(
            QueueUrl=queue_url,
            AttributeNames=["SentTimestamp"],
            MaxNumberOfMessages=1,
            MessageAttributeNames=["All"],
            VisibilityTimeout=2,
            WaitTimeSeconds=2,
        )
        self.assertEqual(1, len(response["Messages"]))

        os.environ.pop("DEFAULT_REGION")
        if region_original is not None:
            os.environ["DEFAULT_REGION"] = region_original
Exemplo n.º 2
0
    def start_runtime_components():
        from localstack.services.edge import start_edge

        # TODO: we want a composable LocalStack runtime (edge proxy, service manager, dns, ...)
        t = start_thread(start_edge, quiet=False)

        # TODO: properly encapsulate starting/stopping of edge server in a class
        if not poll_condition(
                lambda: is_port_open(config.get_edge_port_http()),
                timeout=15,
                interval=0.3):
            if LOG.isEnabledFor(logging.DEBUG):
                # make another call with quiet=False to print detailed error logs
                is_port_open(config.get_edge_port_http(), quiet=False)
            raise TimeoutError(
                f"gave up waiting for edge server on {config.EDGE_BIND_HOST}:{config.EDGE_PORT}"
            )

        return t
Exemplo n.º 3
0
    def start_runtime_components():
        from localstack.services.edge import start_edge
        from localstack.services.internal import LocalstackResourceHandler, get_internal_apis

        # serve internal APIs through the generic proxy
        ProxyListener.DEFAULT_LISTENERS.append(LocalstackResourceHandler(get_internal_apis()))

        # TODO: we want a composable LocalStack runtime (edge proxy, service manager, dns, ...)
        t = start_thread(start_edge, quiet=False)

        # TODO: properly encapsulate starting/stopping of edge server in a class
        if not poll_condition(
            lambda: is_port_open(config.get_edge_port_http()), timeout=15, interval=0.3
        ):
            if LOG.isEnabledFor(logging.DEBUG):
                # make another call with quiet=False to print detailed error logs
                is_port_open(config.get_edge_port_http(), quiet=False)
            raise TimeoutError(
                f"gave up waiting for edge server on {config.EDGE_BIND_HOST}:{config.EDGE_PORT}"
            )

        return t
Exemplo n.º 4
0
def get_execute_api_endpoint(api_id: str, protocol: str = "") -> str:
    port = config.get_edge_port_http()
    return f"{protocol}{api_id}.execute-api.{LOCALHOST_HOSTNAME}:{port}"