How Do I Set Up AWS Elastic Load Balancing With OpenSearch?
Introduction
This guide provides a comprehensive walkthrough on configuring AWS Elastic Load Balancing (ALB) with an OpenSearch domain. By setting up an Application Load Balancer (ALB), you can distribute incoming traffic across multiple targets, such as OpenSearch nodes. This setup enhances the high availability and fault tolerance of your OpenSearch cluster, ensuring robust performance and reliability.
Step-by-Step Process
Create an OpenSearch Domain: Begin by setting up an OpenSearch domain with the desired configuration, specifying the version and the instance types.
Set Up an Application Load Balancer: Configure an ALB to handle incoming traffic. This involves defining the security groups and subnets for the load balancer.
Create Target Groups and Attach Them to the ALB: Establish target groups that will include the instances or IP addresses the ALB will route traffic to. Attach these target groups to the ALB.
Configure Listeners for the ALB: Set up listeners on the ALB to define how it listens for and routes incoming traffic to the OpenSearch cluster.
Below is a sample code to accomplish these steps:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.elasticsearch.Domain("example", {
domainName: "example-domain",
elasticsearchVersion: "7.10",
clusterConfig: {
instanceCount: 2,
instanceType: "m4.large.elasticsearch",
},
ebsOptions: {
ebsEnabled: true,
volumeSize: 20,
},
tags: {
Domain: "example",
},
});
const lbSg = new aws.ec2.SecurityGroup("lb_sg", {
name: "lb_sg",
description: "Allow HTTP inbound traffic",
vpcId: "vpc-abcdef",
ingress: [{
fromPort: 80,
toPort: 80,
protocol: "tcp",
cidrBlocks: ["0.0.0.0/0"],
}],
egress: [{
fromPort: 0,
toPort: 0,
protocol: "-1",
cidrBlocks: ["0.0.0.0/0"],
}],
});
const exampleLoadBalancer = new aws.lb.LoadBalancer("example", {
name: "example-alb",
internal: false,
loadBalancerType: "application",
securityGroups: [lbSg.id],
subnets: [
"subnet-12345",
"subnet-67890",
],
});
const exampleTargetGroup = new aws.lb.TargetGroup("example", {
name: "example-targets",
port: 80,
protocol: "HTTP",
vpcId: "vpc-abcdef",
targetType: "instance",
healthCheck: {
path: "/",
port: "80",
protocol: "HTTP",
healthyThreshold: 5,
unhealthyThreshold: 2,
interval: 30,
timeout: 5,
},
});
const exampleListener = new aws.lb.Listener("example", {
loadBalancerArn: exampleLoadBalancer.arn,
port: 80,
protocol: "HTTP",
defaultActions: [{
type: "forward",
targetGroupArn: exampleTargetGroup.arn,
}],
});
export const opensearchEndpoint = example.endpoint;
export const loadBalancerDnsName = exampleLoadBalancer.dnsName;
Key Points
- OpenSearch Domain: The cluster configuration provisions an OpenSearch domain with specific instance types and counts.
- Application Load Balancer: This handles distributing incoming traffic to your targets (OpenSearch nodes).
- Target Group: A group of instances or IP addresses that the load balancer routes traffic to.
- Listeners: They define how the load balancer listens for traffic.
Summary
In this guide, we have successfully set up AWS Elastic Load Balancing to distribute traffic to an OpenSearch domain. This configuration significantly improves the availability and reliability of your OpenSearch cluster. By effectively managing incoming requests, the ALB ensures they are routed to the appropriate OpenSearch instances, maintaining optimal performance.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.