Exemple #1
0
        public async Task InitializeAsync()
        {
            var webHostUrl = FixtureUtils.IsRunningInContainer
                ? FixtureUtils.GetLocalIPAddress()
                : "127.0.0.1";

            var settings = new LambdaTestHostSettings(() => new TestLambdaContext())
            {
                WebHostUrl       = $"http://{webHostUrl}:0",
                ConfigureLogging = logging =>
                {
                    logging.AddXUnit(_outputHelper);
                    logging.SetMinimumLevel(LogLevel.Debug);
                }
            };

            settings.AddFunction(new LambdaFunctionInfo(
                                     nameof(SimpleLambdaFunction),
                                     typeof(SimpleLambdaFunction),
                                     nameof(SimpleLambdaFunction.FunctionHandler)));
            _lambdaTestHost = await LambdaTestHost.Start(settings);

            var lambdaInvokeEndpoint = FixtureUtils.GetLambdaInvokeEndpoint(_outputHelper, _lambdaTestHost);

            _stepFunctionsLocal = new Builder()
                                  .UseContainer()
                                  .WithName("lambda-testhost-stepfunctions")
                                  .UseImage("amazon/aws-stepfunctions-local:latest")
                                  .WithEnvironment($"LAMBDA_ENDPOINT={lambdaInvokeEndpoint}")
                                  .ReuseIfExists()
                                  .ExposePort(0, ContainerPort)
                                  .Build()
                                  .Start();

            var exposedPort = _stepFunctionsLocal
                              .GetConfiguration()
                              .NetworkSettings
                              .Ports.First()
                              .Value.First()
                              .HostPort;

            var stepFunctionsServiceUrl = new UriBuilder($"http://localhost:{exposedPort}");

            if (FixtureUtils.IsRunningInContainer)
            {
                var host = _stepFunctionsLocal
                           .GetConfiguration()
                           .NetworkSettings
                           .IPAddress;

                stepFunctionsServiceUrl.Host = host;
                stepFunctionsServiceUrl.Port = ContainerPort;
            }

            _stepFunctionsServiceUrl = stepFunctionsServiceUrl.Uri;
        }
Exemple #2
0
        public static async Task <LocalStackFixture> Create(ITestOutputHelper outputHelper)
        {
            var webHostUrl = FixtureUtils.IsRunningInContainer
                ? FixtureUtils.GetLocalIPAddress()
                : "127.0.0.1";

            // Runs a the Lambda TestHost (invoke api) on a random port
            var settings = new LambdaTestHostSettings(() => new TestLambdaContext())
            {
                WebHostUrl       = $"http://{webHostUrl}:0",
                ConfigureLogging = logging =>
                {
                    logging.AddXUnit(outputHelper);
                    logging.SetMinimumLevel(LogLevel.Debug);
                }
            };

            settings.AddFunction(new LambdaFunctionInfo(
                                     nameof(SimpleLambdaFunction),
                                     typeof(SimpleLambdaFunction),
                                     nameof(SimpleLambdaFunction.FunctionHandler)));
            settings.AddFunction(new LambdaFunctionInfo(
                                     nameof(SQSLambdaFunction),
                                     typeof(SQSLambdaFunction),
                                     nameof(SQSLambdaFunction.FunctionHandler)));
            var lambdaTestHost = await LambdaTestHost.Start(settings);

            var lambdaInvokeEndpoint = FixtureUtils.GetLambdaInvokeEndpoint(outputHelper, lambdaTestHost);

            var localStackBuilder = new Builder()
                                    .UseContainer()
                                    .WithName($"lambda-testhost-localstack-{Guid.NewGuid()}")
                                    .UseImage("localstack/localstack:latest")
                                    .WithEnvironment(
                "SERVICES=lambda,sqs",
                "LS_LOG=debug",
                $"LAMBDA_FORWARD_URL={lambdaInvokeEndpoint}")
                                    .ExposePort(0, ContainerPort);
            var localStack = localStackBuilder.Build().Start();

            var exposedPort = localStack
                              .GetConfiguration()
                              .NetworkSettings
                              .Ports.First()
                              .Value.First()
                              .HostPort;

            var localstackServiceUrl = new UriBuilder($"http://localhost:{exposedPort}");

            if (FixtureUtils.IsRunningInContainer)
            {
                var host = localStack
                           .GetConfiguration()
                           .NetworkSettings
                           .IPAddress;

                localstackServiceUrl.Host = host;
                localstackServiceUrl.Port = ContainerPort;
            }

            outputHelper.WriteLine($"Using localstackServiceUrl={localstackServiceUrl}");
            return(new LocalStackFixture(lambdaTestHost, localStack, localstackServiceUrl.Uri, outputHelper));
        }