# InstanceIdTarget

Class · Stable

An EC2 instance that is the target for load balancing.

If you register a target of this type, you are responsible for making
sure the load balancer's security group can connect to the instance.

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)
Superclass of: [InstanceTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2_targets.InstanceTarget.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#L10)

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_elasticloadbalancingv2_targets as elasticloadbalancingv2_targets } from 'aws-cdk-lib';
const instanceIdTarget = new elasticloadbalancingv2_targets.InstanceIdTarget('instanceId', /* 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_elasticloadbalancingv2_targets as elasticloadbalancingv2_targets

instance_id_target = elasticloadbalancingv2_targets.InstanceIdTarget("instanceId", 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.elasticloadbalancingv2.targets.*;

InstanceIdTarget instanceIdTarget = new InstanceIdTarget("instanceId", 123);
```

C#:

```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.ElasticLoadBalancingV2.Targets;

var instanceIdTarget = new InstanceIdTarget("instanceId", 123);
```

Go:

```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"

instanceIdTarget := awscdk.Aws_elasticloadbalancingv2_targets.NewInstanceIdTarget(jsii.String("instanceId"), jsii.Number(123))
```

## Initializer

TypeScript:

```ts
new InstanceIdTarget(instanceId: string, port?: number)
```

Python:

```python
InstanceIdTarget(instance_id: str, port: typing.Optional[int | float] = None)
```

Java:

```java
new InstanceIdTarget(String instanceId, Number port)
```

C#:

```csharp
new InstanceIdTarget(string instanceId, double? port = null)
```

Go:

```go
NewInstanceIdTarget(InstanceId *string, 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.
