0% found this document useful (0 votes)
17 views3 pages

Ex. 15 - Load Balancer using AWS

This document outlines the steps to create an Application Load Balancer (ALB) that triggers an AWS Lambda function via HTTP requests. It includes detailed instructions for creating the Lambda function, adding permissions for ALB to invoke the function, creating a target group for the Lambda, setting up the ALB, and testing the setup. The process involves using the AWS Management Console and AWS CLI for configuration.

Uploaded by

vdjohn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Ex. 15 - Load Balancer using AWS

This document outlines the steps to create an Application Load Balancer (ALB) that triggers an AWS Lambda function via HTTP requests. It includes detailed instructions for creating the Lambda function, adding permissions for ALB to invoke the function, creating a target group for the Lambda, setting up the ALB, and testing the setup. The process involves using the AWS Management Console and AWS CLI for configuration.

Uploaded by

vdjohn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.

15 Create Application Load Balancer Using AWS Lambda function

Use Application Load Balancer (ALB) to trigger a Lambda function via HTTP requests.

Steps to Create ALB with Lambda Target


🔹 Step 1: Create Your Lambda Function
1. Go to AWS Lambda Console → Click Create function.

2. Choose Author from scratch.

3. Provide:

○ Function name (e.g., MyLambdaHandler)

○ Runtime (Python, Node.js, etc.)

Add simple handler code, for example (Node.js):

javascript
CopyEdit
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify("Hello from Lambda behind ALB!"),
};
};

4.
5. Click Create Function.

🔹 Step 2: Add Permission for ALB to Invoke Lambda


Use AWS CLI or Lambda console > Permissions > Add permission:

bash
CopyEdit
aws lambda add-permission \
--function-name MyLambdaHandler \
--statement-id alb-access \
--action "lambda:InvokeFunction" \
--principal elasticloadbalancing.amazonaws.com \
--source-arn arn:aws:elasticloadbalancing:<region>:<account-
id>:loadbalancer/app/<alb-name>/<id>

(You’ll get the ALB ARN in Step 4)

🔹 Step 3: Create a Target Group for Lambda


1. Go to EC2 Console > Target Groups.

2. Click Create target group.

3. Select Target type: Lambda function.

4. Name it (e.g., lambda-target-group).

5. Choose your Lambda function.

6. Click Create.

🔹 Step 4: Create an Application Load Balancer


1. Go to EC2 Console > Load Balancers → Click Create Load Balancer → Choose Application Load
Balancer.

2. Name your ALB (e.g., alb-lambda).

3. Choose Internet-facing, protocol: HTTP (or HTTPS).

4. Select 2+ public subnets.

5. Assign a Security Group that allows inbound traffic on port 80 (or 443).

6. In the Listeners section:

○ Protocol: HTTP

○ Action: Forward to Target Group

○ Choose the Lambda target group you created.


🔹 Step 5: Test the ALB
● Copy the DNS name of the ALB from the console.

● Open it in a browser or use curl:

bash
CopyEdit
curl http://<ALB-DNS-Name>

You might also like