class Listener (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.GlobalAccelerator.Listener |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsglobalaccelerator#Listener |
![]() | software.amazon.awscdk.services.globalaccelerator.Listener |
![]() | aws_cdk.aws_globalaccelerator.Listener |
![]() | aws-cdk-lib » aws_globalaccelerator » Listener |
Implements
IConstruct
, IDependable
, IResource
, IListener
The construct for the Listener.
Example
// Create an Accelerator
const accelerator = new globalaccelerator.Accelerator(this, 'Accelerator');
// Create a Listener
const listener = accelerator.addListener('Listener', {
portRanges: [
{ fromPort: 80 },
{ fromPort: 443 },
],
});
// Import the Load Balancers
const nlb1 = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, 'NLB1', {
loadBalancerArn: 'arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b',
});
const nlb2 = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, 'NLB2', {
loadBalancerArn: 'arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1',
});
// Add one EndpointGroup for each Region we are targeting
listener.addEndpointGroup('Group1', {
endpoints: [new ga_endpoints.NetworkLoadBalancerEndpoint(nlb1)],
});
listener.addEndpointGroup('Group2', {
// Imported load balancers automatically calculate their Region from the ARN.
// If you are load balancing to other resources, you must also pass a `region`
// parameter here.
endpoints: [new ga_endpoints.NetworkLoadBalancerEndpoint(nlb2)],
});
Initializer
new Listener(scope: Construct, id: string, props: ListenerProps)
Parameters
- scope
Construct
- id
string
- props
Listener
Props
Construct Props
Name | Type | Description |
---|---|---|
accelerator | IAccelerator | The accelerator for this listener. |
port | Port [] | The list of port ranges for the connections from clients to the accelerator. |
client | Client | Client affinity to direct all requests from a user to the same endpoint. |
listener | string | Name of the listener. |
protocol? | Connection | The protocol for the connections from clients to the accelerator. |
accelerator
Type:
IAccelerator
The accelerator for this listener.
portRanges
Type:
Port
[]
The list of port ranges for the connections from clients to the accelerator.
clientAffinity?
Type:
Client
(optional, default: ClientAffinity.NONE)
Client affinity to direct all requests from a user to the same endpoint.
If you have stateful applications, client affinity lets you direct all requests from a user to the same endpoint.
By default, each connection from each client is routed to seperate endpoints. Set client affinity to SOURCE_IP to route all connections from a single client to the same endpoint.
listenerName?
Type:
string
(optional, default: logical ID of the resource)
Name of the listener.
protocol?
Type:
Connection
(optional, default: ConnectionProtocol.TCP)
The protocol for the connections from clients to the accelerator.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
listener | string | The ARN of the listener. |
listener | string | The name of the listener. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
listenerArn
Type:
string
The ARN of the listener.
listenerName
Type:
string
The name of the listener.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
add | Add a new endpoint group to this listener. |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | import from ARN. |
addEndpointGroup(id, options?)
public addEndpointGroup(id: string, options?: EndpointGroupOptions): EndpointGroup
Parameters
- id
string
- options
Endpoint
Group Options
Returns
Add a new endpoint group to this listener.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromListenerArn(scope, id, listenerArn)
public static fromListenerArn(scope: Construct, id: string, listenerArn: string): IListener
Parameters
- scope
Construct
- id
string
- listenerArn
string
Returns
import from ARN.