# InstanceConnectEndpoint
`InstanceConnectEndpoint` is a sample AWS CDK construct that allows you to build [EC2 Instance Connect Endpoint](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html) in your VPC with CDK custom resource.
This sample is generated with [projen](https://github.com/projen/projen) `awscdk-construct` project type so you can reference the `.projenrc.ts` and create your own CDK construct library like this with very little modification.
# sample
```ts
// create an EIC Endpoint in an isolated subnet
new InstanceConnectEndpoint(stack, 'EICEndpoint', {
subnet: vpc.isolatedSubnets[0],
preserveClientIp: false,
});
```
See full sample at [integ.default.ts](./src/integ.default.ts).
# deploy the default integration test
```sh
$ cd typescripts/ec2-instance-connect-endpoint
$ yarn install
# configure your AWS CLI
$ npx cdk diff
$ npx cdk deploy
```
On deployment completed, check the instance ID from the output:
```
integ-testing-eicendpoint.InstanceId = i-01d0f0c7ca761ff29
```
Now, connect it with AWS CLI:
```sh
$ aws ec2-instance-connect ssh --instance-id i-01d0f0c7ca761ff29
```
# `awssh`
Alternatively, you can create an `awssh` alias like this:
```sh
alias awssh='aws ec2-instance-connect ssh --instance-id'
```
Now, you can just `awssh` into any ec2 instance behind the endpoint.
```sh
$ awssh i-01d0f0c7ca761ff29
```
# run the tests
```sh
$ yarn test
```
# clean up
```sh
$ npx cdk destroy
```
# API Reference
## Constructs
### InstanceConnectEndpoint
#### Initializers
```typescript
import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint'
new InstanceConnectEndpoint(scope: Construct, id: string, props: InstanceConnectEndpointProps)
```
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| scope
| constructs.Construct
| *No description.* |
| id
| string
| *No description.* |
| props
| InstanceConnectEndpointProps
| *No description.* |
---
##### `scope`Required
- *Type:* constructs.Construct
---
##### `id`Required
- *Type:* string
---
##### `props`Required
- *Type:* InstanceConnectEndpointProps
---
#### Methods
| **Name** | **Description** |
| --- | --- |
| toString
| Returns a string representation of this construct. |
---
##### `toString`
```typescript
public toString(): string
```
Returns a string representation of this construct.
#### Static Functions
| **Name** | **Description** |
| --- | --- |
| isConstruct
| Checks if `x` is a construct. |
---
##### ~~`isConstruct`~~
```typescript
import { InstanceConnectEndpoint } from 'ec2-instance-connect-endpoint'
InstanceConnectEndpoint.isConstruct(x: any)
```
Checks if `x` is a construct.
###### `x`Required
- *Type:* any
Any object.
---
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| node
| constructs.Node
| The tree node. |
---
##### `node`Required
```typescript
public readonly node: Node;
```
- *Type:* constructs.Node
The tree node.
---
## Structs
### InstanceConnectEndpointProps
#### Initializer
```typescript
import { InstanceConnectEndpointProps } from 'ec2-instance-connect-endpoint'
const instanceConnectEndpointProps: InstanceConnectEndpointProps = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| subnet
| aws-cdk-lib.aws_ec2.ISubnet
| EC2 subnet for this endpoint. |
| preserveClientIp
| boolean
| whether to enable the preserveClientIp. |
| securityGroup
| aws-cdk-lib.aws_ec2.ISecurityGroup[]
| Security groups of this endpoint. |
---
##### `subnet`Required
```typescript
public readonly subnet: ISubnet;
```
- *Type:* aws-cdk-lib.aws_ec2.ISubnet
EC2 subnet for this endpoint.
---
##### `preserveClientIp`Optional
```typescript
public readonly preserveClientIp: boolean;
```
- *Type:* boolean
- *Default:* true
whether to enable the preserveClientIp.
---
##### `securityGroup`Optional
```typescript
public readonly securityGroup: ISecurityGroup[];
```
- *Type:* aws-cdk-lib.aws_ec2.ISecurityGroup[]
Security groups of this endpoint.
---