# InstanceTarget

An EC2 instance that is the target for load balancing.

Extends: InstanceTarget
Implements: IConnectable, ILoadBalancerTarget

- Source: [`aws-elasticloadbalancing/lib/load-balancer.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-elasticloadbalancing/lib/load-balancer.ts#L455)
- Type last changed: v2.70.0 · 22 Mar 2023

## Example

```ts
declare const vpc: ec2.IVpc;
const lb = new elb.LoadBalancer(this, 'LB', {
  vpc,
  internetFacing: true,
});

// instance to add as the target for load balancer.
const instance = new ec2.Instance(this, 'targetInstance', {
  vpc: vpc,
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
  machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }),
});
lb.addTarget(new elb.InstanceTarget(instance));
```

## Initializer

```ts
new InstanceTarget(instance: Instance)
```

## Properties

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) — The network connections associated with this resource.

- `instance`: [Instance](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Instance.html) — Instance to register to.

## Methods

- `attachToClassicLB(loadBalancer: LoadBalancer): void` — Attach load-balanced target to a classic ELB.
