aws-cdk-lib.aws_ec2.NetworkAcl

class NetworkAcl (construct)

LanguageType name
.NETAmazon.CDK.AWS.EC2.NetworkAcl
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#NetworkAcl
Javasoftware.amazon.awscdk.services.ec2.NetworkAcl
Pythonaws_cdk.aws_ec2.NetworkAcl
TypeScript (source)aws-cdk-lib » aws_ec2 » NetworkAcl

Implements IConstruct, IDependable, IResource, INetworkAcl

Define a new custom network ACL.

By default, will deny all inbound and outbound traffic unless entries are added explicitly allowing it.

Example

// 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';

declare const subnet: ec2.Subnet;
declare const subnetFilter: ec2.SubnetFilter;
declare const vpc: ec2.Vpc;
const networkAcl = new ec2.NetworkAcl(this, 'MyNetworkAcl', {
  vpc: vpc,

  // the properties below are optional
  networkAclName: 'networkAclName',
  subnetSelection: {
    availabilityZones: ['availabilityZones'],
    onePerAz: false,
    subnetFilters: [subnetFilter],
    subnetGroupName: 'subnetGroupName',
    subnets: [subnet],
    subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
  },
});

Initializer

new NetworkAcl(scope: Construct, id: string, props: NetworkAclProps)

Parameters

  • scope Construct
  • id string
  • props NetworkAclProps

Construct Props

NameTypeDescription
vpcIVpcThe VPC in which to create the NetworkACL.
networkAclName?stringThe name of the NetworkAcl.
subnetSelection?SubnetSelectionSubnets in the given VPC to associate the ACL with.

vpc

Type: IVpc

The VPC in which to create the NetworkACL.


networkAclName?

Type: string (optional, default: If you don't specify a networkAclName, AWS CloudFormation generates a unique physical ID and uses that ID for the group name.)

The name of the NetworkAcl.

It is not recommended to use an explicit name.


subnetSelection?

Type: SubnetSelection (optional, default: No subnets associated)

Subnets in the given VPC to associate the ACL with.

More subnets can always be added later by calling associateWithSubnets().

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
networkAclIdstringThe ID of the NetworkACL.
networkAclVpcIdstringThe VPC ID for this NetworkACL.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


networkAclId

Type: string

The ID of the NetworkACL.


networkAclVpcId

Type: string

The VPC ID for this NetworkACL.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.

Methods

NameDescription
addEntry(id, options)Add a new entry to the ACL.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
associateWithSubnet(id, selection)Associate the ACL with a given set of subnets.
toString()Returns a string representation of this construct.
static fromNetworkAclId(scope, id, networkAclId)Import an existing NetworkAcl into this app.

addEntry(id, options)

public addEntry(id: string, options: CommonNetworkAclEntryOptions): NetworkAclEntry

Parameters

  • id string
  • options CommonNetworkAclEntryOptions

Returns

  • NetworkAclEntry

Add a new entry to the ACL.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


associateWithSubnet(id, selection)

public associateWithSubnet(id: string, selection: SubnetSelection): void

Parameters

  • id string
  • selection SubnetSelection

Associate the ACL with a given set of subnets.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromNetworkAclId(scope, id, networkAclId)

public static fromNetworkAclId(scope: Construct, id: string, networkAclId: string): INetworkAcl

Parameters

  • scope Construct
  • id string
  • networkAclId string

Returns

  • INetworkAcl

Import an existing NetworkAcl into this app.