Grzegorz Redlicki
Grzegorz Redlicki

Reputation: 269

AWS lambda basic-authentication with Application Load Balancer

A couple of days ago I asked AWS lambda basic-authentication without custom authorizer. I got the answer which was enough for me, I implemented the custom authorizer which works properly.

I have a very similar problem right now because we decided to change API Gateway to Application Load Balancer which will trigger the lambda function on an appropriate path.

I would like to prepare the basic authentication for this endpoint also (exact the same as before).

So, the same problem:

AWS lambda function which is a proxy for an additional service. This function only forwards the whole request and give the user the whole response. That's why I need to force the usage of the Authentication header and I would like to have the prompt window for passing the credentials: Authentication.

The response which should be sent from the lambda function is a little bit different than for the API Gateway: Using AWS Lambda with an Application Load Balancer - AWS Lambda

About the authentication with the usage of ALB, I found only Authenticate Users Using an Application Load Balancer - Elastic Load Balancing.

I can't find anything connected with Basic Authentication and the prompt window.

Has anyone ever tried to setup basic auth with ALB for the lambda function? Where to look for the information?

Upvotes: 2

Views: 8708

Answers (1)

Grzegorz Redlicki
Grzegorz Redlicki

Reputation: 269

To answer my own question:
I started my search for an answer in the wrong places. I thought that it should be connected with the ALB but in the end, it was not that hard as I thought at the beginning. It can work as a simple Basic Authentication.

So, it is enough to return that response from the asynchronous function/handler to do that in the simplest way:

{
    statusCode: 401,
    statusDescription: "401 Unauthorized",
    isBase64Encoded: false,
    headers: { "content-type": "application/json", "WWW-Authenticate": "Basic" },
    body: "",
};

Of course, there is a possibility to return anything that you want in the body of this response.

Upvotes: 1

Related Questions