aws-cdk-lib.aws_globalaccelerator.Listener

class Listener (construct)

LanguageType name
.NETAmazon.CDK.AWS.GlobalAccelerator.Listener
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsglobalaccelerator#Listener
Javasoftware.amazon.awscdk.services.globalaccelerator.Listener
Pythonaws_cdk.aws_globalaccelerator.Listener
TypeScript (source)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 ListenerProps

Construct Props

NameTypeDescription
acceleratorIAcceleratorThe accelerator for this listener.
portRangesPortRange[]The list of port ranges for the connections from clients to the accelerator.
clientAffinity?ClientAffinityClient affinity to direct all requests from a user to the same endpoint.
listenerName?stringName of the listener.
protocol?ConnectionProtocolThe protocol for the connections from clients to the accelerator.

accelerator

Type: IAccelerator

The accelerator for this listener.


portRanges

Type: PortRange[]

The list of port ranges for the connections from clients to the accelerator.


clientAffinity?

Type: ClientAffinity (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: ConnectionProtocol (optional, default: ConnectionProtocol.TCP)

The protocol for the connections from clients to the accelerator.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
listenerArnstringThe ARN of the listener.
listenerNamestringThe name of the listener.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.

env

Type: ResourceEnvironment

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

NameDescription
addEndpointGroup(id, options?)Add a new endpoint group to this listener.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.
static fromListenerArn(scope, id, listenerArn)import from ARN.

addEndpointGroup(id, options?)

public addEndpointGroup(id: string, options?: EndpointGroupOptions): EndpointGroup

Parameters

  • id string
  • options EndpointGroupOptions

Returns

  • EndpointGroup

Add a new endpoint group to this listener.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

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

  • IListener

import from ARN.