What is @aws-sdk/client-elastic-load-balancing-v2?
@aws-sdk/client-elastic-load-balancing-v2 is an AWS SDK for JavaScript package that allows developers to interact with the Elastic Load Balancing (ELB) service, specifically the Application Load Balancer (ALB) and Network Load Balancer (NLB). It provides a set of APIs to manage load balancers, target groups, listeners, and rules.
What are @aws-sdk/client-elastic-load-balancing-v2's main functionalities?
Create Load Balancer
This feature allows you to create a new load balancer. The code sample demonstrates how to create an Application Load Balancer with specified subnets, security groups, and other configurations.
const { ElasticLoadBalancingV2Client, CreateLoadBalancerCommand } = require('@aws-sdk/client-elastic-load-balancing-v2');
const client = new ElasticLoadBalancingV2Client({ region: 'us-west-2' });
const params = {
Name: 'my-load-balancer',
Subnets: ['subnet-12345678'],
SecurityGroups: ['sg-12345678'],
Scheme: 'internet-facing',
Type: 'application'
};
const command = new CreateLoadBalancerCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
Create Target Group
This feature allows you to create a new target group. The code sample demonstrates how to create a target group with specified protocol, port, and VPC ID.
const { ElasticLoadBalancingV2Client, CreateTargetGroupCommand } = require('@aws-sdk/client-elastic-load-balancing-v2');
const client = new ElasticLoadBalancingV2Client({ region: 'us-west-2' });
const params = {
Name: 'my-target-group',
Protocol: 'HTTP',
Port: 80,
VpcId: 'vpc-12345678'
};
const command = new CreateTargetGroupCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
Register Targets
This feature allows you to register targets with a target group. The code sample demonstrates how to register EC2 instances with a specified target group.
const { ElasticLoadBalancingV2Client, RegisterTargetsCommand } = require('@aws-sdk/client-elastic-load-balancing-v2');
const client = new ElasticLoadBalancingV2Client({ region: 'us-west-2' });
const params = {
TargetGroupArn: 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-target-group/abcdef123456',
Targets: [
{ Id: 'i-12345678' },
{ Id: 'i-87654321' }
]
};
const command = new RegisterTargetsCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
Create Listener
This feature allows you to create a listener for a load balancer. The code sample demonstrates how to create an HTTP listener that forwards requests to a specified target group.
const { ElasticLoadBalancingV2Client, CreateListenerCommand } = require('@aws-sdk/client-elastic-load-balancing-v2');
const client = new ElasticLoadBalancingV2Client({ region: 'us-west-2' });
const params = {
LoadBalancerArn: 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/abcdef123456',
Protocol: 'HTTP',
Port: 80,
DefaultActions: [
{
Type: 'forward',
TargetGroupArn: 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-target-group/abcdef123456'
}
]
};
const command = new CreateListenerCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
Other packages similar to @aws-sdk/client-elastic-load-balancing-v2
aws-sdk
The 'aws-sdk' package is the official AWS SDK for JavaScript. It provides a comprehensive set of APIs for interacting with all AWS services, including Elastic Load Balancing. Compared to '@aws-sdk/client-elastic-load-balancing-v2', it is a monolithic package that includes all AWS services, which can result in larger bundle sizes.
serverless
The 'serverless' package is a framework for building and deploying serverless applications on AWS and other cloud providers. It provides abstractions and tools for managing AWS resources, including load balancers. While it offers higher-level abstractions and easier deployment, it may not provide the same level of granular control as '@aws-sdk/client-elastic-load-balancing-v2'.
terraform
The 'terraform' package is an open-source infrastructure as code software tool created by HashiCorp. It allows users to define and provision data center infrastructure using a high-level configuration language. While it supports AWS ELB, it is a multi-cloud tool and not specific to JavaScript, offering a different approach to infrastructure management compared to '@aws-sdk/client-elastic-load-balancing-v2'.
@aws-sdk/client-elastic-load-balancing-v2
Description
AWS SDK for JavaScript ElasticLoadBalancingV2 Client for Node.js, Browser and React Native.
Elastic Load Balancing
A load balancer distributes incoming traffic across targets, such as your EC2 instances.
This enables you to increase the availability of your application. The load balancer also
monitors the health of its registered targets and ensures that it routes traffic only to
healthy targets. You configure your load balancer to accept incoming traffic by specifying one
or more listeners, which are configured with a protocol and port number for connections from
clients to the load balancer. You configure a target group with a protocol and port number for
connections from the load balancer to the targets, and with health check settings to be used
when checking the health status of the targets.
Elastic Load Balancing supports the following types of load balancers: Application Load
Balancers, Network Load Balancers, Gateway Load Balancers, and Classic Load Balancers. This
reference covers the following load balancer types:
-
Application Load Balancer - Operates at the application layer (layer 7) and supports
HTTP and HTTPS.
-
Network Load Balancer - Operates at the transport layer (layer 4) and supports TCP,
TLS, and UDP.
-
Gateway Load Balancer - Operates at the network layer (layer 3).
For more information, see the Elastic Load Balancing User
Guide.
All Elastic Load Balancing operations are idempotent, which means that they complete at
most one time. If you repeat an operation, it succeeds.
Installing
To install this package, simply type add or install @aws-sdk/client-elastic-load-balancing-v2
using your favorite package manager:
npm install @aws-sdk/client-elastic-load-balancing-v2
yarn add @aws-sdk/client-elastic-load-balancing-v2
pnpm add @aws-sdk/client-elastic-load-balancing-v2
Getting Started
Import
The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the ElasticLoadBalancingV2Client
and
the commands you need, for example DescribeListenersCommand
:
const { ElasticLoadBalancingV2Client, DescribeListenersCommand } = require("@aws-sdk/client-elastic-load-balancing-v2");
import { ElasticLoadBalancingV2Client, DescribeListenersCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
Usage
To send a request, you:
- Initiate client with configuration (e.g. credentials, region).
- Initiate command with input parameters.
- Call
send
operation on client with command object as input.
- If you are using a custom http handler, you may call
destroy()
to close open connections.
const client = new ElasticLoadBalancingV2Client({ region: "REGION" });
const params = {
};
const command = new DescribeListenersCommand(params);
Async/await
We recommend using await
operator to wait for the promise returned by send operation as follows:
try {
const data = await client.send(command);
} catch (error) {
} finally {
}
Async-await is clean, concise, intuitive, easy to debug and has better error handling
as compared to using Promise chains or callbacks.
Promises
You can also use Promise chaining
to execute send operation.
client.send(command).then(
(data) => {
},
(error) => {
}
);
Promises can also be called using .catch()
and .finally()
as follows:
client
.send(command)
.then((data) => {
})
.catch((error) => {
})
.finally(() => {
});
Callbacks
We do not recommend using callbacks because of callback hell,
but they are supported by the send operation.
client.send(command, (err, data) => {
});
v2 compatible style
The client can also send requests using v2 compatible style.
However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post
on modular packages in AWS SDK for JavaScript
import * as AWS from "@aws-sdk/client-elastic-load-balancing-v2";
const client = new AWS.ElasticLoadBalancingV2({ region: "REGION" });
try {
const data = await client.describeListeners(params);
} catch (error) {
}
client
.describeListeners(params)
.then((data) => {
})
.catch((error) => {
});
client.describeListeners(params, (err, data) => {
});
Troubleshooting
When the service returns an exception, the error will include the exception information,
as well as response metadata (e.g. request id).
try {
const data = await client.send(command);
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
}
Getting Help
Please use these community resources for getting help.
We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
To test your universal JavaScript code in Node.js, browser and react-native environments,
visit our code samples repo.
Contributing
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-elastic-load-balancing-v2
package is updated.
To contribute to client you can check our generate clients scripts.
License
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE for more information.
Client Commands (Operations List)
AddListenerCertificates
Command API Reference / Input / Output
AddTags
Command API Reference / Input / Output
AddTrustStoreRevocations
Command API Reference / Input / Output
CreateListener
Command API Reference / Input / Output
CreateLoadBalancer
Command API Reference / Input / Output
CreateRule
Command API Reference / Input / Output
CreateTargetGroup
Command API Reference / Input / Output
CreateTrustStore
Command API Reference / Input / Output
DeleteListener
Command API Reference / Input / Output
DeleteLoadBalancer
Command API Reference / Input / Output
DeleteRule
Command API Reference / Input / Output
DeleteSharedTrustStoreAssociation
Command API Reference / Input / Output
DeleteTargetGroup
Command API Reference / Input / Output
DeleteTrustStore
Command API Reference / Input / Output
DeregisterTargets
Command API Reference / Input / Output
DescribeAccountLimits
Command API Reference / Input / Output
DescribeCapacityReservation
Command API Reference / Input / Output
DescribeListenerAttributes
Command API Reference / Input / Output
DescribeListenerCertificates
Command API Reference / Input / Output
DescribeListeners
Command API Reference / Input / Output
DescribeLoadBalancerAttributes
Command API Reference / Input / Output
DescribeLoadBalancers
Command API Reference / Input / Output
DescribeRules
Command API Reference / Input / Output
DescribeSSLPolicies
Command API Reference / Input / Output
DescribeTags
Command API Reference / Input / Output
DescribeTargetGroupAttributes
Command API Reference / Input / Output
DescribeTargetGroups
Command API Reference / Input / Output
DescribeTargetHealth
Command API Reference / Input / Output
DescribeTrustStoreAssociations
Command API Reference / Input / Output
DescribeTrustStoreRevocations
Command API Reference / Input / Output
DescribeTrustStores
Command API Reference / Input / Output
GetResourcePolicy
Command API Reference / Input / Output
GetTrustStoreCaCertificatesBundle
Command API Reference / Input / Output
GetTrustStoreRevocationContent
Command API Reference / Input / Output
ModifyCapacityReservation
Command API Reference / Input / Output
ModifyListener
Command API Reference / Input / Output
ModifyListenerAttributes
Command API Reference / Input / Output
ModifyLoadBalancerAttributes
Command API Reference / Input / Output
ModifyRule
Command API Reference / Input / Output
ModifyTargetGroup
Command API Reference / Input / Output
ModifyTargetGroupAttributes
Command API Reference / Input / Output
ModifyTrustStore
Command API Reference / Input / Output
RegisterTargets
Command API Reference / Input / Output
RemoveListenerCertificates
Command API Reference / Input / Output
RemoveTags
Command API Reference / Input / Output
RemoveTrustStoreRevocations
Command API Reference / Input / Output
SetIpAddressType
Command API Reference / Input / Output
SetRulePriorities
Command API Reference / Input / Output
SetSecurityGroups
Command API Reference / Input / Output
SetSubnets
Command API Reference / Input / Output