# ConnectionRule

- Source: [`aws-ec2/lib/security-group.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts#L778)

## 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';
const connectionRule: ec2.ConnectionRule = {
  fromPort: 123,

  // the properties below are optional
  description: 'description',
  protocol: 'protocol',
  toPort: 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

connection_rule = ec2.ConnectionRule(
    from_port=123,

    # the properties below are optional
    description="description",
    protocol="protocol",
    to_port=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.*;

ConnectionRule connectionRule = ConnectionRule.builder()
        .fromPort(123)

        // the properties below are optional
        .description("description")
        .protocol("protocol")
        .toPort(123)
        .build();
```

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;

var connectionRule = new ConnectionRule {
    FromPort = 123,

    // the properties below are optional
    Description = "description",
    Protocol = "protocol",
    ToPort = 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"

connectionRule := &ConnectionRule{
	FromPort: jsii.Number(123),

	// the properties below are optional
	Description: jsii.String("description"),
	Protocol: jsii.String("protocol"),
	ToPort: jsii.Number(123),
}
```

## Properties

- `description`: string — Description of this connection.

  **Default:** No description

  It is applied to both the ingress rule
  and the egress rule.

- `fromPort`: number (required) — Start of port range for the TCP and UDP protocols, or an ICMP type number.

  If you specify icmp for the IpProtocol property, you can specify
  -1 as a wildcard (i.e., any ICMP type number).

- `protocol`: string = tcp — The IP protocol name (tcp, udp, icmp) or number (see Protocol Numbers).

  Use -1 to specify all protocols. If you specify -1, or a protocol number
  other than tcp, udp, icmp, or 58 (ICMPv6), traffic on all ports is
  allowed, regardless of any ports you specify. For tcp, udp, and icmp, you
  must specify a port range. For protocol 58 (ICMPv6), you can optionally
  specify a port range; if you don't, traffic for all types and codes is
  allowed.

- `toPort`: number — End of port range for the TCP and UDP protocols, or an ICMP code.

  **Default:** If toPort is not specified, it will be the same as fromPort.

  If you specify icmp for the IpProtocol property, you can specify -1 as a
  wildcard (i.e., any ICMP code).
