class NetworkAcl (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.NetworkAcl |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsec2#NetworkAcl |
Java | software.amazon.awscdk.services.ec2.NetworkAcl |
Python | aws_cdk.aws_ec2.NetworkAcl |
TypeScript (source) | aws-cdk-lib » aws_ec2 » NetworkAcl |
Implements
IConstruct
, IDependable
, IResource
, INetwork
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
Network
Acl Props
Construct Props
Name | Type | Description |
---|---|---|
vpc | IVpc | The VPC in which to create the NetworkACL. |
network | string | The name of the NetworkAcl. |
subnet | Subnet | Subnets 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: CDK generated name)
The name of the NetworkAcl.
Since the NetworkAcl resource doesn't support providing a physical name, the value provided here will be recorded in the Name
tag.
subnetSelection?
Type:
Subnet
(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
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
network | string | The ID of the NetworkACL. |
network | string | The VPC ID for this NetworkACL. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
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
Name | Description |
---|---|
add | Add a new entry to the ACL. |
apply | Apply the given removal policy to this resource. |
associate | Associate the ACL with a given set of subnets. |
to | Returns a string representation of this construct. |
static from | Import an existing NetworkAcl into this app. |
Entry(id, options)
addpublic addEntry(id: string, options: CommonNetworkAclEntryOptions): NetworkAclEntry
Parameters
- id
string
- options
Common
Network Acl Entry Options
Returns
Add a new entry to the ACL.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
).
WithSubnet(id, selection)
associatepublic associateWithSubnet(id: string, selection: SubnetSelection): void
Parameters
- id
string
- selection
Subnet
Selection
Associate the ACL with a given set of subnets.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
NetworkAclId(scope, id, networkAclId)
static frompublic static fromNetworkAclId(scope: Construct, id: string, networkAclId: string): INetworkAcl
Parameters
- scope
Construct
- id
string
- networkAclId
string
Returns
Import an existing NetworkAcl into this app.