# InstanceTarget

Extends: [InstanceIdTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2_targets.InstanceIdTarget.html) › InstanceTarget
Implements: [IApplicationLoadBalancerTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.IApplicationLoadBalancerTarget.html), [INetworkLoadBalancerTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.INetworkLoadBalancerTarget.html)

- Source: [`aws-elasticloadbalancingv2-targets/lib/instance-target.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2-targets/lib/instance-target.ts#L48)

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_elasticloadbalancingv2_targets as elasticloadbalancingv2_targets } from 'aws-cdk-lib';

declare const instance: ec2.Instance;
const instanceTarget = new elasticloadbalancingv2_targets.InstanceTarget(instance, /* all optional props */ 123);
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_elasticloadbalancingv2_targets as elasticloadbalancingv2_targets

# instance: ec2.Instance

instance_target = elasticloadbalancingv2_targets.InstanceTarget(instance, 123)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.elasticloadbalancingv2.targets.*;

Instance instance;

InstanceTarget instanceTarget = new InstanceTarget(instance, 123);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.ElasticLoadBalancingV2.Targets;

Instance instance;

var instanceTarget = new InstanceTarget(instance, 123);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var instance Instance

instanceTarget := awscdk.Aws_elasticloadbalancingv2_targets.NewInstanceTarget(instance, jsii.Number(123))
```

## Initializer

TypeScript:

```ts
new InstanceTarget(instance: Instance, port?: number)
```

Python:

```python
InstanceTarget(instance: Instance, port: typing.Optional[int | float] = None)
```

Java:

```java
new InstanceTarget(Instance instance, Number port)
```

C# / .NET:

```csharp
new InstanceTarget(Instance instance, double? port = null)
```

Golang:

```go
NewInstanceTarget(Instance Instance, Port *float64)
```

## Methods

- `attachToApplicationTargetGroup(targetGroup: IApplicationTargetGroup): LoadBalancerTargetProps` — Register this instance target with a load balancer.

  Don't call this, it is called automatically when you add the target to a
  load balancer.

- `attachToNetworkTargetGroup(targetGroup: INetworkTargetGroup): LoadBalancerTargetProps` — Register this instance target with a load balancer.

  Don't call this, it is called automatically when you add the target to a
  load balancer.
