AWS Lambda LocalStack – Cannot assign requested address: HttpRequestException

I found myself hitting the following exception whilst playing around with AWS Lambda and LocalStack when invoking a Lambda function from another Lambda function:

Cannot assign requested address: HttpRequestException
localstack_main  |    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
localstack_main  |    at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
localstack_main  |    at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
localstack_main  |    at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)localstack_main  |    at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)localstack_main  |    at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
localstack_main  |    at FanOutFunction.Function.FunctionHandler(Stream stream, ILambdaContext context) in C:\Git\MyApp\src\FanOutFunction\Function.cs:line 86

Lambdas in LocalStack run within Docker so the AWS endpoint should to be set to the LocalStack container which wasn’t the case for me. As the LocalStack edge port is typically exposed you can just target the docker host by using host.docker.internal

I am using the .NET LocalStack client so this looks like the following:

// appsettings.json
{
  "LocalStack": {
    "UseLocalStack": true,
    "Session": {
      ...
    },
    "Config": {
      "LocalStackHost": "host.docker.internal",
      "UseSsl": false,
      "UseLegacyPorts": false,
      "EdgePort": 4566
    }
  }
}

Build & deploy ASP.NET Core applications with Jenkins and Octopus Deploy

After recently getting to grips with Jenkins I wanted to expand into deployment automation as that was the only stage missing from my workflow. At my current place of work, we use Octopus Deploy for all of our in-house application deployments and it works flawlessly so I threw up an Octopus VM in Azure to play with. What we want to end up with is Jenkins building our ASP.NET Core application from source, packaging the published output and then pushing that package to Octopus for it to deploy.
Continue reading “Build & deploy ASP.NET Core applications with Jenkins and Octopus Deploy”

jQuery’s hide() and show() slow in Chrome

Whilst working on a project where I’m filtering elements on the client using JavaScript I came across a very interesting issue with Chrome.

I filter elements by running jQuery’s hide() or show() on them depending on what the user entered and there’s around 750 elements that need this filtering. I noticed that this was quite slow in Chrome as it took around 2-3 seconds for the page to become responsive whilst filtering. I tested the page in Internet Explorer 9 to confirm that the code I had written was to blame, but the filtering was instant. What the hell Chrome?

Continue reading “jQuery’s hide() and show() slow in Chrome”