# SecurityGroupProps

Used as props by: [SecurityGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SecurityGroup.html)

- 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#L248)
- Type last changed: v2.45.0 · 6 Oct 2022

## Example

TypeScript:

```ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';

declare const vpc: ec2.Vpc;
declare const code: lambda.WebFunctionCode;

const securityGroup = new ec2.SecurityGroup(this, 'EgressSecurityGroup', { vpc });

const connector = new lambda.NetworkConnector(this, 'Egress', {
  configuration: lambda.NetworkConnectorConfiguration.vpcEgress({
    computeType: lambda.NetworkConnectorComputeType.WEB_FUNCTION,
    vpc,
    vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
    securityGroups: [securityGroup],
  }),
});

new lambda.WebFunction(this, 'MyWebFunction', {
  code,
  runtime: lambda.WebFunctionRuntime.NODEJS_24_X,
  defaultEndpointAuth: lambda.WebFunctionAuthType.IAM_AUTH,
  egressNetworkConnector: connector,
});
```

Python:

```python
import aws_cdk.aws_ec2 as ec2

# vpc: ec2.Vpc
# code: lambda.WebFunctionCode

security_group = ec2.SecurityGroup(self, "EgressSecurityGroup", vpc=vpc)

connector = lambda_.NetworkConnector(self, "Egress",
    configuration=lambda_.NetworkConnectorConfiguration.vpc_egress(
        compute_type=lambda_.NetworkConnectorComputeType.WEB_FUNCTION,
        vpc=vpc,
        vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS),
        security_groups=[security_group]
    )
)

lambda_.WebFunction(self, "MyWebFunction",
    code=code,
    runtime=lambda_.WebFunctionRuntime.NODEJS_24_X,
    default_endpoint_auth=lambda_.WebFunctionAuthType.IAM_AUTH,
    egress_network_connector=connector
)
```

Java:

```java
import software.amazon.awscdk.services.ec2.*;

Vpc vpc;
WebFunctionCode code;

SecurityGroup securityGroup = SecurityGroup.Builder.create(this, "EgressSecurityGroup").vpc(vpc).build();

NetworkConnector connector = NetworkConnector.Builder.create(this, "Egress")
        .configuration(NetworkConnectorConfiguration.vpcEgress(VpcEgressConfiguration.builder()
                .computeType(NetworkConnectorComputeType.WEB_FUNCTION)
                .vpc(vpc)
                .vpcSubnets(SubnetSelection.builder().subnetType(SubnetType.PRIVATE_WITH_EGRESS).build())
                .securityGroups(List.of(securityGroup))
                .build()))
        .build();

WebFunction.Builder.create(this, "MyWebFunction")
        .code(code)
        .runtime(WebFunctionRuntime.NODEJS_24_X)
        .defaultEndpointAuth(WebFunctionAuthType.IAM_AUTH)
        .egressNetworkConnector(connector)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;

Vpc vpc;
WebFunctionCode code;

var securityGroup = new SecurityGroup(this, "EgressSecurityGroup", new SecurityGroupProps { Vpc = vpc });

var connector = new NetworkConnector(this, "Egress", new NetworkConnectorProps {
    Configuration = NetworkConnectorConfiguration.VpcEgress(new VpcEgressConfiguration {
        ComputeType = NetworkConnectorComputeType.WEB_FUNCTION,
        Vpc = vpc,
        VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PRIVATE_WITH_EGRESS },
        SecurityGroups = new [] { securityGroup }
    })
});

new WebFunction(this, "MyWebFunction", new WebFunctionProps {
    Code = code,
    Runtime = WebFunctionRuntime.NODEJS_24_X,
    DefaultEndpointAuth = WebFunctionAuthType.IAM_AUTH,
    EgressNetworkConnector = connector
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

var vpc Vpc
var code WebFunctionCode

securityGroup := ec2.NewSecurityGroup(this, jsii.String("EgressSecurityGroup"), &SecurityGroupProps{
	Vpc: Vpc,
})

connector := lambda.NewNetworkConnector(this, jsii.String("Egress"), &NetworkConnectorProps{
	Configuration: lambda.NetworkConnectorConfiguration_VpcEgress(&VpcEgressConfiguration{
		ComputeType: lambda.NetworkConnectorComputeType_WEB_FUNCTION,
		Vpc: *Vpc,
		VpcSubnets: &SubnetSelection{
			SubnetType: ec2.SubnetType_PRIVATE_WITH_EGRESS,
		},
		SecurityGroups: []ISecurityGroupRef{
			securityGroup,
		},
	}),
})

lambda.NewWebFunction(this, jsii.String("MyWebFunction"), &WebFunctionProps{
	Code: Code,
	Runtime: lambda.WebFunctionRuntime_NODEJS_24_X(),
	DefaultEndpointAuth: lambda.WebFunctionAuthType_IAM_AUTH,
	EgressNetworkConnector: connector,
})
```

## Properties

- `allowAllIpv6Outbound`: boolean = false — Whether to allow all outbound ipv6 traffic by default.

  If this is set to true, there will only be a single egress rule which allows all
  outbound ipv6 traffic. If this is set to false, no outbound traffic will be allowed by
  default and all egress ipv6 traffic must be explicitly authorized.

  To allow all ipv4 traffic use allowAllOutbound

- `allowAllOutbound`: boolean = true — Whether to allow all outbound traffic by default.

  If this is set to true, there will only be a single egress rule which allows all
  outbound traffic. If this is set to false, no outbound traffic will be allowed by
  default and all egress traffic must be explicitly authorized.

  To allow all ipv6 traffic use allowAllIpv6Outbound

- `description`: string — A description of the security group.

  **Default:** The default name will be the construct's CDK path.

- `disableInlineRules`: boolean = false — Whether to disable inline ingress and egress rule optimization.

  If this is set to true, ingress and egress rules will not be declared under the
  SecurityGroup in cloudformation, but will be separate elements.

  Inlining rules is an optimization for producing smaller stack templates. Sometimes
  this is not desirable, for example when security group access is managed via tags.

  The default value can be overridden globally by setting the context variable
  '@aws-cdk/aws-ec2.securityGroupDisableInlineRules'.

- `securityGroupName`: string — The name of the security group.

  **Default:** If you don't specify a GroupName, AWS CloudFormation generates a unique physical ID and uses that ID for the group name.

  For valid values, see the GroupName
  parameter of the CreateSecurityGroup action in the Amazon EC2 API
  Reference.

  It is not recommended to use an explicit group name.

- `vpc`: [IVpc](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — The VPC in which to create the security group.
