Use CreateNetworkAclEntry with an AWS SDK or CLI - Amazon Elastic Compute Cloud

Use CreateNetworkAclEntry with an AWS SDK or CLI

The following code examples show how to use CreateNetworkAclEntry.

CLI
AWS CLI

To create a network ACL entry

This example creates an entry for the specified network ACL. The rule allows ingress traffic from any IPv4 address (0.0.0.0/0) on UDP port 53 (DNS) into any associated subnet. If the command succeeds, no output is returned.

Command:

<userinput>aws ec2 create-network-acl-entry --network-acl-id <replaceable>acl-5fb85d36</replaceable> --ingress --rule-number <replaceable>100</replaceable> --protocol <replaceable>udp</replaceable> --port-range <replaceable>From=53,To=53</replaceable> --cidr-block <replaceable>0.0.0.0/0</replaceable> --rule-action <replaceable>allow</replaceable></userinput>

This example creates a rule for the specified network ACL that allows ingress traffic from any IPv6 address (::/0) on TCP port 80 (HTTP).

Command:

<userinput>aws ec2 create-network-acl-entry --network-acl-id <replaceable>acl-5fb85d36</replaceable> --ingress --rule-number <replaceable>120</replaceable> --protocol <replaceable>tcp</replaceable> --port-range <replaceable>From=80,To=80</replaceable> --ipv6-cidr-block <replaceable>::/0</replaceable> --rule-action <replaceable>allow</replaceable></userinput>
PowerShell
Tools for PowerShell

Example 1: This example creates an entry for the specified network ACL. The rule allows inbound traffic from anywhere (0.0.0.0/0) on UDP port 53 (DNS) into any associated subnet.

New-EC2NetworkAclEntry -NetworkAclId acl-12345678 -Egress $false -RuleNumber 100 -Protocol 17 -PortRange_From 53 -PortRange_To 53 -CidrBlock 0.0.0.0/0 -RuleAction allow

For a complete list of AWS SDK developer guides and code examples, see Create Amazon EC2 resources using an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.