id
stringlengths
8
78
source
stringclasses
743 values
chunk_id
int64
1
5.05k
text
stringlengths
593
49.7k
vpc-ug-104
vpc-ug.pdf
104
already associated with another resource, and cannot be associated with the NAT gateway. more information, see Add internet access to a subnet. Check which resource is associated with the Elastic IP address. Go to the Elastic IPs page in the Amazon VPC console, and view the values specified for the instance ID or network interface ID. If you do not require the Elastic IP address for that resource, you can disassociate it. Alternati vely, allocate a new Elastic IP address to your account. For more information, see Start using Elastic IP addresses. NAT gateways 289 Amazon Virtual Private Cloud NAT gateway quota User Guide When you try to create a NAT gateway, you get the following error. Performing this operation would exceed the limit of 5 NAT gateways Cause You've reached the quota for the number of NAT gateways for that Availability Zone. Solution If you've reached this NAT gateway quota for your account, you can do one of the following: • Request an increase in the NAT gateways per Availability Zone quota using the Service Quotas console. • Check the status of your NAT gateway. A status of Pending, Available, or Deleting counts against your quota. If you've recently deleted a NAT gateway, wait a few minutes for the status to go from Deleting to Deleted. Then try creating a new NAT gateway. • If you do not need your NAT gateway in a specific Availability Zone, try creating a NAT gateway in an Availability Zone where you haven't reached your quota. For more information, see Amazon VPC quotas. Elastic IP address quota Problem When you try to allocate an Elastic IP address for your public NAT gateway, you get the following error. The maximum number of addresses has been reached. Cause You've reached the quota for the number of Elastic IP addresses for your account for that Region. Solution NAT gateways 290 Amazon Virtual Private Cloud User Guide If you've reached your Elastic IP address quota, you can disassociate an Elastic IP address from another resource. Alternatively, you can request an increase in the Elastic IPs quota using the Service Quotas console. Availability Zone is unsupported Problem When you try to create a NAT gateway, you get the following error: NotAvailableInZone. Cause You might be trying to create the NAT gateway in a constrained Availability Zone — a zone in which our ability to expand is constrained. Solution We cannot support NAT gateways in these Availability Zones. You can create a NAT gateway in a different Availability Zone and use it for private subnets in the constrained zone. You can also move your resources to an unconstrained Availability Zone so that your resources and your NAT gateway are in the same zone. NAT gateway is no longer visible Problem You created a NAT gateway but it's no longer visible in the Amazon VPC console. Cause There might have been an error during the creation of your NAT gateway, and creation failed. A NAT gateway with a status of Failed is visible in the Amazon VPC console for about an hour). After an hour, it's automatically deleted. Solution Review the information in NAT gateway creation fails, and try creating a new NAT gateway. NAT gateway doesn't respond to a ping command Problem NAT gateways 291 Amazon Virtual Private Cloud User Guide When you try to ping a NAT gateway's Elastic IP address or private IP address from the internet (for example, from your home computer) or from an instance in your VPC, you do not get a response. Cause A NAT gateway only passes traffic from an instance in a private subnet to the internet. Solution To test that your NAT gateway is working, see Test the public NAT gateway. Instances cannot access the internet Problem You created a public NAT gateway and followed the steps to test it, but the ping command fails, or your instances in the private subnet cannot access the internet. Causes The cause of this problem might be one of the following: • The NAT gateway is not ready to serve traffic. • Your route tables are not configured correctly. • Your security groups or network ACLs are blocking inbound or outbound traffic. • You're using an unsupported protocol. Solution Check the following information: • Check that the NAT gateway is in the Available state. In the Amazon VPC console, go to the NAT gateways page and view the status information in the details pane. If the NAT gateway is in a failed state, there may have been an error when it was created. For more information, see NAT gateway creation fails. • Check that you've configured your route tables correctly: • The NAT gateway must be in a public subnet with a route table that routes internet traffic to an internet gateway. •
vpc-ug-105
vpc-ug.pdf
105
You're using an unsupported protocol. Solution Check the following information: • Check that the NAT gateway is in the Available state. In the Amazon VPC console, go to the NAT gateways page and view the status information in the details pane. If the NAT gateway is in a failed state, there may have been an error when it was created. For more information, see NAT gateway creation fails. • Check that you've configured your route tables correctly: • The NAT gateway must be in a public subnet with a route table that routes internet traffic to an internet gateway. • Your instance must be in a private subnet with a route table that routes internet traffic to the NAT gateway. NAT gateways 292 Amazon Virtual Private Cloud User Guide • Check that there are no other route table entries that route all or part of the internet traffic to another device instead of the NAT gateway. • Ensure that your security group rules for your private instance allow outbound internet traffic. For the ping command to work, the rules must also allow outbound ICMP traffic. The NAT gateway itself allows all outbound traffic and traffic received in response to an outbound request (it is therefore stateful). • Ensure that the network ACLs that are associated with the private subnet and public subnets do not have rules that block inbound or outbound internet traffic. For the ping command to work, the rules must also allow inbound and outbound ICMP traffic. You can enable flow logs to help you diagnose dropped connections because of network ACL or security group rules. For more information, see Logging IP traffic using VPC Flow Logs. • If you are using the ping command, ensure that you are pinging a host that has ICMP enabled. If ICMP is not enabled, you will not receive reply packets. To test this, perform the same ping command from the command line terminal on your own computer. • Check that your instance is able to ping other resources, for example, other instances in the private subnet (assuming that security group rules allow this). • Ensure that your connection is using a TCP, UDP, or ICMP protocol only. TCP connection to a destination fails Problem Some of your TCP connections from instances in a private subnet to a specific destination through a NAT gateway are successful, but some are failing or timing out. Causes The cause of this problem might be one of the following: • The destination endpoint is responding with fragmented TCP packets. NAT gateways do not support IP fragmentation for TCP or ICMP. For more information, see Compare NAT gateways and NAT instances. • The tcp_tw_recycle option is enabled on the remote server, which is known to cause issues when there are multiple connections from behind a NAT device. NAT gateways 293 Amazon Virtual Private Cloud Solutions User Guide Verify whether the endpoint to which you're trying to connect is responding with fragmented TCP packets by doing the following: 1. Use an instance in a public subnet with a public IP address to trigger a response large enough to cause fragmentation from the specific endpoint. 2. Use the tcpdump utility to verify that the endpoint is sending fragmented packets. Important You must use an instance in a public subnet to perform these checks. You cannot use the instance from which the original connection was failing, or an instance in a private subnet behind a NAT gateway or a NAT instance. Diagnostic tools that send or receive large ICMP packets will report packet loss. For example, the command ping -s 10000 example.com does not work behind a NAT gateway. 3. If the endpoint is sending fragmented TCP packets, you can use a NAT instance instead of a NAT gateway. If you have access to the remote server, you can verify whether the tcp_tw_recycle option is enabled by doing the following: 1. From the server, run the following command. cat /proc/sys/net/ipv4/tcp_tw_recycle If the output is 1, then the tcp_tw_recycle option is enabled. 2. If tcp_tw_recycle is enabled, we recommend disabling it. If you need to reuse connections, tcp_tw_reuse is a safer option. If you don't have access to the remote server, you can test by temporarily disabling the tcp_timestamps option on an instance in the private subnet. Then connect to the remote server again. If the connection is successful, the cause of the previous failure is likely because tcp_tw_recycle is enabled on the remote server. If possible, contact the owner of the remote server to verify if this option is enabled and request for it to be disabled. NAT gateways 294 Amazon Virtual Private Cloud User Guide Traceroute output does not display NAT gateway private IP address Problem Your instance can access the internet, but when you perform the traceroute command,
vpc-ug-106
vpc-ug.pdf
106
you can test by temporarily disabling the tcp_timestamps option on an instance in the private subnet. Then connect to the remote server again. If the connection is successful, the cause of the previous failure is likely because tcp_tw_recycle is enabled on the remote server. If possible, contact the owner of the remote server to verify if this option is enabled and request for it to be disabled. NAT gateways 294 Amazon Virtual Private Cloud User Guide Traceroute output does not display NAT gateway private IP address Problem Your instance can access the internet, but when you perform the traceroute command, the output does not display the private IP address of the NAT gateway. Cause Your instance is accessing the internet using a different gateway, such as an internet gateway. Solution In the route table of the subnet in which your instance is located, check the following information: • Ensure that there is a route that sends internet traffic to the NAT gateway. • Ensure that there isn't a more specific route that's sending internet traffic to other devices, such as a virtual private gateway or an internet gateway. Internet connection drops after 350 seconds Problem Your instances can access the internet, but the connection drops after 350 seconds. Cause If a connection that's using a NAT gateway is idle for 350 seconds or more, the connection times out. When a connection times out, a NAT gateway returns an RST packet to any resources behind the NAT gateway that attempt to continue the connection (it does not send a FIN packet). Solution To prevent the connection from being dropped, you can initiate more traffic over the connection. Alternatively, you can enable TCP keepalive on the instance with a value less than 350 seconds. IPsec connection cannot be established Problem NAT gateways 295 Amazon Virtual Private Cloud User Guide You cannot establish an IPsec connection to a destination. Cause NAT gateways currently do not support the IPsec protocol. Solution You can use NAT-Traversal (NAT-T) to encapsulate IPsec traffic in UDP, which is a supported protocol for NAT gateways. Ensure that you test your NAT-T and IPsec configuration to verify that your IPsec traffic is not dropped. Cannot initiate more connections Problem You have existing connections to a destination through a NAT gateway, but you cannot establish more connections. Cause You might have reached the limit for simultaneous connections for a single NAT gateway. For more information, see NAT gateway basics. If your instances in the private subnet create a large number of connections, you might reach this limit. Solution Do one of the following: • Create a NAT gateway per Availability Zone and spread your clients across those zones. • Create additional NAT gateways in the public subnet and split your clients into multiple private subnets, each with a route to a different NAT gateway. • Limit the number of connections your clients can create to the destination. • Use the IdleTimeoutCount metric in CloudWatch to monitor for increases in idle connections. Close idle connections to release capacity. • Create a NAT gateway with multiple IP addresses or add secondary IP addresses to an existing NAT gateway. Each new IPv4 address can support up to 55,000 concurrent connections. For more information, see Create a NAT gateway or Edit secondary IP address associations. NAT gateways 296 Amazon Virtual Private Cloud Pricing for NAT gateways User Guide When you provision a NAT gateway, you are charged for each hour that your NAT gateway is available and each gigabyte of data that it processes. For more information, see Amazon VPC Pricing. The following strategies can help you reduce the data transfer charges for your NAT gateway: • If your AWS resources send or receive a significant volume of traffic across Availability Zones, ensure that the resources are in the same Availability Zone as the NAT gateway. Alternatively, create a NAT gateway in each Availability Zone with resources. • If most traffic through your NAT gateway is to AWS services that support interface endpoints or gateway endpoints, consider creating an interface endpoint or gateway endpoint for these services. For more information about the potential cost savings, see AWS PrivateLink pricing. NAT instances A NAT instance provides network address translation (NAT). You can use a NAT instance to allow resources in a private subnet to communicate with destinations outside the virtual private cloud (VPC), such as the internet or an on-premises network. The resources in the private subnet can initiate outbound IPv4 traffic to the internet, but they can't receive inbound traffic initiated on the internet. Important NAT AMI is built on the last version of the Amazon Linux AMI, 2018.03, which reached the end of standard support on December 31, 2020 and end of maintenance support on December 31, 2023. For more information, see the following
vpc-ug-107
vpc-ug.pdf
107
network address translation (NAT). You can use a NAT instance to allow resources in a private subnet to communicate with destinations outside the virtual private cloud (VPC), such as the internet or an on-premises network. The resources in the private subnet can initiate outbound IPv4 traffic to the internet, but they can't receive inbound traffic initiated on the internet. Important NAT AMI is built on the last version of the Amazon Linux AMI, 2018.03, which reached the end of standard support on December 31, 2020 and end of maintenance support on December 31, 2023. For more information, see the following blog post: Amazon Linux AMI end of life. If you use an existing NAT AMI, AWS recommends that you migrate to a NAT gateway. NAT gateways provide better availability, higher bandwidth, and requires less administrative effort. For more information, see Compare NAT gateways and NAT instances. If NAT instances are a better match for your use case than NAT gateways, you can create your own NAT AMI from a current version of Amazon Linux as described in the section called “3. Create a NAT AMI”. Contents NAT instances 297 Amazon Virtual Private Cloud • NAT instance basics • Enable private resources to communicate outside the VPC User Guide NAT instance basics The following figure illustrates the NAT instance basics. The route table associated with the private subnet sends internet traffic from the instances in the private subnet to the NAT instance in the public subnet. The NAT instance then sends the traffic to the internet gateway. The traffic is attributed to the public IP address of the NAT instance. The NAT instance specifies a high port number for the response; if a response comes back, the NAT instance sends it to an instance in the private subnet based on the port number for the response. The NAT instance must have internet access, so it must be in a public subnet (a subnet that has a route table with a route to the internet gateway), and it must have a public IP address or an Elastic IP address. NAT instances 298 Amazon Virtual Private Cloud User Guide To get started with NAT instances, create a NAT AMI, create a security group for the NAT instance, and launch the NAT instance into your VPC. Your NAT instance quota depends on your instance quota for the Region. For more information, see Amazon EC2 service quotas in the AWS General Reference. Enable private resources to communicate outside the VPC This section describes how to create and work with NAT instances to enable resources in a private subnet to communicate outside the virtual private cloud. Tasks • 1. Create a VPC for the NAT instance NAT instances 299 Amazon Virtual Private Cloud User Guide • 2. Create a security group for the NAT instance • 3. Create a NAT AMI • 4. Launch a NAT instance • 5. Disable source/destination checks • 6. Update the route table • 7. Test your NAT instance 1. Create a VPC for the NAT instance Use the following procedure to create a VPC with a public subnet and a private subnet. To create the VPC 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. Choose Create VPC. 3. 4. 5. For Resources to create, choose VPC and more. For Name tag auto-generation, enter a name for the VPC. To configure the subnets, do the following: a. b. c. For Number of Availability Zones, choose 1 or 2, depending on your needs. For Number of public subnets, ensure that you have one public subnet per Availability Zone. For Number of private subnets, ensure that you have one private subnet per Availability Zone. 6. Choose Create VPC. 2. Create a security group for the NAT instance Create a security group with the rules described in the following table. These rules enable your NAT instance to receive internet-bound traffic from instances in the private subnet, as well as SSH traffic from your network. The NAT instance can also send traffic to the internet, which enables the instances in the private subnet to get software updates. The following are the inbound recommended rules. NAT instances 300 Amazon Virtual Private Cloud User Guide Source Protocol Port range Comments Private subnet CIDR TCP 80 Private subnet CIDR TCP 443 Public IP address TCP 22 range of your network Allow inbound HTTP traffic from servers in the private subnet Allow inbound HTTPS traffic from servers in the private subnet Allow inbound SSH access to the NAT instance from your network (over the internet gateway) The following are the recommended outbound rules. Destination Protocol Port range Comments 0.0.0.0/0 TCP 80 0.0.0.0/0 TCP 443 Allow outbound HTTP access to the internet Allow outbound HTTPS access to the internet To create the security group 1. Open the Amazon VPC
vpc-ug-108
vpc-ug.pdf
108
Protocol Port range Comments Private subnet CIDR TCP 80 Private subnet CIDR TCP 443 Public IP address TCP 22 range of your network Allow inbound HTTP traffic from servers in the private subnet Allow inbound HTTPS traffic from servers in the private subnet Allow inbound SSH access to the NAT instance from your network (over the internet gateway) The following are the recommended outbound rules. Destination Protocol Port range Comments 0.0.0.0/0 TCP 80 0.0.0.0/0 TCP 443 Allow outbound HTTP access to the internet Allow outbound HTTPS access to the internet To create the security group 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Security groups. 3. Choose Create security group. 4. 5. Enter a name and description for the security group. For VPC, select the ID of the VPC for your NAT instance. 6. Add rules for inbound traffic under Inbound rules as follows: a. Choose Add rule. Choose HTTP for Type and enter the IP address range of your private subnet for Source. b. Choose Add rule. Choose HTTPS for Type and enter the IP address range of your private subnet for Source. NAT instances 301 Amazon Virtual Private Cloud User Guide c. Choose Add rule. Choose SSH for Type and enter the IP address range of your network for Source. 7. Add rules for outbound traffic under Outbound rules as follows: a. Choose Add rule. Choose HTTP for Type and enter 0.0.0.0/0 for Destination. b. Choose Add rule. Choose HTTPS for Type and enter 0.0.0.0/0 for Destination. 8. Choose Create security group. For more information, see Security groups. 3. Create a NAT AMI A NAT AMI is configured to run NAT on an EC2 instance. You must create a NAT AMI and then launch your NAT instance using your NAT AMI. If you plan to use an operating system other than Amazon Linux for your NAT AMI, refer to the documentation for this operating system to learn how to configure NAT. Be sure to save these settings so that they persist even after an instance reboot. To create a NAT AMI for Amazon Linux 1. Launch an EC2 instance running AL2023 or Amazon Linux 2. Be sure to specify the security group that you created for the NAT instance. 2. Connect to your instance and run the following commands on the instance to enable iptables. sudo yum install iptables-services -y sudo systemctl enable iptables sudo systemctl start iptables 3. Do the following on the instance to enable IP forwarding such that it persists after reboot: a. Using a text editor, such as nano or vim, create the following configuration file: /etc/ sysctl.d/custom-ip-forwarding.conf. b. Add the following line to the configuration file. net.ipv4.ip_forward=1 c. Save the configuration file and exit the text editor. d. Run the following command to apply the configuration file. NAT instances 302 Amazon Virtual Private Cloud User Guide sudo sysctl -p /etc/sysctl.d/custom-ip-forwarding.conf 4. Run the following command on the instance, and note the name of the primary network interface. You'll need this information for the next step. netstat -i In the following example output, docker0 is a network interface created by docker, eth0 is the primary network interface, and lo is the loopback interface. Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg docker0 1500 0 0 0 0 0 0 0 0 BMU eth0 9001 7276052 0 0 0 5364991 0 0 0 BMRU lo 65536 538857 0 0 0 538857 0 0 0 LRU In the following example output, the primary network interface is enX0. Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg enX0 9001 1076 0 0 0 1247 0 0 0 BMRU lo 65536 24 0 0 0 24 0 0 0 LRU In the following example output, the primary network interface is ens5. Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens5 9001 14036 0 0 0 2116 0 0 0 BMRU lo 65536 12 0 0 0 12 0 0 0 LRU 5. Run the following commands on the instance to configure NAT. If the primary network interface is not eth0, replace eth0 with the primary network interface that you noted in the previous step. sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo /sbin/iptables -F FORWARD sudo service iptables save 6. Create a NAT AMI from the EC2 instance. For more information, see Create a Linux AMI from an instance in the Amazon EC2 User Guide. NAT instances 303 Amazon Virtual Private Cloud 4. Launch a NAT instance User Guide Use the following procedure to launch a NAT instance using the VPC, security group, and NAT AMI that you created. To launch a NAT instance 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. 2. On the dashboard, choose Launch instance. 3. 4.
vpc-ug-109
vpc-ug.pdf
109
sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo /sbin/iptables -F FORWARD sudo service iptables save 6. Create a NAT AMI from the EC2 instance. For more information, see Create a Linux AMI from an instance in the Amazon EC2 User Guide. NAT instances 303 Amazon Virtual Private Cloud 4. Launch a NAT instance User Guide Use the following procedure to launch a NAT instance using the VPC, security group, and NAT AMI that you created. To launch a NAT instance 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. 2. On the dashboard, choose Launch instance. 3. 4. 5. 6. 7. For Name, enter a name for your NAT instance. For Application and OS Images, select your NAT AMI (choose Browse more AMIs, My AMIs). For Instance type, choose an instance type that provides the compute, memory, and storage resources that your NAT instance needs. For Key pair, select an existing key pair or choose Create new key pair. For Network settings, do the following: a. b. c. d. e. Choose Edit. For VPC, choose the VPC that you created. For Subnet, choose the public subnet that you created. For Auto-assign public IP, choose Enable. Alternatively, after you launch the NAT instance, allocate an Elastic IP address and assign it to the NAT instance. For Firewall, choose Select existing security group and then choose the security group that you created. 8. Choose Launch instance. Choose the instance ID to open the instance details page. Wait for the instance state to change to Running and for the status checks to succeed. 9. Disable source/destination checks for the NAT instance (see 5. Disable source/destination checks). 10. Update the route table to send traffic to the NAT instance (see 6. Update the route table). 5. Disable source/destination checks Each EC2 instance performs source/destination checks by default. This means that the instance must be the source or destination of any traffic it sends or receives. However, a NAT instance must be able to send and receive traffic when the source or destination is not itself. Therefore, you must disable source/destination checks on the NAT instance. NAT instances 304 Amazon Virtual Private Cloud User Guide To disable source/destination checking 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. 2. 3. In the navigation pane, choose Instances. Select the NAT instance. 4. Choose Actions, Networking, Change source/destination check. 5. For Source/destination checking, select Stop. 6. Choose Save. 7. If the NAT instance has a secondary network interface, choose it from Network interfaces on the Networking tab. Choose the interface ID to go to the network interfaces page. Choose Actions, Change source/dest. check, clear Enable, and choose Save. 6. Update the route table The route table for the private subnet must have a route that sends internet traffic to the NAT instance. To update the route table 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Route tables. Select the route table for the private subnet. 4. On the Routes tab, choose Edit routes and then choose Add route. 5. Enter 0.0.0.0/0 for Destination and the instance ID of the NAT instance for Target. 6. Choose Save changes. For more information, see Configure route tables. 7. Test your NAT instance After you have launched a NAT instance and completed the configuration steps above, you can test whether an instance in your private subnet can access the internet through the NAT instance by using the NAT instance as a bastion server. Tasks NAT instances 305 Amazon Virtual Private Cloud User Guide • Step 1: Update the NAT instance security group • Step 2: Launch a test instance in the private subnet • Step 3: Ping an ICMP-enabled website • Step 4: Clean up Step 1: Update the NAT instance security group To allow instances in your private subnet to send ping traffic to the NAT instance, add a rule to allow inbound and outbound ICMP traffic. To allow the NAT instance to serve as a bastion server, add a rule to allow outbound SSH traffic to the private subnet. To update your NAT instance security group 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Security groups. Select the check box for the security group associated with your NAT instance. 4. On the Inbound rules tab, choose Edit inbound rules. 5. Choose Add rule. Choose All ICMP - IPv4 for Type. Choose Custom for Source and enter the IP address range of your private subnet. Choose Save rules. 6. On the Outbound rules tab, choose Edit outbound rules. 7. Choose Add rule. Choose SSH for Type. Choose Custom for Destination and enter the IP address range of your private subnet. 8. Choose Add rule. Choose All ICMP - IPv4 for Type. Choose Anywhere - IPv4
vpc-ug-110
vpc-ug.pdf
110
Security groups. Select the check box for the security group associated with your NAT instance. 4. On the Inbound rules tab, choose Edit inbound rules. 5. Choose Add rule. Choose All ICMP - IPv4 for Type. Choose Custom for Source and enter the IP address range of your private subnet. Choose Save rules. 6. On the Outbound rules tab, choose Edit outbound rules. 7. Choose Add rule. Choose SSH for Type. Choose Custom for Destination and enter the IP address range of your private subnet. 8. Choose Add rule. Choose All ICMP - IPv4 for Type. Choose Anywhere - IPv4 for Destination. Choose Save rules. Step 2: Launch a test instance in the private subnet Launch an instance into your private subnet. You must allow SSH access from the NAT instance, and you must use the same key pair that you used for the NAT instance. To launch a test instance in the private subnet 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. 2. On the dashboard, choose Launch instance. 3. Select your private subnet. NAT instances 306 Amazon Virtual Private Cloud User Guide 4. Do not assign a public IP address to this instance. 5. Ensure that the security group for this instance allows inbound SSH access from your NAT instance, or from the IP address range of your public subnet, and outbound ICMP traffic. 6. Select the same key pair that you used for the NAT instance. Step 3: Ping an ICMP-enabled website To verify that the test instance in your private subnet can use your NAT instance to communicate with the internet, run the ping command. To test the internet connection from your private instance 1. From your local computer, configure SSH agent forwarding, so that you can use the NAT instance as a bastion server. Linux and macOS ssh-add key.pem Windows Download and install Pageant, if it is not already installed. Convert your private key using PuTTYgen. Start Pageant, right-click the Pageant icon on the taskbar (it might be hidden), and choose Add Key. Select the .ppk file that you created, enter the passphrase if required, and choose Open. 2. From your local computer, connect to your NAT instance. Linux and macOS ssh -A ec2-user@nat-instance-public-ip-address Windows Connect to your NAT instance using PuTTY. For Auth, you must select Allow agent forwarding and leave Private key file for authentication blank. 3. From the NAT instance, run the ping command, specifying a website that is enabled for ICMP. NAT instances 307 Amazon Virtual Private Cloud User Guide [ec2-user@ip-10-0-4-184]$ ping ietf.org To confirm that your NAT instance has internet access, verify that you received output such as the following, and then press Ctrl+C to cancel the ping command. Otherwise, verify that the NAT instance is in a public subnet (its route table has a route to an internet gateway). PING ietf.org (104.16.45.99) 56(84) bytes of data. 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=1 ttl=33 time=7.88 ms 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=2 ttl=33 time=8.09 ms 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=3 ttl=33 time=7.97 ms ... 4. From your NAT instance, connect to your instance in your private subnet by using its private IP address. [ec2-user@ip-10-0-4-184]$ ssh ec2-user@private-server-private-ip-address 5. From your private instance, test that you can connect to the internet by running the ping command. [ec2-user@ip-10-0-135-25]$ ping ietf.org To confirm that your private instance has internet access through the NAT instance verify that you received output such as the following, and then press Ctrl+C to cancel the ping command. PING ietf.org (104.16.45.99) 56(84) bytes of data. 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=1 ttl=33 time=8.76 ms 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=2 ttl=33 time=8.26 ms 64 bytes from 104.16.45.99 (104.16.45.99): icmp_seq=3 ttl=33 time=8.27 ms ... Troubleshooting If the ping command fails from the server in the private subnet, use the following steps to troubleshoot the issue: NAT instances 308 Amazon Virtual Private Cloud User Guide • Verify that you pinged a website that has ICMP enabled. Otherwise, your server can't receive reply packets. To test this, run the same ping command from a command line terminal on your own computer. • Verify that the security group for your NAT instance allows inbound ICMP traffic from your private subnet. Otherwise, your NAT instance can't receive the ping command from your private instance. • Verify that you disabled source/destination checking for your NAT instance. For more information, see 5. Disable source/destination checks. • Verify that you configured your route tables correctly. For more information, see 6. Update the route table. Step 4: Clean up If you no longer require the test server in the private subnet, terminate the instance so that you are no longer billed for it. For more information, see Terminate your instance in the Amazon EC2 User Guide. If you no longer require the NAT instance, you can stop or
vpc-ug-111
vpc-ug.pdf
111
instance can't receive the ping command from your private instance. • Verify that you disabled source/destination checking for your NAT instance. For more information, see 5. Disable source/destination checks. • Verify that you configured your route tables correctly. For more information, see 6. Update the route table. Step 4: Clean up If you no longer require the test server in the private subnet, terminate the instance so that you are no longer billed for it. For more information, see Terminate your instance in the Amazon EC2 User Guide. If you no longer require the NAT instance, you can stop or terminate it, so that you are no longer billed for it. If you created a NAT AMI, you can create a new NAT instance whenever you need one. Compare NAT gateways and NAT instances The following is a high-level summary of the differences between NAT gateways and NAT instances. We recommend that you use NAT gateways because they provide better availability and bandwidth and require less effort on your part to administer. Attribute NAT gateway NAT instance Availabil ity Highly available. NAT gateways in each Availability Zone are implemented with redundancy. Create a NAT gateway in each Availability Zone to ensure zone- independent architecture. Bandwidth Scale up to 100 Gbps. Use a script to manage failover between instances. Depends on the bandwidth of the instance type. Compare NAT devices 309 Amazon Virtual Private Cloud User Guide Attribute NAT gateway NAT instance Maintenan ce Managed by AWS. You do not need to perform any maintenance. Managed by you, for example, by installing software updates or operating system patches on the instance. Performan ce Software is optimized for handling NAT traffic. A generic AMI that's configured to perform NAT. Cost Charged depending on the number of NAT gateways you use, duration of Charged depending on the number of NAT instances that you use, duration of usage, and amount of data that you send usage, and instance type and size. through the NAT gateways. Type and size Uniform offering; you don’t need to decide on the type or size. Choose a suitable instance type and size, according to your predicted workload. Public IP addresses Choose the Elastic IP address to associate with a public NAT gateway at creation. Use an Elastic IP address or a public IP address with a NAT instance. You can change the public IP address at any time by associating a new Elastic IP address with the instance. Private IP Automatically selected from the subnet's IP address range when you create the Assign a specific private IP address from the subnet's IP address range when you addresses gateway. launch the instance. Security groups You cannot associate security groups with NAT gateways. You can associate them with the resources behind the NAT gateway to control inbound and outbound traffic. Associate with your NAT instance and the resources behind your NAT instance to control inbound and outbound traffic. Network ACLs Use a network ACL to control the traffic to and from the subnet in which your NAT gateway resides. Use a network ACL to control the traffic to and from the subnet in which your NAT instance resides. Compare NAT devices 310 Amazon Virtual Private Cloud User Guide Attribute NAT gateway NAT instance Flow logs Port forwardin g Bastion servers Use flow logs to capture the traffic. Use flow logs to capture the traffic. Not supported. Manually customize the configuration to support port forwarding. Not supported. Use as a bastion server. Traffic metrics View CloudWatch metrics for the NAT gateway. View CloudWatch metrics for the instance. Timeout behavior When a connection times out, a NAT gateway returns an RST packet to any When a connection times out, a NAT instance sends a FIN packet to resources resources behind the NAT gateway that behind the NAT instance to close the attempt to continue the connection (it connection. does not send a FIN packet). IP fragmenta Supports forwarding of IP fragmented packets for the UDP protocol. Supports reassembly of IP fragmente d packets for the UDP, TCP, and ICMP tion protocols. Does not support fragmentation for the TCP and ICMP protocols. Fragmente d packets for these protocols will get dropped. Migrate from a NAT instance to a NAT gateway If you're already using a NAT instance, we recommend that you replace it with a NAT gateway. You can create a NAT gateway in the same subnet as your NAT instance, and then replace the existing route in your route table that points to the NAT instance with a route that points to the NAT gateway. To use the same Elastic IP address for the NAT gateway that you currently use for your NAT instance, you must first disassociate the Elastic IP address from your NAT instance and then associate it with your NAT
vpc-ug-112
vpc-ug.pdf
112
NAT instance to a NAT gateway If you're already using a NAT instance, we recommend that you replace it with a NAT gateway. You can create a NAT gateway in the same subnet as your NAT instance, and then replace the existing route in your route table that points to the NAT instance with a route that points to the NAT gateway. To use the same Elastic IP address for the NAT gateway that you currently use for your NAT instance, you must first disassociate the Elastic IP address from your NAT instance and then associate it with your NAT gateway when you create the gateway. Compare NAT devices 311 Amazon Virtual Private Cloud User Guide If you change your routing from a NAT instance to a NAT gateway, or if you disassociate the Elastic IP address from your NAT instance, any current connections are dropped and have to be re- established. Ensure that you do not have any critical tasks (or any other tasks that operate through the NAT instance) running. Associate Elastic IP addresses with resources in your VPC An Elastic IP address is a static, public IPv4 address designed specifically for the dynamic nature of cloud computing. This feature allows you to associate an Elastic IP address with any instance or network interface within any Virtual Private Cloud (VPC) in your AWS account. By leveraging Elastic IP addresses, you can unlock a host of benefits that simplify the management and resilience of your cloud-based infrastructure. One of the primary advantages of Elastic IP addresses is their ability to mask the failure of an instance. Should an instance experience an unexpected outage or need to be replaced, you can remap the associated Elastic IP address to another instance within your VPC. This failover process ensures that your applications and services maintain a consistent and reliable public endpoint, minimizing downtime and providing a superior user experience. Furthermore, Elastic IP addresses offer flexibility in how you manage your network resources. You can programmatically associate and disassociate these addresses as needed, allowing you to direct traffic to different instances based on your evolving business requirements. This dynamic allocation of public IP addresses empowers you to adapt to changing demand, scale your infrastructure, and implement innovative architectures without the constraints of static IP assignments. Beyond their use for instance failover, Elastic IP addresses can also serve as stable identifiers for your cloud-based resources. This can be beneficial when configuring external services, such as DNS records or firewall rules, to communicate with your AWS-hosted applications. By associating a persistent public IP address, you can future-proof your networking configurations and avoid the need to update external references when underlying instances are replaced or scaled. Contents • Elastic IP address concepts and rules • Start using Elastic IP addresses Elastic IP addresses 312 Amazon Virtual Private Cloud User Guide Elastic IP address concepts and rules To use an Elastic IP address, you first allocate it for use in your account. Then, you can associate it with an instance or network interface in your VPC. Your Elastic IP address remains allocated to your AWS account until you explicitly release it. An Elastic IP address is a property of a network interface. You can associate an Elastic IP address with an instance by updating the network interface attached to the instance. The advantage of associating the Elastic IP address with the network interface instead of directly with the instance is that you can move all the attributes of the network interface from one instance to another in a single step. For more information, see Elastic network interfaces in the Amazon EC2 User Guide. The following rules apply: • An Elastic IP address can be associated with a single instance or network interface at a time. • You can move an Elastic IP address from one instance or network interface to another. • If you associate an Elastic IP address with the primary network interface of your instance, its current public IPv4 address (if it had one) is released to the public IP address pool. If you disassociate the Elastic IP address, the primary network interface is automatically assigned a new public IPv4 address within a few minutes. This doesn't apply if you've attached a second network interface to your instance. • You're limited to five Elastic IP addresses. To help conserve them, you can use a NAT device. For more information, see Connect to the internet or other networks using NAT devices. • Elastic IP addresses for IPv6 are not supported. • You can tag an Elastic IP address that's allocated for use in a VPC, however, cost allocation tags are not supported. If you recover an Elastic IP address, tags are not recovered. • You can access an Elastic IP address from the internet when the
vpc-ug-113
vpc-ug.pdf
113
This doesn't apply if you've attached a second network interface to your instance. • You're limited to five Elastic IP addresses. To help conserve them, you can use a NAT device. For more information, see Connect to the internet or other networks using NAT devices. • Elastic IP addresses for IPv6 are not supported. • You can tag an Elastic IP address that's allocated for use in a VPC, however, cost allocation tags are not supported. If you recover an Elastic IP address, tags are not recovered. • You can access an Elastic IP address from the internet when the security group and network ACL allow traffic from the source IP address. The reply traffic from within the VPC back to the internet requires an internet gateway. For more information, see Security groups and Network ACLs. • You can use any of the following options for the Elastic IP addresses: • Have Amazon provide the Elastic IP addresses. When you select this option, you can associate the Elastic IP addresses with a network border group. This is the location from which we advertise the CIDR block. Setting the network border group limits the CIDR block to this group. • Use your own IP addresses. For information about bringing your own IP addresses, see Bring your own IP addresses (BYOIP) in the Amazon EC2 User Guide. Elastic IP address concepts and rules 313 Amazon Virtual Private Cloud User Guide • Public IPv4 addresses support cost allocation tags. If you apply tags to Elastic IP addresses, you can use those tags to track public IPv4 address costs in AWS Cost Explorer. Before you can use tags as cost allocation tags, you must activate the tags. For more information, see Activating user-defined cost allocation tags in the AWS Billing User Guide. Note that after you create and apply user-defined tags to your resources, it can take up to 24 hours for the tag keys to appear on your cost allocation tags page for activation. Once the cost allocation tags are activated... • For all public IPv4 addresses (including public IPv4 addresses assigned to EC2 instances and Elastic IP addresses) that are associated with an elastic network interface, you can view the costs associated with public IPv4 addresses in Cost Explorer by choosing Usage type > PublicIPv4InUseAddress (Hrs). • If a tagged Elastic IP address is not associated with an ENI or is associated with a stopped resource (like a stopped EC2 instance), it's considered an idle IPv4 address. You can view the costs associated with idle IPv4 addresses in Cost Explorer by choosing Usage type > PublicIPv4IdleAddress (Hrs). For more information about Cost Explorer, see Analyzing your costs with AWS Cost Explorer in the AWS Billing User Guide. Elastic IP addresses are regional. For more information about using Global Accelerator to provision global IP addresses, see Using global static IP addresses instead of regional static IP addresses in the AWS Global Accelerator Developer Guide. For more information about pricing for Elastic IP addresses, see Public IPv4 address in Amazon VPC Pricing. Start using Elastic IP addresses The following sections describe how you can get started using Elastic IP addresses. Tasks • 1. Allocate an Elastic IP address • 2. Associate an Elastic IP address • 3. Disassociate an Elastic IP address • 4. Transfer Elastic IP addresses Start using Elastic IP addresses 314 Amazon Virtual Private Cloud • 5. Release an Elastic IP address • 6. Recover an Elastic IP address • Command line overview 1. Allocate an Elastic IP address User Guide Before you use an Elastic IP, you must allocate one for use in your VPC. To allocate an Elastic IP address 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Elastic IPs. 3. Choose Allocate Elastic IP address. 4. (Optional) When you allocate an Elastic IP address (EIP), you choose the Network border group in which to allocate the EIP. A network border group is a collection of Availability Zones (AZs), Local Zones, or Wavelength Zones from which AWS advertises a public IP address. Local Zones and Wavelength Zones may have different network border groups than the AZs in a Region to ensure minimum latency or physical distance between the AWS network and the customers accessing the resources in these Zones. Important You must allocate an EIP in the same network border group as the AWS resource that will be associated with the EIP. An EIP in one network border group can only be advertised in zones in that network border group and not in any other zones represented by other network border groups. If you have Local Zones or Wavelength Zones enabled (for more information, see Enable a Local Zone or Enable Wavelength Zones), you can choose a network border group for AZs, Local
vpc-ug-114
vpc-ug.pdf
114
or physical distance between the AWS network and the customers accessing the resources in these Zones. Important You must allocate an EIP in the same network border group as the AWS resource that will be associated with the EIP. An EIP in one network border group can only be advertised in zones in that network border group and not in any other zones represented by other network border groups. If you have Local Zones or Wavelength Zones enabled (for more information, see Enable a Local Zone or Enable Wavelength Zones), you can choose a network border group for AZs, Local Zones, or Wavelength Zones. Choose the network border group carefully as the EIP and the AWS resource it is associated with must reside in the same network border group. You can use the EC2 console to view the network border group that your Availability Zones, Local Zones, or Wavelength Zones are in (see Local Zones). Typically, all Availability Zones in a Region belong to the same network border group, whereas Local Zones or Wavelength Zones belong to their own separate network border groups. Start using Elastic IP addresses 315 Amazon Virtual Private Cloud User Guide If you don't have Local Zones or Wavelength Zones enabled, when you allocate an EIP, the network border group that represents all of the AZs for the Region (such as us-west-2) is predefined for you and you cannot change it. This means that the EIP that you allocate to this network border group will be advertised in all AZs in the Region you're in. 5. For Public IPv4 address pool choose one of the following: • Amazon's pool of IP addresses—If you want an IPv4 address to be allocated from Amazon's pool of IP addresses. • My pool of public IPv4 addresses—If you want to allocate an IPv4 address from an IP address pool that you have brought to your AWS account. This option is disabled if you do not have any IP address pools. • Customer owned pool of IPv4 addresses—If you want to allocate an IPv4 address from a pool created from your on-premises network for use with an Outpost. This option is only available if you have an Outpost. 6. (Optional) Add or remove a tag. [Add a tag] Choose Add new tag and do the following: • For Key, enter the key name. • For Value, enter the key value. [Remove a tag] Choose Remove to the right of the tag’s Key and Value. 7. Choose Allocate. 2. Associate an Elastic IP address You can associate an Elastic IP with a running instance or network interface in your VPC. After you associate the Elastic IP address with your instance, the instance receives a public DNS hostname if DNS hostnames are enabled. For more information, see DNS attributes for your VPC. To associate an Elastic IP address with an instance or network interface 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Elastic IPs. Start using Elastic IP addresses 316 Amazon Virtual Private Cloud User Guide 3. Select an Elastic IP address that's allocated for use with a VPC (the Scope column has a value of vpc), and then choose Actions, Associate Elastic IP address. 4. Choose Instance or Network interface, and then select either the instance or network interface ID. Select the private IP address with which to associate the Elastic IP address. Choose Associate. 3. Disassociate an Elastic IP address To change the resource that the Elastic IP address is associated with, you must first disassociate it from the currently associated resource. To disassociate an Elastic IP address 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Elastic IPs. Select the Elastic IP address, and then choose Actions, Disassociate Elastic IP address. 4. When prompted, choose Disassociate. 4. Transfer Elastic IP addresses This section describes how to transfer Elastic IP addresses from one AWS account to another. Transferring Elastic IP addresses can be helpful in the following situations: • Organizational restructuring – Use Elastic IP address transfers to quickly move workloads from one AWS account to another. You don't have to wait for new Elastic IP addresses to be allowlisted in your security groups and NACLs. • Centralized security administration – Use a centralized AWS security account to track and transfer Elastic IP addresses that have been vetted for security compliance. • Disaster recovery – Use Elastic IP address transfers to quickly remap IPs for public-facing internet workloads during emergency events. There is no charge for transferring Elastic IP addresses. Tasks • Enable Elastic IP address transfer • Disable Elastic IP address transfer Start using Elastic IP addresses 317 Amazon Virtual Private Cloud User Guide • Accept a transferred Elastic IP address Enable Elastic IP address transfer This section
vpc-ug-115
vpc-ug.pdf
115
allowlisted in your security groups and NACLs. • Centralized security administration – Use a centralized AWS security account to track and transfer Elastic IP addresses that have been vetted for security compliance. • Disaster recovery – Use Elastic IP address transfers to quickly remap IPs for public-facing internet workloads during emergency events. There is no charge for transferring Elastic IP addresses. Tasks • Enable Elastic IP address transfer • Disable Elastic IP address transfer Start using Elastic IP addresses 317 Amazon Virtual Private Cloud User Guide • Accept a transferred Elastic IP address Enable Elastic IP address transfer This section describes how to accept a transferred Elastic IP address. Note the following limitations related to enabling Elastic IP addresses for transfer: • You can transfer Elastic IP addresses from any AWS account (source account) to any other AWS account in the same AWS Region (transfer account). • When you transfer an Elastic IP address, there is a two-step handshake between the AWS accounts. When the source account starts the transfer, the transfer accounts have seven days to accept the Elastic IP address transfer. During those seven days, the source account can view the pending transfer (for example in the AWS console or by using the describe-address-transfers AWS CLI command). After seven days, the transfer expires and ownership of the Elastic IP address returns to the source account. • Accepted transfers are visible to the source account (for example in the AWS console or by using the describe-address-transfers AWS CLI command) for 14 days after the transfers have been accepted. • AWS does not notify transfer accounts about pending Elastic IP address transfer requests. The owner of the source account must notify the owner of the transfer account that there is an Elastic IP address transfer request that they must accept. • Any tags that are associated with an Elastic IP address being transferred are reset when the transfer is complete. • You cannot transfer Elastic IP addresses allocated from public IPv4 address pools that you bring to your AWS account – commonly referred to as Bring Your Own IP (BYOIP) address pools. • If you attempt to transfer an Elastic IP address that has a reverse DNS record associated with it, you can begin the transfer process, but the transfer account will not be able to accept the transfer until the associated DNS record is removed. • If you have enabled and configured AWS Outposts, you might have allocated Elastic IP addresses from a customer-owned IP address pool (CoIP). You cannot transfer Elastic IP addresses allocated from a CoIP. However, you can use AWS RAM to share a CoIP with another account. For more information, see Customer-owned IP addresses in the AWS Outposts User Guide. • You can use Amazon VPC IPAM to track the transfer of Elastic IP addresses to accounts in an organization from AWS Organizations. For more information, see View IP address history. If an Start using Elastic IP addresses 318 Amazon Virtual Private Cloud User Guide Elastic IP address is transferred to an AWS account outside of the organization, the IPAM audit history of the Elastic IP address is lost. These steps must be completed by the source account. To enable Elastic IP address transfer 1. Ensure that you're using the source AWS account. 2. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 3. 4. 5. In the navigation pane, choose Elastic IPs. Select one or more Elastic IP address to enable for transfer and choose Actions, Enable transfer. If you are transferring multiple Elastic IP addresses, you’ll see the Transfer type option. Choose one of the following options: • Choose Single account if you are transferring the Elastic IP addresses to a single AWS account. • Choose Multiple accounts if you are transferring the Elastic IP addresses to multiple AWS accounts. 6. Under Transfer account ID, enter the IDs of the AWS accounts that you want to transfer the Elastic IP addresses to. 7. Confirm the transfer by entering enable in the text box. 8. Choose Submit. 9. To accept the transfer, see Accept a transferred Elastic IP address. To disable the transfer, see Disable Elastic IP address transfer. Disable Elastic IP address transfer This section describes how to disable an Elastic IP transfer after the transfer has been enabled. These steps must be completed by the source account that enabled the transfer. To disable an Elastic IP address transfer 1. Ensure that you're using the source AWS account. 2. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. Start using Elastic IP addresses 319 Amazon Virtual Private Cloud User Guide 3. 4. 5. In the navigation pane, choose Elastic IPs. In the resource list of Elastic IPs, ensure that you have the property enabled that shows the column Transfer status. Select one or more Elastic IP address
vpc-ug-116
vpc-ug.pdf
116
describes how to disable an Elastic IP transfer after the transfer has been enabled. These steps must be completed by the source account that enabled the transfer. To disable an Elastic IP address transfer 1. Ensure that you're using the source AWS account. 2. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. Start using Elastic IP addresses 319 Amazon Virtual Private Cloud User Guide 3. 4. 5. In the navigation pane, choose Elastic IPs. In the resource list of Elastic IPs, ensure that you have the property enabled that shows the column Transfer status. Select one or more Elastic IP address that have a Transfer status of Pending, and choose Actions, Disable transfer. 6. Confirm by entering disable in the text box. 7. Choose Submit. Accept a transferred Elastic IP address This section describes how to accept a transferred Elastic IP address. When you transfer an Elastic IP address, there is a two-step handshake between the AWS accounts. When the source account starts the transfer, the transfer accounts have seven days to accept the Elastic IP address transfer. During those seven days, the source account can view the pending transfer (for example in the AWS console or by using the describe-address-transfers AWS CLI command). After seven days, the transfer expires and ownership of the Elastic IP address returns to the source account. When accepting transfers, note the following exceptions that might occur and how to resolve them: • AddressLimitExceeded: If your transfer account has exceeded the Elastic IP address quota, the source account can enable Elastic IP address transfer, but this exception occurs when the transfer account tries to accept the transfer. By default, all AWS accounts are limited to 5 Elastic IP addresses per Region. See Elastic IP address limit in the Amazon EC2 User Guide for instructions on increasing the limit. • InvalidTransfer.AddressCustomPtrSet: If you or someone in your organization has configured the Elastic IP address that you are attempting to transfer to use reverse DNS lookup, the source account can enable transfer for the Elastic IP address, but this exception occurs when the transfer account tries to accept the transfer. To resolve this issue, the source account must remove the DNS record for the Elastic IP address. For more information, see Remove a reverse DNS record in the Amazon EC2 User Guide. • InvalidTransfer.AddressAssociated: If an Elastic IP address is associated with an ENI or EC2 instance, the source account can enable transfer for the Elastic IP address, but this exception occurs when the transfer account tries to accept the transfer. To resolve this issue, the source Start using Elastic IP addresses 320 Amazon Virtual Private Cloud User Guide account must disassociate the Elastic IP address. For more information, see Disassociate an Elastic IP address in the Amazon EC2 User Guide. For any other exceptions, contact Support. These steps must be completed by the transfer account. To accept an Elastic IP address transfer 1. Ensure that you're using the transfer account. 2. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 3. In the navigation pane, choose Elastic IPs. 4. Choose Actions, Accept transfer. 5. No tags that are associated with the Elastic IP address being transferred are transferred with the Elastic IP address when you accept the transfer. If you want to define a Name tag for the Elastic IP address that you are accepting, select Create a tag with a key of 'Name' and a value that you specify. 6. 7. Enter the Elastic IP address that you want to transfer. If you are accepting multiple transferred Elastic IP addresses, choose Add address to enter an additional Elastic IP address. 8. Choose Submit. 5. Release an Elastic IP address If you no longer need an Elastic IP address, we recommend that you release it. You incur charges for any Elastic IP address that's allocated for use with a VPC even if it's not associated with an instance. The Elastic IP address must not be associated with an instance or network interface. To release an Elastic IP address 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Elastic IPs. Select the Elastic IP address, and then choose Actions, Release Elastic IP addresses. 4. When prompted, choose Release. Start using Elastic IP addresses 321 Amazon Virtual Private Cloud User Guide 6. Recover an Elastic IP address If you release an Elastic IP address but change your mind, you might be able to recover it. You cannot recover the Elastic IP address if it has been allocated to another AWS account, or if recovering it results in you exceeding your Elastic IP address quota. You can recover an Elastic IP address by using the Amazon EC2 API or a command line tool. To recover an Elastic IP address using the AWS CLI Use the allocate-address
vpc-ug-117
vpc-ug.pdf
117
When prompted, choose Release. Start using Elastic IP addresses 321 Amazon Virtual Private Cloud User Guide 6. Recover an Elastic IP address If you release an Elastic IP address but change your mind, you might be able to recover it. You cannot recover the Elastic IP address if it has been allocated to another AWS account, or if recovering it results in you exceeding your Elastic IP address quota. You can recover an Elastic IP address by using the Amazon EC2 API or a command line tool. To recover an Elastic IP address using the AWS CLI Use the allocate-address command and specify the IP address using the --address parameter. aws ec2 allocate-address --domain vpc --address 203.0.113.3 Command line overview You can perform the tasks described in this section using the command line or an API. For more information about the command line interfaces and a list of available API actions, see Working with Amazon VPC. Accept Elastic IP address transfer • accept-address-transfer (AWS CLI) • Approve-EC2AddressTransfer (AWS Tools for Windows PowerShell) Allocate an Elastic IP address • allocate-address (AWS CLI) • New-EC2Address (AWS Tools for Windows PowerShell) Associate an Elastic IP address with an instance or network interface • associate-address (AWS CLI) • Register-EC2Address (AWS Tools for Windows PowerShell) Describe Elastic IP address transfers • describe-address-transfers (AWS CLI) Start using Elastic IP addresses 322 Amazon Virtual Private Cloud User Guide • Get-EC2AddressTransfer (AWS Tools for Windows PowerShell) Disable Elastic IP address transfer • disable-address-transfer (AWS CLI) • Disable-EC2AddressTransfer (AWS Tools for Windows PowerShell) Disassociate an Elastic IP address • disassociate-address (AWS CLI) • Unregister-EC2Address (AWS Tools for Windows PowerShell) Enable Elastic IP address transfer • enable-address-transfer (AWS CLI) • Enable-EC2AddressTransfer (AWS Tools for Windows PowerShell) Release an Elastic IP address • release-address (AWS CLI) • Remove-EC2Address (AWS Tools for Windows PowerShell) Tag an Elastic IP address • create-tags (AWS CLI) • New-EC2Tag (AWS Tools for Windows PowerShell) View your Elastic IP addresses • describe-addresses (AWS CLI) • Get-EC2Address (AWS Tools for Windows PowerShell) Start using Elastic IP addresses 323 Amazon Virtual Private Cloud User Guide Connect your VPC to other VPCs and networks using a transit gateway You can connect your virtual private clouds (VPC) and on-premises networks using a transit gateway, which acts as a central hub, routing traffic between VPCs, VPN connections, and AWS Direct Connect connections. One of the key benefits of using a transit gateway is the ability to centralize and simplify the management of connectivity between your VPCs and on-premises networks. Rather than configuring multiple VPN connections or Direct Connect links, you can leverage the transit gateway as a single point of integration, which can help reduce the overall complexity and operational overhead of your network architecture. The pricing for using a transit gateway is based on the volume of data transferred through the gateway. There is a per-GB rate for data transferred in and out of the transit gateway, as well as a separate per-hour rate for the transit gateway resource itself. The specific pricing can vary by AWS Region and is subject to change, so it's important to refer to the current AWS Transit Gateway pricing page for the most up-to-date information. By understanding the pricing model for transit gateways, you can better plan and budget for the ongoing costs associated with this AWS networking service. This, combined with the operational efficiencies and connectivity benefits, makes transit gateways a compelling choice for organizations looking to build scalable and cost- effective hybrid cloud solutions. The following table describes some common use case for transit gateways. For more information about each use case, see Example transit gateway scenarios in the AWS Transit Gateway User Guide. Example Usage Centralized router Isolated VPCs Configure your transit gateway as a centralized router that connects all of your VPCs, AWS Direct Connect, and AWS Site- to-Site VPN connections. Configure your transit gateway as multiple isolated routers. This is similar to using multiple transit gateways, but provides more flexibility in cases where the routes and attachments might change. AWS Transit Gateway 324 Amazon Virtual Private Cloud User Guide Example Usage Isolated VPCs with shared services Configure your transit gateway as multiple isolated routers that use a shared service. This is similar to using multiple transit gateways, but provides more flexibility in cases where the routes and attachments might change. For more information, see AWS Transit Gateway. Connect your VPC to remote networks using AWS Virtual Private Network You can connect your VPC to remote networks and users using the following VPN connectivity options. VPN connectivity option Description AWS Site-to-Site VPN You can create an IPsec VPN connection between your VPC and your remote network. On the AWS side of the Site-to-Site VPN AWS Client VPN connection, a virtual private gateway or transit gateway provides two VPN endpoints (tunnels) for
vpc-ug-118
vpc-ug.pdf
118
is similar to using multiple transit gateways, but provides more flexibility in cases where the routes and attachments might change. For more information, see AWS Transit Gateway. Connect your VPC to remote networks using AWS Virtual Private Network You can connect your VPC to remote networks and users using the following VPN connectivity options. VPN connectivity option Description AWS Site-to-Site VPN You can create an IPsec VPN connection between your VPC and your remote network. On the AWS side of the Site-to-Site VPN AWS Client VPN connection, a virtual private gateway or transit gateway provides two VPN endpoints (tunnels) for automatic failover. You configure your customer gateway device on the remote side of the Site-to-Site VPN connection. For more information, see the AWS Site-to-Site VPN User Guide. AWS Client VPN is a managed client-based VPN service that enables you to securely access your AWS resources or your on-premises network. With AWS Client VPN, you configure an endpoint to which your users can connect to establish a secure TLS VPN session. This enables clients to access resources in AWS or on-premises from any location using an OpenVPN-based VPN client. For more information, see the AWS Client VPN Administrator Guide. AWS VPN CloudHub If you have more than one remote network (for example, multiple branch offices), you can create multiple AWS Site-to-Site VPN AWS Virtual Private Network 325 Amazon Virtual Private Cloud VPN connectivity option Description User Guide connections via your virtual private gateway to enable communication between these networks. For more information, see Providing secure communication between sites using VPN CloudHub in the AWS Site-to- Site VPN User Guide. Third party software VPN appliance You can create a VPN connection to your remote network by using an Amazon EC2 instance in your VPC that's running a third party software VPN appliance. AWS does not provide or maintain third party software VPN appliances; however, you can choose from a range of products provided by partners and open source communities. Find third party software VPN appliances on the AWS Marketplace. You can also use AWS Direct Connect to create a dedicated private connection from a remote network to your VPC. You can combine this connection with an AWS Site-to-Site VPN to create an IPsec-encrypted connection. For more information, see What is AWS Direct Connect? in the AWS Direct Connect User Guide. Connect VPCs using VPC peering A VPC peering connection is a networking feature that enables secure and direct communication between two virtual private clouds (VPCs) within the AWS infrastructure. This private connection allows resources in the peered VPCs to interact with each other as if they were part of the same network, eliminating the need to traverse the public internet. The process of creating a VPC peering connection leverages the existing VPC infrastructure to establish this connection, without the requirement of a gateway, AWS Site-to-Site VPN, or VPC peering connections 326 Amazon Virtual Private Cloud User Guide any additional physical hardware. This design ensures that there is no single point of failure or bandwidth bottleneck. One of the key advantages of a VPC peering connection is the ability to connect VPCs across different AWS accounts or even different AWS Regions. This flexibility allows organizations to seamlessly integrate their cloud resources, whether they are within the same account or spread across multiple accounts and geographic locations. The private nature of the connection also ensures that all data traffic between the peered VPCs remains within the AWS network, without ever traversing the public internet. The use cases for VPC peering connections are wide-ranging. Organizations can leverage this feature to enable secure communication between different tiers of an application (such as web servers and database servers), facilitate the sharing of resources between multiple teams or business units, or even enable hybrid cloud architectures by connecting on-premises networks to their AWS VPCs. A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them privately. Resources in peered VPCs can communicate with each other as if they are within the same network. You can create a VPC peering connection between your own VPCs, with a VPC in another AWS account, or with a VPC in a different AWS Region. Traffic between peered VPCs never traverses the public internet. For more information, see the Amazon VPC Peering Guide. VPC peering connections 327 Amazon Virtual Private Cloud User Guide Monitoring your VPC You can use the following tools to monitor traffic or network access in your virtual private cloud (VPC). VPC Flow Logs You can use VPC Flow Logs to capture detailed information about the traffic going to and from network interfaces in your VPCs. Amazon CloudWatch Internet Monitor You can use Internet Monitor for visibility into how internet issues impact the performance and availability between your applications hosted on AWS
vpc-ug-119
vpc-ug.pdf
119
Traffic between peered VPCs never traverses the public internet. For more information, see the Amazon VPC Peering Guide. VPC peering connections 327 Amazon Virtual Private Cloud User Guide Monitoring your VPC You can use the following tools to monitor traffic or network access in your virtual private cloud (VPC). VPC Flow Logs You can use VPC Flow Logs to capture detailed information about the traffic going to and from network interfaces in your VPCs. Amazon CloudWatch Internet Monitor You can use Internet Monitor for visibility into how internet issues impact the performance and availability between your applications hosted on AWS and your end users. You can also explore, in near real-time, how to improve the projected latency of your application by switching to use other services, or by rerouting traffic to your workload through different AWS Regions. For more information, see Using Amazon CloudWatch Internet Monitor. Amazon VPC IP Address Manager (IPAM) You can use IPAM to plan, track, and monitor IP addresses for your workloads. For more information, see IP Address Manager. Traffic Mirroring You can use this feature to copy network traffic from a network interface of an Amazon EC2 instance and send it to out-of-band security and monitoring appliances for deep packet inspection. You can detect network and security anomalies, gain operational insights, implement compliance and security controls, and troubleshoot issues. For more information, see Traffic Mirroring. Reachability Analyzer You can use this tool to analyze and debug network reachability between two resources in your VPC. After you specify the source and destination resources, Reachability Analyzer produces hop-by-hop details of the virtual path between them when they are reachable, and identifies the blocking component when they are unreachable. For more information, see Reachability Analyzer. Network Access Analyzer You can use Network Access Analyzer to understand network access to your resources. This helps you identify improvements to your network security posture and demonstrate that your 328 Amazon Virtual Private Cloud User Guide network meets specific compliance requirements. For more information, see Network Access Analyzer. CloudTrail logs AWS CloudTrail logs API calls for Amazon VPC, such as: • Which API calls were made (such as actions like creating or modifying VPC resources) • The source IP address of the call • Who made the call • When the call was made Separate logs are created for CreateVpc, DeleteVpc and CreateDefaultVpc actions. These logs also include the default resources (like any default internet gateways or default security groups) created and associated with the VPC. For more information, see Log Amazon EC2 API calls using AWS CloudTrail in the Amazon EC2 User Guide. Logging IP traffic using VPC Flow Logs VPC Flow Logs is a feature that enables you to capture information about the IP traffic going to and from network interfaces in your VPC. Flow log data can be published to the following locations: Amazon CloudWatch Logs, Amazon S3, or Amazon Data Firehose. The configured delivery path and permissions that enable network traffic logs to be sent to a destination like CloudWatch Logs or S3 are referred to as subscriptions. After you create a flow log, you can retrieve and view the flow log records in the log group, bucket, or delivery stream that you configured. Flow logs can help you with a number of tasks, such as: • Diagnosing overly restrictive security group rules • Monitoring the traffic that is reaching your instance • Determining the direction of the traffic to and from the network interfaces Flow log data is collected outside of the path of your network traffic, and therefore does not affect network throughput or latency. You can create or delete flow logs without any risk of impact to network performance. VPC Flow Logs 329 Amazon Virtual Private Cloud User Guide Note This section only talks about flow logs for VPCs. For information about flow logs for transit gateways introduced in version 6, see Logging network traffic using Transit Gateway Flow Logs in the Amazon VPC Transit Gateways User Guide. Contents • Flow logs basics • Flow log records • Flow log record examples • Flow log limitations • Pricing • Work with flow logs • Publish flow logs to CloudWatch Logs • Publish flow logs to Amazon S3 • Publish flow logs to Amazon Data Firehose • Query flow logs using Amazon Athena • Troubleshoot VPC Flow Logs Flow logs basics You can create a flow log for a VPC, a subnet, or a network interface. If you create a flow log for a subnet or VPC, each network interface in that subnet or VPC is monitored. Flow log data for a monitored network interface is recorded as flow log records, which are log events consisting of fields that describe the traffic flow. For more information, see Flow log records. To create a flow log, you
vpc-ug-120
vpc-ug.pdf
120
Amazon S3 • Publish flow logs to Amazon Data Firehose • Query flow logs using Amazon Athena • Troubleshoot VPC Flow Logs Flow logs basics You can create a flow log for a VPC, a subnet, or a network interface. If you create a flow log for a subnet or VPC, each network interface in that subnet or VPC is monitored. Flow log data for a monitored network interface is recorded as flow log records, which are log events consisting of fields that describe the traffic flow. For more information, see Flow log records. To create a flow log, you specify: • The resource for which to create the flow log • The type of traffic to capture (accepted traffic, rejected traffic, or all traffic) • The destinations to which you want to publish the flow log data Flow logs basics 330 Amazon Virtual Private Cloud User Guide In the following example, you create a flow log that captures accepted traffic for the network interface for one of the EC2 instances in a private subnet and publishes the flow log records to an Amazon S3 bucket. In the following example, a flow log captures all traffic for a subnet and publishes the flow log records to Amazon CloudWatch Logs. The flow log captures traffic for all network interfaces in the subnet. Flow logs basics 331 Amazon Virtual Private Cloud User Guide After you create a flow log, it can take several minutes to begin collecting and publishing data to the chosen destinations. Flow logs do not capture real-time log streams for your network interfaces. For more information, see 2. Create a flow log. If you launch an instance into your subnet after you create a flow log for your subnet or VPC, we create a log stream (for CloudWatch Logs) or log file object (for Amazon S3) for the new network interface as soon as there is network traffic for the network interface. You can create flow logs for network interfaces that are created by other AWS services, such as: • Elastic Load Balancing • Amazon RDS • Amazon ElastiCache • Amazon Redshift Flow logs basics 332 Amazon Virtual Private Cloud • Amazon WorkSpaces • NAT gateways • Transit gateways User Guide Regardless of the type of network interface, you must use the Amazon EC2 console or the Amazon EC2 API to create a flow log for a network interface. You can apply tags to your flow logs. Each tag consists of a key and an optional value, both of which you define. Tags can help you organize your flow logs, for example by purpose or owner. If you no longer require a flow log, you can delete it. Deleting a flow log disables the flow log service for the resource, so that no new flow log records are created or published. Deleting a flow log does not delete any existing flow log data. After you delete a flow log, you can delete the flow log data directly from the destination when you are finished with it. For more information, see 4. Delete a flow log. Flow log records A flow log record represents a network flow in your VPC. By default, each record captures a network internet protocol (IP) traffic flow (characterized by a 5-tuple on a per network interface basis) that occurs within an aggregation interval, also referred to as a capture window. Each record is a string with fields separated by spaces. A record includes values for the different components of the IP flow, for example, the source, destination, and protocol. When you create a flow log, you can use the default format for the flow log record, or you can specify a custom format. Contents • Aggregation interval • Default format • Custom format • Available fields Aggregation interval The aggregation interval is the period of time during which a particular flow is captured and aggregated into a flow log record. By default, the maximum aggregation interval is 10 minutes. Flow log records 333 Amazon Virtual Private Cloud User Guide When you create a flow log, you can optionally specify a maximum aggregation interval of 1 minute. Flow logs with a maximum aggregation interval of 1 minute produce a higher volume of flow log records than flow logs with a maximum aggregation interval of 10 minutes. When a network interface is attached to a Nitro-based instance, the aggregation interval is always 1 minute or less, regardless of the specified maximum aggregation interval. After data is captured within an aggregation interval, it takes additional time to process and publish the data to CloudWatch Logs or Amazon S3. The flow log service typically delivers logs to CloudWatch Logs in about 5 minutes and to Amazon S3 in about 10 minutes. However, log delivery is on a best effort
vpc-ug-121
vpc-ug.pdf
121
minute produce a higher volume of flow log records than flow logs with a maximum aggregation interval of 10 minutes. When a network interface is attached to a Nitro-based instance, the aggregation interval is always 1 minute or less, regardless of the specified maximum aggregation interval. After data is captured within an aggregation interval, it takes additional time to process and publish the data to CloudWatch Logs or Amazon S3. The flow log service typically delivers logs to CloudWatch Logs in about 5 minutes and to Amazon S3 in about 10 minutes. However, log delivery is on a best effort basis, and your logs might be delayed beyond the typical delivery time. Default format With the default format, the flow log records include the version 2 fields, in the order shown in the available fields table. You cannot customize or change the default format. To capture additional fields or a different subset of fields, specify a custom format instead. Custom format With a custom format, you specify which fields are included in the flow log records and in which order. This enables you to create flow logs that are specific to your needs and to omit fields that are not relevant. Using a custom format can reduce the need for separate processes to extract specific information from the published flow logs. You can specify any number of the available flow log fields, but you must specify at least one. Available fields The following table describes all of the available fields for a flow log record. The Version column indicates the VPC Flow Logs version in which the field was introduced. The default format includes all version 2 fields, in the same order that they appear in the table. When publishing flow log data to Amazon S3, the data type for the fields depends on the flow log format. If the format is plain text, all fields are of type STRING. If the format is Parquet, see the table for the field data types. If a field is not applicable or could not be computed for a specific record, the record displays a '-' symbol for that entry. Metadata fields that do not come directly from the packet header are best effort approximations, and their values might be missing or inaccurate. Flow log records 334 Amazon Virtual Private Cloud Field version Description User Guide Version The VPC Flow Logs version. If you use the default format, the version is 2. If you use a custom format, the version is the highest 2 version among the specified fields. For example, if you specify only fields from version 2, the version is 2. If you specify a mixture of fields from versions 2, 3, and 4, the version is 4. Parquet data type: INT_32 account-id The AWS account ID of the owner of the source network interface for which traffic is recorded. If the network interface is created 2 by an AWS service, for example when creating a VPC endpoint or Network Load Balancer, the record might display unknown for this field. Parquet data type: STRING interface-id The ID of the network interface for which the traffic is recorded. srcaddr dstaddr Parquet data type: STRING For incoming traffic, this is the IP address of the source of traffic. For outgoing traffic, this is the private IPv4 address or the IPv6 address of the network interface sending the traffic. See also pkt- srcaddr. Parquet data type: STRING The destination address for outgoing traffic, or the IPv4 or IPv6 address of the network interface for incoming traffic on the network interface. The IPv4 address of the network interface is always its private IPv4 address. See also pkt-dstaddr. Parquet data type: STRING srcport The source port of the traffic. Parquet data type: INT_32 2 2 2 2 Flow log records 335 Amazon Virtual Private Cloud Field Description dstport The destination port of the traffic. Parquet data type: INT_32 protocol The IANA protocol number of the traffic. For more information, see Assigned Internet Protocol Numbers. Parquet data type: INT_32 packets The number of packets transferred during the flow. Parquet data type: INT_64 bytes The number of bytes transferred during the flow. start end Parquet data type: INT_64 The time, in Unix seconds, when the first packet of the flow was received within the aggregation interval. This might be up to 60 seconds after the packet was transmitted or received on the network interface. Parquet data type: INT_64 The time, in Unix seconds, when the last packet of the flow was received within the aggregation interval. This might be up to 60 seconds after the packet was transmitted or received on the network interface. Parquet data type: INT_64 User Guide Version 2 2 2 2 2 2 Flow log records 336 Amazon Virtual Private Cloud Field action Description
vpc-ug-122
vpc-ug.pdf
122
The time, in Unix seconds, when the first packet of the flow was received within the aggregation interval. This might be up to 60 seconds after the packet was transmitted or received on the network interface. Parquet data type: INT_64 The time, in Unix seconds, when the last packet of the flow was received within the aggregation interval. This might be up to 60 seconds after the packet was transmitted or received on the network interface. Parquet data type: INT_64 User Guide Version 2 2 2 2 2 2 Flow log records 336 Amazon Virtual Private Cloud Field action Description The action that is associated with the traffic: • ACCEPT — The traffic was accepted. • REJECT — The traffic was rejected. For example, the traffic was not allowed by the security groups or network ACLs, or packets arrived after the connection was closed. Parquet data type: STRING log-status The logging status of the flow log: User Guide Version 2 2 • OK — Data is logging normally to the chosen destinations. • NODATA — There was no network traffic to or from the network interface during the aggregation interval. • SKIPDATA — Some flow log records were skipped during the aggregation interval. This might be because of an internal capacity constraint, or an internal error. Some flow log records may be skipped during the aggregati on interval (see log-status in Available fields). This may be caused by an internal AWS capacity constraint or internal error. If you are using AWS Cost Explorer to view VPC flow log charges and some flow logs are skipped during the flow log aggregati on interval, the number of flow logs reported in AWS Cost Explorer will be higher than the number of flow logs published by Amazon VPC. Parquet data type: STRING vpc-id The ID of the VPC that contains the network interface for which the traffic is recorded. 3 Parquet data type: STRING Flow log records 337 Amazon Virtual Private Cloud Field Description subnet-id The ID of the subnet that contains the network interface for which the traffic is recorded. Parquet data type: STRING instance-id The ID of the instance that's associated with network interface for which the traffic is recorded, if the instance is owned by you. Returns a '-' symbol for a requester-managed network interface; for example, the network interface for a NAT gateway. Parquet data type: STRING User Guide Version 3 3 Flow log records 338 Amazon Virtual Private Cloud Field Description tcp-flags The bitmask value for the following TCP flags: User Guide Version 3 • FIN — 1 • SYN — 2 • RST — 4 • SYN-ACK — 18 If no supported flags are recorded, the TCP flag value is 0. For example, since tcp-flags does not support logging ACK or PSH flags, records for traffic with these unsupported flags will result in tcp-flags value 0. If, however, an unsupported flag is accompani ed by a supported flag, we will report the value of the supported flag. For example, if ACK is a part of SYN-ACK, it reports 18. And if there is a record like SYN+ECE, since SYN is a supported flag and ECE is not, the TCP flag value is 2. If for some reason the flag combination is invalid and the value cannot be calculated, the value is '-'. If no flags are sent, the TCP flag value is 0. TCP flags can be OR-ed during the aggregation interval. For short connections, the flags might be set on the same line in the flow log record, for example, 19 for SYN-ACK and FIN, and 3 for SYN and FIN. For an example, see TCP flag sequence. For general information about TCP flags (such as the meaning of flags like FIN, SYN, and ACK), see TCP segment structure on Wikipedia. Parquet data type: INT_32 type The type of traffic. The possible values are: IPv4 | IPv6 | EFA. For more information, see Elastic Fabric Adapter. 3 Parquet data type: STRING Flow log records 339 Amazon Virtual Private Cloud Field Description User Guide Version pkt-srcaddr The packet-level (original) source IP address of the traffic. Use this field with the srcaddr field to distinguish between the IP address 3 of an intermediate layer through which traffic flows, and the original source IP address of the traffic. For example, when traffic flows through a network interface for a NAT gateway, or where the IP address of a pod in Amazon EKS is different from the IP address of the network interface of the instance node on which the pod is running (for communication within a VPC). Parquet data type: STRING pkt-dstaddr The packet-level (original) destination IP address for the traffic. Use this field with the dstaddr field to distinguish between the IP 3 address of an intermediate layer
vpc-ug-123
vpc-ug.pdf
123
address 3 of an intermediate layer through which traffic flows, and the original source IP address of the traffic. For example, when traffic flows through a network interface for a NAT gateway, or where the IP address of a pod in Amazon EKS is different from the IP address of the network interface of the instance node on which the pod is running (for communication within a VPC). Parquet data type: STRING pkt-dstaddr The packet-level (original) destination IP address for the traffic. Use this field with the dstaddr field to distinguish between the IP 3 address of an intermediate layer through which traffic flows, and the final destination IP address of the traffic. For example, when traffic flows through a network interface for a NAT gateway, or where the IP address of a pod in Amazon EKS is different from the IP address of the network interface of the instance node on which the pod is running (for communication within a VPC). Parquet data type: STRING The Region that contains the network interface for which traffic is recorded. Parquet data type: STRING The ID of the Availability Zone that contains the network interface for which traffic is recorded. If the traffic is from a sublocation, the record displays a '-' symbol for this field. 4 4 Parquet data type: STRING region az-id Flow log records 340 Amazon Virtual Private Cloud Field Description User Guide Version sublocation-type The type of sublocation that's returned in the sublocation-id field. The possible values are: wavelength | outpost | localzone. If the 4 traffic is not from a sublocation, the record displays a '-' symbol for this field. Parquet data type: STRING sublocation-id The ID of the sublocation that contains the network interface for which traffic is recorded. If the traffic is not from a sublocation, the record displays a '-' symbol for this field. Parquet data type: STRING pkt-src-aws- service The name of the subset of IP address ranges for the pkt-srcad dr field, if the source IP address is for an AWS service. If the pkt- srcaddr belongs to an overlapped range, pkt-src-aws-service will only show one of the AWS service code. The possible values are: AMAZON | AMAZON_APPFLOW | AMAZON_CONNECT | API_GATEWAY | CHIME_MEETINGS | CHIME_VOICECONNECT OR | CLOUD9 | CLOUDFRONT | CODEBUILD | DYNAMODB | EBS | EC2 | EC2_INSTANCE_CONNECT | GLOBALACCELERATOR | KINESIS_VIDEO_STREAMS | ROUTE53 | ROUTE53_HEALTHCHECKS | ROUTE53_HEALTHCHECKS_PUBLISHING | ROUTE53_RESOLVER | S3 | WORKSPACES_GATEWAYS. Parquet data type: STRING pkt-dst-aws- service The name of the subset of IP address ranges for the pkt-dstaddr field, if the destination IP address is for an AWS service. For a list of possible values, see the pkt-src-aws-service field. Parquet data type: STRING flow-direction The direction of the flow with respect to the interface where traffic is captured. The possible values are: ingress | egress. Parquet data type: STRING 4 5 5 5 Flow log records 341 Amazon Virtual Private Cloud Field Description User Guide Version traffic-path The path that egress traffic takes to the destination. To determine whether the traffic is egress traffic, check the flow-direction field. 5 The possible values are as follows. If none of the values apply, the field is set to -. • 1 — Through another resource in the same VPC, including resources that create a network interface in the VPC • 2 — Through an internet gateway or a gateway VPC endpoint • 3 — Through a virtual private gateway • 4 — Through an intra-region VPC peering connection • 5 — Through an inter-region VPC peering connection • 6 — Through a local gateway • 7 — Through a gateway VPC endpoint (Nitro-based instances only) • 8 — Through an internet gateway (Nitro-based instances only) Parquet data type: INT_32 ecs-cluster-arn AWS Resource Name (ARN) of the ECS cluster if the traffic is from a running ECS task. To include this field in your subscription, you need permission to call ecs:ListClusters. Parquet data type: STRING ecs-cluster- name ecs-container- instance-arn Name of the ECS cluster if the traffic is from a running ECS task. To include this field in your subscription, you need permission to call ecs:ListClusters. Parquet data type: STRING ARN of the ECS container instance if the traffic is from a running ECS task on an EC2 instance. If the capacity provider is AWS Fargate, this field will be '-'. To include this field in your subscript ion, you need permission to call ecs:ListClusters and ecs:ListC ontainerInstances. Parquet data type: STRING 7 7 7 Flow log records 342 Amazon Virtual Private Cloud Field Description User Guide Version ecs-container- instance-id ID of the ECS container instance if the traffic is from a running ECS task on an EC2 instance. If the capacity provider is AWS Fargate, 7 this field will be '-'. To include this field in your
vpc-ug-124
vpc-ug.pdf
124
traffic is from a running ECS task on an EC2 instance. If the capacity provider is AWS Fargate, this field will be '-'. To include this field in your subscript ion, you need permission to call ecs:ListClusters and ecs:ListC ontainerInstances. Parquet data type: STRING 7 7 7 Flow log records 342 Amazon Virtual Private Cloud Field Description User Guide Version ecs-container- instance-id ID of the ECS container instance if the traffic is from a running ECS task on an EC2 instance. If the capacity provider is AWS Fargate, 7 this field will be '-'. To include this field in your subscription, you need permission to call ecs:ListClusters and ecs:ListContainerI nstances. Parquet data type: STRING ecs-container-id Docker runtime ID of the container if the traffic is from a running ECS task. If there are one or more containers in the ECS task, this will be the docker runtime ID of the first container. To include this field in your subscription, you need permission to call ecs:ListC lusters. Parquet data type: STRING ecs-second- container-id Docker runtime ID of the container if the traffic is from a running ECS task. If there are more than one containers in the ECS task, this will be the Docker runtime ID of the second container. To include this field in your subscription, you need permission to call ecs:ListClusters. Parquet data type: STRING 7 7 ecs-service- name Name of the ECS service if the traffic is from a running ECS task and the ECS task is started by an ECS service. If the ECS task is not 7 started by an ECS service, this field will be '-'. To include this field in your subscription, you need permission to call ecs:ListClusters and ecs:ListServices. Parquet data type: STRING ecs-task- definition-arn ARN of the ECS task definition if the traffic is from a running ECS task. To include this field in your subscription, you need permissio n to call ecs:ListClusters and ecs:ListTaskDefinitions Parquet data type: STRING 7 Flow log records 343 Amazon Virtual Private Cloud Field Description ecs-task-arn ARN of the ECS task if the traffic is from a running ECS task. To include this field in your subscription, you need permission to call ecs:ListClusters and ecs:ListTasks. Parquet data type: STRING ecs-task-id ID of the ECS task if the traffic is from a running ECS task. To include this field in your subscription, you need permission to call ecs:ListClusters and ecs:ListTasks. Parquet data type: STRING reject-reason Reason why traffic was rejected. Possible values: BPA. Returns a '-' for any other reject reason. For more information about VPC Block Public Access (BPA), see Block public access to VPCs and subnets. Parquet data type: STRING User Guide Version 7 7 8 Flow log record examples The following are examples of flow log records that capture specific traffic flows. For information about flow log record format, see Flow log records. For information about how to create flow logs, see Work with flow logs. Contents • Accepted and rejected traffic • No data and skipped records • Security group and network ACL rules • IPv6 traffic • TCP flag sequence • Traffic through a NAT gateway • Traffic through a transit gateway • Service name, traffic path, and flow direction Flow log record examples 344 Amazon Virtual Private Cloud User Guide Accepted and rejected traffic The following are examples of default flow log records. In this example, SSH traffic (destination port 22, TCP protocol) from IP address 172.31.16.139 to network interface with private IP address is 172.31.16.21 and ID eni-1235b8ca123456789 in account 123456789010 was allowed. 2 123456789010 eni-1235b8ca123456789 172.31.16.139 172.31.16.21 20641 22 6 20 4249 1418530010 1418530070 ACCEPT OK In this example, RDP traffic (destination port 3389, TCP protocol) to network interface eni-1235b8ca123456789 in account 123456789010 was rejected. 2 123456789010 eni-1235b8ca123456789 172.31.9.69 172.31.9.12 49761 3389 6 20 4249 1418530010 1418530070 REJECT OK No data and skipped records The following are examples of default flow log records. In this example, no data was recorded during the aggregation interval. 2 123456789010 eni-1235b8ca123456789 - - - - - - - 1431280876 1431280934 - NODATA VPC Flow Logs skips records when it can't capture flow log data during an aggregation interval because it exceeds internal capacity. A single skipped record can represent multiple flows that were not captured for the network interface during the aggregation interval. 2 123456789010 eni-11111111aaaaaaaaa - - - - - - - 1431280876 1431280934 - SKIPDATA Note Some flow log records may be skipped during the aggregation interval (see log-status in Available fields). This may be caused by an internal AWS capacity constraint or internal error. If you are using AWS Cost Explorer to view VPC flow log charges and some flow logs are skipped during the flow log aggregation interval, the number of flow logs reported in AWS Cost Explorer will be
vpc-ug-125
vpc-ug.pdf
125
single skipped record can represent multiple flows that were not captured for the network interface during the aggregation interval. 2 123456789010 eni-11111111aaaaaaaaa - - - - - - - 1431280876 1431280934 - SKIPDATA Note Some flow log records may be skipped during the aggregation interval (see log-status in Available fields). This may be caused by an internal AWS capacity constraint or internal error. If you are using AWS Cost Explorer to view VPC flow log charges and some flow logs are skipped during the flow log aggregation interval, the number of flow logs reported in AWS Cost Explorer will be higher than the number of flow logs published by Amazon VPC. Flow log record examples 345 Amazon Virtual Private Cloud User Guide Security group and network ACL rules If you're using flow logs to diagnose overly restrictive or permissive security group rules or network ACL rules, be aware of the statefulness of these resources. Security groups are stateful — this means that responses to allowed traffic are also allowed, even if the rules in your security group do not permit it. Conversely, network ACLs are stateless, therefore responses to allowed traffic are subject to network ACL rules. For example, you use the ping command from your home computer (IP address is 203.0.113.12) to your instance (the network interface's private IP address is 172.31.16.139). Your security group's inbound rules allow ICMP traffic but the outbound rules do not allow ICMP traffic. Because security groups are stateful, the response ping from your instance is allowed. Your network ACL permits inbound ICMP traffic but does not permit outbound ICMP traffic. Because network ACLs are stateless, the response ping is dropped and does not reach your home computer. In a default flow log, this is displayed as two flow log records: • An ACCEPT record for the originating ping that was allowed by both the network ACL and the security group, and therefore was allowed to reach your instance. • A REJECT record for the response ping that the network ACL denied. 2 123456789010 eni-1235b8ca123456789 203.0.113.12 172.31.16.139 0 0 1 4 336 1432917027 1432917142 ACCEPT OK 2 123456789010 eni-1235b8ca123456789 172.31.16.139 203.0.113.12 0 0 1 4 336 1432917094 1432917142 REJECT OK If your network ACL permits outbound ICMP traffic, the flow log displays two ACCEPT records (one for the originating ping and one for the response ping). If your security group denies inbound ICMP traffic, the flow log displays a single REJECT record, because the traffic was not permitted to reach your instance. IPv6 traffic The following is an example of a default flow log record. In the example, SSH traffic (port 22) from IPv6 address 2001:db8:1234:a100:8d6e:3477:df66:f105 to network interface eni-1235b8ca123456789 in account 123456789010 was allowed. Flow log record examples 346 Amazon Virtual Private Cloud User Guide 2 123456789010 eni-1235b8ca123456789 2001:db8:1234:a100:8d6e:3477:df66:f105 2001:db8:1234:a102:3304:8879:34cf:4071 34892 22 6 54 8855 1477913708 1477913820 ACCEPT OK TCP flag sequence This section contains examples of custom flow logs that capture the following fields in the following order. version vpc-id subnet-id instance-id interface-id account-id type srcaddr dstaddr srcport dstport pkt-srcaddr pkt-dstaddr protocol bytes packets start end action tcp- flags log-status The tcp-flags field in the examples in this section are represented by the second-to-last value in the flow log. TCP flags can help you identify the direction of the traffic, for example, which server initiated the connection. Note For more information about the tcp-flags option and an explanation of each of the TCP flags, see Available fields. In the following records (starting at 7:47:55 PM and ending at 7:48:53 PM), two connections were started by a client to a server running on port 5001. Two SYN flags (2) were received by server from the client from different source ports on the client (43416 and 43418). For each SYN, a SYN- ACK was sent from the server to the client (18) on the corresponding port. 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 52.213.180.42 10.0.0.62 43416 5001 52.213.180.42 10.0.0.62 6 568 8 1566848875 1566848933 ACCEPT 2 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43416 10.0.0.62 52.213.180.42 6 376 7 1566848875 1566848933 ACCEPT 18 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 52.213.180.42 10.0.0.62 43418 5001 52.213.180.42 10.0.0.62 6 100701 70 1566848875 1566848933 ACCEPT 2 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43418 10.0.0.62 52.213.180.42 6 632 12 1566848875 1566848933 ACCEPT 18 OK Flow log record examples 347 Amazon Virtual Private Cloud User Guide In the second aggregation interval, one of the connections that was established during the previous flow is now closed. The client sent a FIN flag (1) to the server for the connection on port 43418. The server sent a FIN to the client on port 43418. 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43418 10.0.0.62 52.213.180.42 6 63388 1219 1566848933
vpc-ug-126
vpc-ug.pdf
126
1566848875 1566848933 ACCEPT 2 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43418 10.0.0.62 52.213.180.42 6 632 12 1566848875 1566848933 ACCEPT 18 OK Flow log record examples 347 Amazon Virtual Private Cloud User Guide In the second aggregation interval, one of the connections that was established during the previous flow is now closed. The client sent a FIN flag (1) to the server for the connection on port 43418. The server sent a FIN to the client on port 43418. 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43418 10.0.0.62 52.213.180.42 6 63388 1219 1566848933 1566849113 ACCEPT 1 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 52.213.180.42 10.0.0.62 43418 5001 52.213.180.42 10.0.0.62 6 23294588 15774 1566848933 1566849113 ACCEPT 1 OK For short connections (for example, a few seconds) that are opened and closed within a single aggregation interval, the flags might be set on the same line in the flow log record for traffic flow in the same direction. In the following example, the connection is established and finished within the same aggregation interval. In the first line, the TCP flag value is 3, which indicates that there was a SYN and a FIN message sent from the client to the server. In the second line, the TCP flag value is 19, which indicates that there was SYN-ACK and a FIN message sent from the server to the client. 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 52.213.180.42 10.0.0.62 43638 5001 52.213.180.42 10.0.0.62 6 1260 17 1566933133 1566933193 ACCEPT 3 OK 3 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-01234567890123456 eni-1235b8ca123456789 123456789010 IPv4 10.0.0.62 52.213.180.42 5001 43638 10.0.0.62 52.213.180.42 6 967 14 1566933133 1566933193 ACCEPT 19 OK Traffic through a NAT gateway In this example, an instance in a private subnet accesses the internet through a NAT gateway that's in a public subnet. Flow log record examples 348 Amazon Virtual Private Cloud User Guide The following custom flow log for the NAT gateway network interface captures the following fields in the following order. instance-id interface-id srcaddr dstaddr pkt-srcaddr pkt-dstaddr The flow log shows the flow of traffic from the instance IP address (10.0.1.5) through the NAT gateway network interface to a host on the internet (203.0.113.5). The NAT gateway network interface is a requester-managed network interface, therefore the flow log record displays a '-' symbol for the instance-id field. The following line shows traffic from the source instance to the NAT gateway network interface. The values for the dstaddr and pkt-dstaddr fields are different. The dstaddr field displays the private IP address of the NAT gateway network interface, and the pkt-dstaddr field displays the final destination IP address of the host on the internet. Flow log record examples 349 Amazon Virtual Private Cloud User Guide - eni-1235b8ca123456789 10.0.1.5 10.0.0.220 10.0.1.5 203.0.113.5 The next two lines show the traffic from the NAT gateway network interface to the target host on the internet, and the response traffic from the host to the NAT gateway network interface. - eni-1235b8ca123456789 10.0.0.220 203.0.113.5 10.0.0.220 203.0.113.5 - eni-1235b8ca123456789 203.0.113.5 10.0.0.220 203.0.113.5 10.0.0.220 The following line shows the response traffic from the NAT gateway network interface to the source instance. The values for the srcaddr and pkt-srcaddr fields are different. The srcaddr field displays the private IP address of the NAT gateway network interface, and the pkt-srcaddr field displays the IP address of the host on the internet. - eni-1235b8ca123456789 10.0.0.220 10.0.1.5 203.0.113.5 10.0.1.5 You create another custom flow log using the same set of fields as above. You create the flow log for the network interface for the instance in the private subnet. In this case, the instance-id field returns the ID of the instance that's associated with the network interface, and there is no difference between the dstaddr and pkt-dstaddr fields and the srcaddr and pkt-srcaddr fields. Unlike the network interface for the NAT gateway, this network interface is not an intermediate network interface for traffic. i-01234567890123456 eni-1111aaaa2222bbbb3 10.0.1.5 203.0.113.5 10.0.1.5 203.0.113.5 #Traffic from the source instance to host on the internet i-01234567890123456 eni-1111aaaa2222bbbb3 203.0.113.5 10.0.1.5 203.0.113.5 10.0.1.5 #Response traffic from host on the internet to the source instance Traffic through a transit gateway In this example, a client in VPC A connects to a web server in VPC B through a transit gateway. The client and server are in different Availability Zones. Traffic arrives at the server in VPC B using one elastic network interface ID (in this example, let's say the ID is eni-11111111111111111) and leaves VPC B using another (for example eni-22222222222222222). Flow log record examples 350 Amazon Virtual Private Cloud User Guide You create a custom flow log for VPC B with the following format. version interface-id account-id vpc-id subnet-id instance-id srcaddr dstaddr srcport dstport protocol tcp-flags type pkt-srcaddr pkt-dstaddr action log-status The following lines from the flow log records demonstrate the
vpc-ug-127
vpc-ug.pdf
127
server in VPC B through a transit gateway. The client and server are in different Availability Zones. Traffic arrives at the server in VPC B using one elastic network interface ID (in this example, let's say the ID is eni-11111111111111111) and leaves VPC B using another (for example eni-22222222222222222). Flow log record examples 350 Amazon Virtual Private Cloud User Guide You create a custom flow log for VPC B with the following format. version interface-id account-id vpc-id subnet-id instance-id srcaddr dstaddr srcport dstport protocol tcp-flags type pkt-srcaddr pkt-dstaddr action log-status The following lines from the flow log records demonstrate the flow of traffic on the network interface for the web server. The first line is the request traffic from the client, and the last line is the response traffic from the web server. 3 eni-33333333333333333 123456789010 vpc-abcdefab012345678 subnet-22222222bbbbbbbbb i-01234567890123456 10.20.33.164 10.40.2.236 39812 80 6 3 IPv4 10.20.33.164 10.40.2.236 ACCEPT OK ... 3 eni-33333333333333333 123456789010 vpc-abcdefab012345678 subnet-22222222bbbbbbbbb i-01234567890123456 10.40.2.236 10.20.33.164 80 39812 6 19 IPv4 10.40.2.236 10.20.33.164 ACCEPT OK The following line is the request traffic on eni-11111111111111111, a requester-managed network interface for the transit gateway in subnet subnet-11111111aaaaaaaaa. The flow log Flow log record examples 351 Amazon Virtual Private Cloud User Guide record therefore displays a '-' symbol for the instance-id field. The srcaddr field displays the private IP address of the transit gateway network interface, and the pkt-srcaddr field displays the source IP address of the client in VPC A. 3 eni-11111111111111111 123456789010 vpc-abcdefab012345678 subnet-11111111aaaaaaaaa - 10.40.1.175 10.40.2.236 39812 80 6 3 IPv4 10.20.33.164 10.40.2.236 ACCEPT OK The following line is the response traffic on eni-22222222222222222, a requester-managed network interface for the transit gateway in subnet subnet-22222222bbbbbbbbb. The dstaddr field displays the private IP address of the transit gateway network interface, and the pkt-dstaddr field displays the IP address of the client in VPC A. 3 eni-22222222222222222 123456789010 vpc-abcdefab012345678 subnet-22222222bbbbbbbbb - 10.40.2.236 10.40.2.31 80 39812 6 19 IPv4 10.40.2.236 10.20.33.164 ACCEPT OK Service name, traffic path, and flow direction The following is an example of the fields for a custom flow log record. version srcaddr dstaddr srcport dstport protocol start end type packets bytes account- id vpc-id subnet-id instance-id interface-id region az-id sublocation-type sublocation- id action tcp-flags pkt-srcaddr pkt-dstaddr pkt-src-aws-service pkt-dst-aws-service traffic-path flow-direction log-status In the following example, the version is 5 because the records include version 5 fields. An EC2 instance calls the Amazon S3 service. Flow logs are captured on the network interface for the instance. The first record has a flow direction of ingress and the second record has a flow direction of egress. For the egress record, traffic-path is 8, indicating that the traffic goes through an internet gateway. The traffic-path field is not supported for ingress traffic. When pkt-srcaddr or pkt-dstaddr is a public IP address, the service name is shown. 5 52.95.128.179 10.0.0.71 80 34210 6 1616729292 1616729349 IPv4 14 15044 123456789012 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-0c50d5961bcb2d47b eni-1235b8ca123456789 ap-southeast-2 apse2-az3 - - ACCEPT 19 52.95.128.179 10.0.0.71 S3 - - ingress OK 5 10.0.0.71 52.95.128.179 34210 80 6 1616729292 1616729349 IPv4 7 471 123456789012 vpc- abcdefab012345678 subnet-aaaaaaaa012345678 i-0c50d5961bcb2d47b eni-1235b8ca123456789 ap-southeast-2 apse2-az3 - - ACCEPT 3 10.0.0.71 52.95.128.179 - S3 8 egress OK Flow log record examples 352 Amazon Virtual Private Cloud Flow log limitations User Guide To use flow logs, you need to be aware of the following limitations: • After you create a flow log, you won't see flow log data until there is active traffic for the network interface, subnet, or VPC that you selected. • You can't enable flow logs for VPCs that are peered with your VPC unless the peer VPC is in your account. • After you create a flow log, you can't change its configuration or the flow log record format. For example, you can't associate a different IAM role with the flow log, or add or remove fields in the flow log record. Instead, you can delete the flow log and create a new one with the required configuration. • If your network interface has multiple IPv4 addresses and traffic is sent to a secondary private IPv4 address, the flow log displays the primary private IPv4 address in the dstaddr field. To capture the original destination IP address, create a flow log with the pkt-dstaddr field. • If traffic is sent to a network interface and the destination is not any of the network interface's IP addresses, the flow log displays the primary private IPv4 address in the dstaddr field. To capture the original destination IP address, create a flow log with the pkt-dstaddr field. • If traffic is sent from a network interface and the source is not any of the network interface's IP addresses, when the log record is for an egress flow, the flow log displays the primary private IPv4 address in the srcaddr field. To
vpc-ug-128
vpc-ug.pdf
128
a flow log with the pkt-dstaddr field. • If traffic is sent to a network interface and the destination is not any of the network interface's IP addresses, the flow log displays the primary private IPv4 address in the dstaddr field. To capture the original destination IP address, create a flow log with the pkt-dstaddr field. • If traffic is sent from a network interface and the source is not any of the network interface's IP addresses, when the log record is for an egress flow, the flow log displays the primary private IPv4 address in the srcaddr field. To capture the original source IP address, create a flow log with the pkt-srcaddr field. If the log record is for an ingress flow into the network interface, the primary private IP of the network interface will not be shown in the srcaddr field. • When your network interface is attached to a Nitro-based instance, the aggregation interval is always 1 minute or less, regardless of the specified maximum aggregation interval. • For pkt-srcaddr and pkt-dstaddr fields, if the intermediate layer has Client IP address Preservation enabled, this field may show the preserved Client IP instead of the IP address of the intermediate layer. • Some flow log records may be skipped during the aggregation interval (see log-status in Available fields). This may be caused by an internal AWS capacity constraint or internal error. If you are using AWS Cost Explorer to view VPC flow log charges and some flow logs are skipped during the flow log aggregation interval, the number of flow logs reported in AWS Cost Explorer will be higher than the number of flow logs published by Amazon VPC. • If you are using VPC Block Public Access (BPA): • Flow logs for VPC BPA do not include skipped records. Flow log limitations 353 Amazon Virtual Private Cloud User Guide • Flow logs for VPC BPA do not include bytes even if you include the bytes field in your flow log. Flow logs do not capture all IP traffic. The following types of traffic are not logged: • Traffic generated by instances when they contact the Amazon DNS server. If you use your own DNS server, then all traffic to that DNS server is logged. • Traffic generated by a Windows instance for Amazon Windows license activation. • Traffic to and from 169.254.169.254 for instance metadata. • Traffic to and from 169.254.169.123 for the Amazon Time Sync Service. • DHCP traffic. • Traffic mirrored source traffic. You will see traffic mirrored target traffic only. • Traffic to the reserved IP address for the default VPC router. • Traffic between an endpoint network interface and a Network Load Balancer network interface. • Address Resolution Protocol (ARP) traffic. Limitations specific to ECS fields available in version 7: • To create flow log subscriptions with ECS fields, your account must contain at least one ECS cluster. • ECS fields are not computed if the underlying ECS tasks are not owned by the owner of the flow log subscription. For example, if you share a subnet (SubnetA) with another account (AccountB), and then you create a flow log subscription for SubnetA, if AccountB launches ECS tasks in the shared subnet, your subscription will receive traffic logs from ECS tasks launched by AccountB but the ECS fields for these logs will not be computed due to security concerns. • If you create flow log subscriptions with ECS fields at the VPC/Subnet resource level, any traffic generated for non-ECS network interfaces will also be delivered for your subscriptions. The values for ECS fields will be '-' for non-ECS IP traffic. For example, you have a subnet (subnet-000000) and you create a flow log subscription for this subnet with ECS fields (fl-00000000). In subnet-000000, you launch an EC2 instance (i-0000000) that is connected to the internet and is actively generating IP traffic. You also launch a running ECS task (ECS- Task-1) in the same subnet. Since both i-0000000 and ECS-Task-1 are generating IP traffic, your flow log subscription fl-00000000 will deliver traffic logs for both entities. However, only Flow log limitations 354 Amazon Virtual Private Cloud User Guide ECS-Task-1 will have actual ECS metadata for the ECS fields you included in your logFormat. For i-0000000 related traffic, these fields will have a value of '-'. • ecs-container-id and ecs-second-container-id are ordered as the VPC Flow Logs service receives them from the ECS event stream. They are not guaranteed to be in the same order as you see them on ECS console or in the DescribeTask API call. If a container enters a STOPPED status while the task is still running, it may continue to appear in your log. • The ECS metadata and IP traffic logs are from two different sources. We start computing your
vpc-ug-129
vpc-ug.pdf
129
the ECS fields you included in your logFormat. For i-0000000 related traffic, these fields will have a value of '-'. • ecs-container-id and ecs-second-container-id are ordered as the VPC Flow Logs service receives them from the ECS event stream. They are not guaranteed to be in the same order as you see them on ECS console or in the DescribeTask API call. If a container enters a STOPPED status while the task is still running, it may continue to appear in your log. • The ECS metadata and IP traffic logs are from two different sources. We start computing your ECS traffic as soon as we obtain all required information from upstream dependencies. After you start a new task, we start computing your ECS fields 1) when we receive IP traffic for the underlying network interface and 2) when we receive the ECS event that contains the metadata for your ECS task to indicate the task is now running. After you stop a task, we stop computing your ECS fields 1) when we no longer receive IP traffic for the underlying network interface or we receive IP traffic that is delayed for more than one day and 2) when we receive the ECS event that contains the metadata for your ECS task to indicate your task is no longer running. • Only ECS tasks launched in awsvpc network mode are supported. Pricing Data ingestion and archival charges for vended logs apply when you publish flow logs. For more information about pricing when publishing vended logs, open Amazon CloudWatch Pricing, select Logs and find Vended Logs. To track charges from publishing flow logs, you can apply cost allocation tags to your destination resource. Thereafter, your AWS cost allocation report includes usage and costs aggregated by these tags. You can apply tags that represent business categories (such as cost centers, application names, or owners) to organize your costs. For more information, see the following: • Using Cost Allocation Tags in the AWS Billing User Guide • Tag log groups in Amazon CloudWatch Logs in the Amazon CloudWatch Logs User Guide • Using cost allocation S3 bucket tags in the Amazon Simple Storage Service User Guide • Tagging Your Delivery Streams in the Amazon Data Firehose Developer Guide Work with flow logs You can work with flow logs using consoles for Amazon EC2 and Amazon VPC. Pricing 355 User Guide Amazon Virtual Private Cloud Tasks • 1. Control the use of flow logs with IAM • 2. Create a flow log • 3. Tag a flow log • 4. Delete a flow log • Command line overview 1. Control the use of flow logs with IAM By default, users do not have permission to work with flow logs. You can create an IAM role with a policy attached that grants users the permissions to create, describe, and delete flow logs. The following is an example policy that grants users full permissions to create, describe, and delete flow logs. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:DeleteFlowLogs", "ec2:CreateFlowLogs", "ec2:DescribeFlowLogs" ], "Resource": "*" } ] } For more information, see the section called “How Amazon VPC works with IAM”. 2. Create a flow log You can create flow logs for your VPCs, subnets, or network interfaces. When you create a flow log, you must specify a destination for the flow log. For more information, see the following: • the section called “Create a flow log that publishes to CloudWatch Logs” • the section called “Create a flow log that publishes to Amazon S3” Work with flow logs 356 Amazon Virtual Private Cloud User Guide • the section called “Create a flow log that publishes to Amazon Data Firehose” 3. Tag a flow log You can add or remove tags for a flow log at any time. To manage tags for a flow log 1. Do one of the following: • • • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. In the navigation pane, choose Network Interfaces. Select the checkbox for the network interface. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Your VPCs. Select the checkbox for the VPC. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Flow Logs. 3. Choose Actions, Manage tags. 4. To add a new tag, choose Add new tag and enter the key and value. To remove a tag, choose Remove. 5. When you are finished adding or removing tags, choose Save. 4. Delete a flow log You can delete a flow log at any time. After you delete a flow log, it can take several minutes to stop collecting data. Deleting a flow log does not delete the log data from the destination or modify the destination resource. You
vpc-ug-130
vpc-ug.pdf
130
navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Flow Logs. 3. Choose Actions, Manage tags. 4. To add a new tag, choose Add new tag and enter the key and value. To remove a tag, choose Remove. 5. When you are finished adding or removing tags, choose Save. 4. Delete a flow log You can delete a flow log at any time. After you delete a flow log, it can take several minutes to stop collecting data. Deleting a flow log does not delete the log data from the destination or modify the destination resource. You must delete the existing flow log data directly from the destination, and clean up the destination resource, using the console for the destination service. To delete a flow log 1. Do one of the following: • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. In the navigation pane, choose Network Interfaces. Select the checkbox for the network interface. Work with flow logs 357 Amazon Virtual Private Cloud User Guide • • Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Your VPCs. Select the checkbox for the VPC. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Flow Logs. 3. Choose Actions, Delete flow logs. 4. When prompted for confirmation, type delete and then choose Delete. Command line overview You can perform the tasks described on this page using the command line. Create a flow log • create-flow-logs (AWS CLI) • New-EC2FlowLog (AWS Tools for Windows PowerShell) Describe a flow log • describe-flow-logs (AWS CLI) • Get-EC2FlowLog (AWS Tools for Windows PowerShell) Tag a flow log • create-tags and delete-tags (AWS CLI) • New-EC2Tag and Remove-EC2Tag (AWS Tools for Windows PowerShell) Delete a flow log • delete-flow-logs (AWS CLI) • Remove-EC2FlowLog (AWS Tools for Windows PowerShell) Work with flow logs 358 Amazon Virtual Private Cloud User Guide Publish flow logs to CloudWatch Logs Flow logs can publish flow log data directly to Amazon CloudWatch. Amazon CloudWatch is a comprehensive monitoring and observability service. It collects and tracks metrics, logs, and event data from various AWS resources, as well as your own applications and services. CloudWatch provides visibility into resource utilization, application performance, and operational health, enabling you to detect and respond to system-wide performance changes and potential issues. With CloudWatch, you can set alarms, visualize logs and metrics, and automatically react to collect and optimize your cloud resources. It is an essential tool for ensuring the reliability, availability, and performance of your cloud-based infrastructure and applications. When publishing to CloudWatch Logs, flow log data is published to a log group, and each network interface has a unique log stream in the log group. Log streams contain flow log records. You can create multiple flow logs that publish data to the same log group. If the same network interface is present in one or more flow logs in the same log group, it has one combined log stream. If you've specified that one flow log should capture rejected traffic, and the other flow log should capture accepted traffic, then the combined log stream captures all traffic. In CloudWatch Logs, the timestamp field corresponds to the start time that's captured in the flow log record. The ingestionTime field indicates the date and time when the flow log record was received by CloudWatch Logs. This timestamp is later than the end time that's captured in the flow log record. For more information about CloudWatch Logs, see Logs sent to CloudWatch Logs in the Amazon CloudWatch Logs User Guide. Pricing Data ingestion and archival charges for vended logs apply when you publish flow logs to CloudWatch Logs. For more information, open Amazon CloudWatch Pricing, select Logs and find Vended Logs. Contents • IAM role for publishing flow logs to CloudWatch Logs • Create a flow log that publishes to CloudWatch Logs • View flow log records with CloudWatch Logs • Search flow log records Publish to CloudWatch Logs 359 Amazon Virtual Private Cloud User Guide • Process flow log records in CloudWatch Logs IAM role for publishing flow logs to CloudWatch Logs The IAM role that's associated with your flow log must have sufficient permissions to publish flow logs to the specified log group in CloudWatch Logs. The IAM role must belong to your AWS account. The IAM policy that's attached to your IAM role must include at least the following permissions. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogGroups", "logs:DescribeLogStreams" ], "Resource": "*" } ] } Ensure that your role has the following trust policy, which allows the flow logs service to assume the role. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "vpc-flow-logs.amazonaws.com" }, "Action": "sts:AssumeRole" } ] Publish
vpc-ug-131
vpc-ug.pdf
131
log must have sufficient permissions to publish flow logs to the specified log group in CloudWatch Logs. The IAM role must belong to your AWS account. The IAM policy that's attached to your IAM role must include at least the following permissions. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogGroups", "logs:DescribeLogStreams" ], "Resource": "*" } ] } Ensure that your role has the following trust policy, which allows the flow logs service to assume the role. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "vpc-flow-logs.amazonaws.com" }, "Action": "sts:AssumeRole" } ] Publish to CloudWatch Logs 360 Amazon Virtual Private Cloud } User Guide We recommend that you use the aws:SourceAccount and aws:SourceArn condition keys to protect yourself against the confused deputy problem. For example, you could add the following condition block to the previous trust policy. The source account is the owner of the flow log and the source ARN is the flow log ARN. If you don't know the flow log ID, you can replace that portion of the ARN with a wildcard (*) and then update the policy after you create the flow log. "Condition": { "StringEquals": { "aws:SourceAccount": "account_id" }, "ArnLike": { "aws:SourceArn": "arn:aws:ec2:region:account_id:vpc-flow-log/flow-log-id" } } Create an IAM role for flow logs You can update an existing role as described above. Alternatively, you can use the following procedure to create a new role for use with flow logs. You'll specify this role when you create the flow log. To create an IAM role for flow logs 1. Open the IAM console at https://console.aws.amazon.com/iam/. 2. In the navigation pane, choose Policies. 3. Choose Create policy. 4. On the Create policy page, do the following: a. Choose JSON. b. Replace the contents of this window with the permissions policy at the start of this c. d. section. Choose Next. Enter a name for your policy and an optional description and tags, and then choose Create policy. 5. In the navigation pane, choose Roles. 6. Choose Create role. Publish to CloudWatch Logs 361 Amazon Virtual Private Cloud User Guide 7. For Trusted entity type, choose Custom trust policy. For Custom trust policy, replace "Principal": {}, with the following, then and choose Next. "Principal": { "Service": "vpc-flow-logs.amazonaws.com" }, 8. On the Add permissions page, select the checkbox for the policy that you created earlier in this procedure, and then choose Next. 9. Enter a name for your role and optionally provide a description. 10. Choose Create role. Create a flow log that publishes to CloudWatch Logs You can create flow logs for your VPCs, subnets, or network interfaces. If you perform these steps as a user using a particular IAM role, ensure that the role has permissions to use the iam:PassRole action. Prerequisite Verify that the IAM principal that you are using to make the request has permissions to call the iam:PassRole action. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["iam:PassRole"], "Resource": "arn:aws:iam::account-id:role/flow-log-role-name" } ] } To create a flow log using the console 1. Do one of the following: • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. In the navigation pane, choose Network Interfaces. Select the checkbox for the network interface. Publish to CloudWatch Logs 362 Amazon Virtual Private Cloud User Guide • • Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Your VPCs. Select the checkbox for the VPC. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Actions, Create flow log. 3. 4. 5. 6. 7. For Filter, specify the type of traffic to log. Choose All to log accepted and rejected traffic, Reject to log only rejected traffic, or Accept to log only accepted traffic. For Maximum aggregation interval, choose the maximum period of time during which a flow is captured and aggregated into one flow log record. For Destination, choose Send to CloudWatch Logs. For Destination log group, choose the name of an existing log group or enter the name of a new log group. If you enter a name, we create the log group when there is traffic to log. For Service access, choose an existing IAM service role that has permissions to publish logs to CloudWatch Logs or choose to create a new service role. 8. For Log record format, select the format for the flow log record. • To use the default format, choose AWS default format. • To use a custom format, choose Custom format and then select fields from Log format. 9. For Additional metadata, select if you want to include metadata from Amazon ECS in the log format. 10. (Optional) Choose Add new tag to apply tags to the flow log. 11. Choose Create flow log. To create a flow log using the
vpc-ug-132
vpc-ug.pdf
132
role that has permissions to publish logs to CloudWatch Logs or choose to create a new service role. 8. For Log record format, select the format for the flow log record. • To use the default format, choose AWS default format. • To use a custom format, choose Custom format and then select fields from Log format. 9. For Additional metadata, select if you want to include metadata from Amazon ECS in the log format. 10. (Optional) Choose Add new tag to apply tags to the flow log. 11. Choose Create flow log. To create a flow log using the command line Use one of the following commands. • create-flow-logs (AWS CLI) • New-EC2FlowLog (AWS Tools for Windows PowerShell) The following AWS CLI example creates a flow log that captures all accepted traffic for the specified subnet. The flow logs are delivered to the specified log group. The --deliver-logs- permission-arn parameter specifies the IAM role required to publish to CloudWatch Logs. Publish to CloudWatch Logs 363 Amazon Virtual Private Cloud User Guide aws ec2 create-flow-logs --resource-type Subnet --resource-ids subnet-1a2b3c4d -- traffic-type ACCEPT --log-group-name my-flow-logs --deliver-logs-permission-arn arn:aws:iam::123456789101:role/publishFlowLogs View flow log records with CloudWatch Logs You can view your flow log records using the CloudWatch Logs console. After you create your flow log, it might take a few minutes for it to be visible in the console. To view flow log records published to CloudWatch Logs using the console 1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/. 2. 3. 4. In the navigation pane, choose Logs, Log groups. Select the name of the log group that contains your flow logs to open its details page. Select the name of the log stream that contains the flow log records. For more information, see Flow log records. To view flow log records published to CloudWatch Logs using the command line • get-log-events (AWS CLI) • Get-CWLLogEvent (AWS Tools for Windows PowerShell) Search flow log records You can search your flow log records that are published to CloudWatch Logs using the CloudWatch Logs console. You can use metric filters to filter flow log records. Flow log records are space delimited. To search flow log records using the CloudWatch Logs console 1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/. 2. 3. In the navigation pane, choose Logs, Log groups. Select the log group that contains your flow log, and then select the log stream, if you know the network interface that you are searching for. Alternatively, choose Search log group. This might take some time if there are many network interfaces in your log group, or depending on the time range that you select. Publish to CloudWatch Logs 364 Amazon Virtual Private Cloud User Guide 4. Under Filter events, enter the string below. This assumes that the flow log record uses the default format. [version, accountid, interfaceid, srcaddr, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, logstatus] 5. Modify the filter as needed by specifying values for the fields. The following examples filter by specific source IP addresses. [version, accountid, interfaceid, srcaddr = 10.0.0.1, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, logstatus] [version, accountid, interfaceid, srcaddr = 10.0.2.*, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, logstatus] The following examples filter by destination port, the number of bytes, and whether the traffic was rejected. [version, accountid, interfaceid, srcaddr, dstaddr, srcport, dstport = 80 || dstport = 8080, protocol, packets, bytes, start, end, action, logstatus] [version, accountid, interfaceid, srcaddr, dstaddr, srcport, dstport = 80 || dstport = 8080, protocol, packets, bytes >= 400, start, end, action = REJECT, logstatus] Process flow log records in CloudWatch Logs You can process flow log records as you would with any other log events collected by CloudWatch Logs. For more information about monitoring log data and metric filters, see Creating metrics from log events using filter in the Amazon CloudWatch Logs User Guide. Example: Create a CloudWatch metric filter and alarm for a flow log In this example, you have a flow log for eni-1a2b3c4d. You want to create an alarm that alerts you if there have been 10 or more rejected attempts to connect to your instance over TCP port 22 (SSH) within a 1-hour time period. First, you must create a metric filter that matches the pattern of the traffic for which to create the alarm. Then, you can create an alarm for the metric filter. To create a metric filter for rejected SSH traffic and create an alarm for the filter 1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/. Publish to CloudWatch Logs 365 Amazon Virtual Private Cloud User Guide 2. 3. 4. In the navigation pane, choose Logs, Log groups. Select the check box for the log group, and then choose Actions, Create metric filter. For Filter pattern, enter the following string. [version, account, eni, source,
vpc-ug-133
vpc-ug.pdf
133
you must create a metric filter that matches the pattern of the traffic for which to create the alarm. Then, you can create an alarm for the metric filter. To create a metric filter for rejected SSH traffic and create an alarm for the filter 1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/. Publish to CloudWatch Logs 365 Amazon Virtual Private Cloud User Guide 2. 3. 4. In the navigation pane, choose Logs, Log groups. Select the check box for the log group, and then choose Actions, Create metric filter. For Filter pattern, enter the following string. [version, account, eni, source, destination, srcport, destport="22", protocol="6", packets, bytes, windowstart, windowend, action="REJECT", flowlogstatus] 5. For Select log data to test, select the log stream for your network interface. (Optional) To view the lines of log data that match the filter pattern, choose Test pattern. 6. When you're ready, choose Next. 7. Enter a filter name, metric namespace, and metric name. Set the metric value to 1. When you're done, choose Next and then choose Create metric filter. 8. In the navigation pane, choose Alarms, All alarms. 9. Choose Create alarm. 10. Select the metric name that you created and then choose Select metric. 11. Configure the alarm as follows, and then choose Next: • For Statistic, choose Sum. This ensure that you capture the total number of data points for the specified time period. • For Period, choose 1 hour. • For Whenever TimeSinceLastActive is..., choose Greater/Equal and enter 10 for the threshold. • For Additional configuration, Datapoints to alarm, leave the default of 1. 12. Choose Next. 13. For Notification, select an existing SNS topic or choose Create new topic to create a new one. Choose Next. 14. Enter a name and description for the alarm and choose Next. 15. When you are done previewing the alarm, choose Create alarm. Publish flow logs to Amazon S3 Flow logs can publish flow log data to Amazon S3. Amazon S3 (Simple Storage Service) is a highly scalable and durable object storage service. It is designed to store and retrieve any amount of data, Publish to Amazon S3 366 Amazon Virtual Private Cloud User Guide from anywhere on the web. S3 offers industry-leading durability and availability, with built-in features for data versioning, encryption, and access control. When publishing to Amazon S3, flow log data is published to an existing Amazon S3 bucket that you specify. Flow log records for all of the monitored network interfaces are published to a series of log file objects that are stored in the bucket. If the flow log captures data for a VPC, the flow log publishes flow log records for all of the network interfaces in the selected VPC. To create an Amazon S3 bucket for use with flow logs, see Create a bucket in the Amazon S3 User Guide. For more information about how to streamline VPC flow log ingestion, flow log processing, and flow log visualization, see Centralized Logging with OpenSearch in the AWS Solutions Library. For more information about CloudWatch Logs, see Logs sent to Amazon S3 in the Amazon CloudWatch Logs User Guide. Pricing Data ingestion and archival charges for vended logs apply when you publish flow logs to Amazon S3. For more information, open Amazon CloudWatch Pricing, select Logs and find Vended Logs. Contents • Flow log files • Amazon S3 bucket permissions for flow logs • Required key policy for use with SSE-KMS • Amazon S3 log file permissions • Create a flow log that publishes to Amazon S3 • View flow log records with Amazon S3 Flow log files VPC Flow Logs collects data about the IP traffic going to and from your VPC into log records, aggregates those records into log files, and then publishes the log files to the Amazon S3 bucket at 5-minute intervals. Multiple files may be published and each log file may contain some or all of the flow log records for the IP traffic recorded in the previous 5 minutes. Publish to Amazon S3 367 Amazon Virtual Private Cloud User Guide In Amazon S3, the Last modified field for the flow log file indicates the date and time at which the file was uploaded to the Amazon S3 bucket. This is later than the timestamp in the file name, and differs by the amount of time taken to upload the file to the Amazon S3 bucket. Log file format You can specify one of the following formats for the log files. Each file is compressed into a single Gzip file. • Text – Plain text. This is the default format. • Parquet – Apache Parquet is a columnar data format. Queries on data in Parquet format are 10 to 100 times faster compared to queries on data in plain text. Data in Parquet format with
vpc-ug-134
vpc-ug.pdf
134
the Amazon S3 bucket. This is later than the timestamp in the file name, and differs by the amount of time taken to upload the file to the Amazon S3 bucket. Log file format You can specify one of the following formats for the log files. Each file is compressed into a single Gzip file. • Text – Plain text. This is the default format. • Parquet – Apache Parquet is a columnar data format. Queries on data in Parquet format are 10 to 100 times faster compared to queries on data in plain text. Data in Parquet format with Gzip compression takes 20 percent less storage space than plain text with Gzip compression. Note If data in Parquet format with Gzip compression is less than 100 KB per aggregation period, storing data in Parquet format may take up more space than plain text with Gzip compression due to Parquet file memory requirements. Log file options You can optionally specify the following options. • Hive-compatible S3 prefixes – Enable Hive-compatible prefixes instead of importing partitions into your Hive-compatible tools. Before you run queries, use the MSCK REPAIR TABLE command. • Hourly partitions – If you have a large volume of logs and typically target queries to a specific hour, you can get faster results and save on query costs by partitioning logs on an hourly basis. Log file S3 bucket structure Log files are saved to the specified Amazon S3 bucket using a folder structure that is based on the flow log's ID, Region, creation date, and destination options. By default, the files are delivered to the following location. bucket-and-optional-prefix/AWSLogs/account_id/vpcflowlogs/region/year/month/day/ Publish to Amazon S3 368 Amazon Virtual Private Cloud User Guide If you enable Hive-compatible S3 prefixes, the files are delivered to the following location. bucket-and-optional-prefix/AWSLogs/aws-account-id=account_id/aws-service=vpcflowlogs/ aws-region=region/year=year/month=month/day=day/ If you enable hourly partitions, the files are delivered to the following location. bucket-and-optional-prefix/AWSLogs/account_id/vpcflowlogs/region/year/month/day/hour/ If you enable Hive-compatible partitions and partition the flow log per hour, the files are delivered to the following location. bucket-and-optional-prefix/AWSLogs/aws-account-id=account_id/aws-service=vpcflowlogs/ aws-region=region/year=year/month=month/day=day/hour=hour/ Log file names The file name of a log file is based on the flow log ID, Region, and creation date and time. File names use the following format. aws_account_id_vpcflowlogs_region_flow_log_id_YYYYMMDDTHHmmZ_hash.log.gz The following is an example of a log file for a flow log created by AWS account 123456789012, for a resource in the us-east-1 Region, on June 20, 2018 at 16:20 UTC. The file contains the flow log records with an end time between 16:20:00 and 16:24:59. 123456789012_vpcflowlogs_us-east-1_fl-1234abcd_20180620T1620Z_fe123456.log.gz Amazon S3 bucket permissions for flow logs By default, Amazon S3 buckets and the objects they contain are private. Only the bucket owner can access the bucket and the objects stored in it. However, the bucket owner can grant access to other resources and users by writing an access policy. If the user creating the flow log owns the bucket and has PutBucketPolicy and GetBucketPolicy permissions for the bucket, we automatically attach the following policy to the bucket. This policy overwrites any existing policy attached to the bucket. Publish to Amazon S3 369 Amazon Virtual Private Cloud User Guide Otherwise, the bucket owner must add this policy to the bucket, specifying the AWS account ID of the flow log creator, or flow log creation fails. For more information, see Using bucket policies in the Amazon Simple Storage Service User Guide. { "Version": "2012-10-17", "Statement": [ { "Sid": "AWSLogDeliveryWrite", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "my-s3-arn/*", "Condition": { "StringEquals": { "aws:SourceAccount": account_id, "s3:x-amz-acl": "bucket-owner-full-control" }, "ArnLike": { "aws:SourceArn": "arn:aws:logs:region:account_id:*" } } }, { "Sid": "AWSLogDeliveryAclCheck", "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "s3:GetBucketAcl", "Resource": "arn:aws:s3:::bucket_name", "Condition": { "StringEquals": { "aws:SourceAccount": account_id }, "ArnLike": { "aws:SourceArn": "arn:aws:logs:region:account_id:*" } } } ] Publish to Amazon S3 370 Amazon Virtual Private Cloud } User Guide The ARN that you specify for my-s3-arn depends on whether you use Hive-compatible S3 prefixes. • Default prefixes arn:aws:s3:::bucket_name/optional_folder/AWSLogs/account_id/* • Hive-compatible S3 prefixes arn:aws:s3:::bucket_name/optional_folder/AWSLogs/aws-account-id=account_id/* It is a best practice to grant these permissions to the log delivery service principal instead of individual AWS account ARNs. It is also a best practice to use the aws:SourceAccount and aws:SourceArn condition keys to protect against the confused deputy problem. The source account is the owner of the flow log and the source ARN is the wildcard (*) ARN of the logs service. Required key policy for use with SSE-KMS You can protect the data in your Amazon S3 bucket by enabling either Server-Side Encryption with Amazon S3-Managed Keys (SSE-S3) or Server-Side Encryption with KMS Keys (SSE-KMS) on your S3 bucket. For more information, see Protecting data using server-side encryption in the Amazon S3 User Guide. If you choose SSE-S3, no additional configuration is required. Amazon S3 handles the encryption key. If you choose SSE-KMS, you must use a customer managed key ARN. If you use a
vpc-ug-135
vpc-ug.pdf
135
the flow log and the source ARN is the wildcard (*) ARN of the logs service. Required key policy for use with SSE-KMS You can protect the data in your Amazon S3 bucket by enabling either Server-Side Encryption with Amazon S3-Managed Keys (SSE-S3) or Server-Side Encryption with KMS Keys (SSE-KMS) on your S3 bucket. For more information, see Protecting data using server-side encryption in the Amazon S3 User Guide. If you choose SSE-S3, no additional configuration is required. Amazon S3 handles the encryption key. If you choose SSE-KMS, you must use a customer managed key ARN. If you use a key ID, you can run into a LogDestination undeliverable error when creating a flow log. Also, you must update the key policy for your customer managed key so that the log delivery account can write to your S3 bucket. For more information about the required key policy for use with SSE-KMS, see Amazon S3 bucket server-side encryption in the Amazon CloudWatch Logs User Guide. Amazon S3 log file permissions In addition to the required bucket policies, Amazon S3 uses access control lists (ACLs) to manage access to the log files created by a flow log. By default, the bucket owner has FULL_CONTROL permissions on each log file. The log delivery owner, if different from the bucket owner, has no Publish to Amazon S3 371 Amazon Virtual Private Cloud User Guide permissions. The log delivery account has READ and WRITE permissions. For more information, see Access control list (ACL) overview in the Amazon S3 User Guide. Create a flow log that publishes to Amazon S3 After you have created and configured your Amazon S3 bucket, you can create flow logs for your network interfaces, subnets, and VPCs. Prerequisite The IAM principal that creates the flow log must be using an IAM role that has the following permissions, which are required to publish flow logs to the destination Amazon S3 bucket. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogDelivery", "logs:DeleteLogDelivery" ], "Resource": "*" } ] } To create a flow log using the console 1. Do one of the following: • • • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. In the navigation pane, choose Network Interfaces. Select the checkbox for the network interface. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Your VPCs. Select the checkbox for the VPC. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Actions, Create flow log. 3. For Filter, specify the type of IP traffic data to log. Publish to Amazon S3 372 Amazon Virtual Private Cloud User Guide • Accept – Log only accepted traffic. • Reject – Log only rejected traffic. • All – Log accepted and rejected traffic. 4. 5. 6. For Maximum aggregation interval, choose the maximum period of time during which a flow is captured and aggregated into one flow log record. For Destination, choose Send to an Amazon S3 bucket. For S3 bucket ARN, specify the Amazon Resource Name (ARN) of an existing Amazon S3 bucket. You can optionally include a subfolder. For example, to specify a subfolder named my- logs in a bucket named my-bucket, use the following ARN: arn:aws:s3:::my-bucket/my-logs/ The bucket cannot use AWSLogs as a subfolder name, as this is a reserved term. If you own the bucket, we automatically create a resource policy and attach it to the bucket. For more information, see Amazon S3 bucket permissions for flow logs. 7. For Log record format, specify the format for the flow log record. • To use the default flow log record format, choose AWS default format. • To create a custom format, choose Custom format. For Log format, choose the fields to include in the flow log record. 8. For Additional metadata, select if you want to include metadata from Amazon ECS in the log format. 9. For Log file format, specify the format for the log file. • Text – Plain text. This is the default format. • Parquet – Apache Parquet is a columnar data format. Queries on data in Parquet format are 10 to 100 times faster compared to queries on data in plain text. Data in Parquet format with Gzip compression takes 20 percent less storage space than plain text with Gzip compression. 10. (Optional) To use Hive-compatible S3 prefixes, choose Hive-compatible S3 prefix, Enable. 11. (Optional) To partition your flow logs per hour, choose Every 1 hour (60 mins). 12. (Optional) To add a tag to the flow log, choose Add new tag and specify the tag key and value. 13. Choose Create flow log. Publish to Amazon S3 373 Amazon Virtual Private Cloud User Guide To create a flow log that publishes to Amazon S3 using the command line Use
vpc-ug-136
vpc-ug.pdf
136
plain text. Data in Parquet format with Gzip compression takes 20 percent less storage space than plain text with Gzip compression. 10. (Optional) To use Hive-compatible S3 prefixes, choose Hive-compatible S3 prefix, Enable. 11. (Optional) To partition your flow logs per hour, choose Every 1 hour (60 mins). 12. (Optional) To add a tag to the flow log, choose Add new tag and specify the tag key and value. 13. Choose Create flow log. Publish to Amazon S3 373 Amazon Virtual Private Cloud User Guide To create a flow log that publishes to Amazon S3 using the command line Use one of the following commands: • create-flow-logs (AWS CLI) • New-EC2FlowLog (AWS Tools for Windows PowerShell) The following AWS CLI example creates a flow log that captures all traffic for the specified VPC and delivers the flow logs to the specified Amazon S3 bucket. The --log-format parameter specifies a custom format for the flow log records. aws ec2 create-flow-logs --resource-type VPC --resource-ids vpc-00112233344556677 -- traffic-type ALL --log-destination-type s3 --log-destination arn:aws:s3:::flow-log- bucket/custom-flow-logs/ --log-format '${version} ${vpc-id} ${subnet-id} ${instance- id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${tcp-flags} ${type} ${pkt- srcaddr} ${pkt-dstaddr}' View flow log records with Amazon S3 You can view your flow log records using the Amazon S3 console. After you create your flow log, it might take a few minutes for it to be visible in the console. The log files are compressed. If you open the log files using the Amazon S3 console, they are decompressed and the flow log records are displayed. If you download the files, you must decompress them to view the flow log records. To view flow log records published to Amazon S3 1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/. 2. Select the name of the bucket to open its details page. 3. Navigate to the folder with the log files. For example, prefix/AWSLogs/account_id/ vpcflowlogs/region/year/month/day/. 4. Select the checkbox next to the file name, and then choose Download. You can also query the flow log records in the log files using Amazon Athena. Amazon Athena is an interactive query service that makes it easier to analyze data in Amazon S3 using standard SQL. For more information, see Querying Amazon VPC Flow Logs in the Amazon Athena User Guide. Publish to Amazon S3 374 Amazon Virtual Private Cloud User Guide Publish flow logs to Amazon Data Firehose Flow logs can publish flow log data directly to Amazon Data Firehose. Amazon Data Firehose is a fully managed service that collects, transforms, and delivers real-time data streams into various AWS data stores and analytics services. It handles the data ingestion on your behalf. When it comes to VPC flow logs, Firehose can be useful. VPC flow logs capture information about the IP traffic going to and from network interfaces in your VPC. This data can be crucial for security monitoring, performance analysis, and regulatory compliance. However, managing the storage and processing of this continuous flow of log data can be a complex and resource-intensive task. By integrating Firehose with your VPC flow logs, you can deliver this data to your preferred destination, such as Amazon S3, Amazon Redshift, or Amazon OpenSearch Service. Firehose will scale to handle the ingestion, transformation, and delivery of your VPC flow logs, relieving you of the operational burden. This allows you to focus on analyzing the logs and deriving insights, rather than worrying about the underlying infrastructure. Additionally, Firehose offers features like data transformation, compression, and encryption, which can enhance the efficiency and security of your VPC flow log processing pipeline. Using Firehose for VPC flow logs can simplify your data management and enable you to gain insights from your network traffic data. When publishing to Amazon Data Firehose, flow log data is published to a Amazon Data Firehose delivery stream, in plain text format. Pricing Standard ingestion and delivery charges apply. For more information, open Amazon CloudWatch Pricing, select Logs and find Vended Logs. Contents • IAM roles for cross account delivery • Create a flow log that publishes to Amazon Data Firehose IAM roles for cross account delivery When you publish to Amazon Data Firehose, you can choose a delivery stream that's in the same account as the resource to monitor (the source account), or in a different account (the destination Publish to Amazon Data Firehose 375 Amazon Virtual Private Cloud User Guide account). To enable cross account delivery of flow logs to Amazon Data Firehose, you must create an IAM role in the source account and an IAM role in the destination account. Roles • Source account role • Destination account role Source account role In the source account, create a role that grants the following permissions. In this example, the name of the role is mySourceRole, but you can choose a different name for this role. The last statement allows
vpc-ug-137
vpc-ug.pdf
137
source account), or in a different account (the destination Publish to Amazon Data Firehose 375 Amazon Virtual Private Cloud User Guide account). To enable cross account delivery of flow logs to Amazon Data Firehose, you must create an IAM role in the source account and an IAM role in the destination account. Roles • Source account role • Destination account role Source account role In the source account, create a role that grants the following permissions. In this example, the name of the role is mySourceRole, but you can choose a different name for this role. The last statement allows the role in the destination account to assume this role. The condition statements ensure that this role is passed only to the log delivery service, and only when monitoring the specified resource. When you create your policy, specify the VPCs, network interfaces, or subnets that you're monitoring with the condition key iam:AssociatedResourceARN. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::source-account:role/mySourceRole", "Condition": { "StringEquals": { "iam:PassedToService": "delivery.logs.amazonaws.com" }, "StringLike": { "iam:AssociatedResourceARN": [ "arn:aws:ec2:region:source-account:vpc/vpc-00112233344556677" ] } } }, { "Effect": "Allow", "Action": [ "logs:CreateLogDelivery", "logs:DeleteLogDelivery", "logs:ListLogDeliveries", "logs:GetLogDelivery" Publish to Amazon Data Firehose 376 User Guide Amazon Virtual Private Cloud ], "Resource": "*" }, { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "arn:aws:iam::destination-account:role/ AWSLogDeliveryFirehoseCrossAccountRole" } ] } Ensure that this role has the following trust policy, which allows the log delivery service to assume the role. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "delivery.logs.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } From the source account, use the following procedure to create the role. To create the source account role 1. Open the IAM console at https://console.aws.amazon.com/iam/. 2. In the navigation pane, choose Policies. 3. Choose Create policy. 4. On the Create policy page, do the following: a. Choose JSON. b. Replace the contents of this window with the permissions policy at the start of this section. Publish to Amazon Data Firehose 377 Amazon Virtual Private Cloud User Guide c. d. Choose Next. Enter a name for your policy and an optional description and tags, and then choose Create policy. 5. In the navigation pane, choose Roles. 6. Choose Create role. 7. For Trusted entity type, choose Custom trust policy. For Custom trust policy, replace "Principal": {}, with the following, which specifies the log delivery service. Choose Next. "Principal": { "Service": "delivery.logs.amazonaws.com" }, 8. On the Add permissions page, select the checkbox for the policy that you created earlier in this procedure, and then choose Next. 9. Enter a name for your role and optionally provide a description. 10. Choose Create role. Destination account role In the destination account, create a role with a name that starts with AWSLogDeliveryFirehoseCrossAccountRole. This role must grant the following permissions. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iam:CreateServiceLinkedRole", "firehose:TagDeliveryStream" ], "Resource": "*" } ] } Ensure that this role has the following trust policy, which allows the role that you created in the source account to assume this role. Publish to Amazon Data Firehose 378 Amazon Virtual Private Cloud User Guide { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::source-account:role/mySourceRole" }, "Action": "sts:AssumeRole" } ] } From the destination account, use the following procedure to create the role. To create the destination account role 1. Open the IAM console at https://console.aws.amazon.com/iam/. 2. In the navigation pane, choose Policies. 3. Choose Create policy. 4. On the Create policy page, do the following: a. Choose JSON. b. Replace the contents of this window with the permissions policy at the start of this c. d. section. Choose Next. Enter a name for your policy that starts with AWSLogDeliveryFirehoseCrossAccountRole, and then choose Create policy. 5. In the navigation pane, choose Roles. 6. Choose Create role. 7. For Trusted entity type, choose Custom trust policy. For Custom trust policy, replace "Principal": {}, with the following, which specifies the source account role. Choose Next. "Principal": { "AWS": "arn:aws:iam::source-account:role/mySourceRole" }, Publish to Amazon Data Firehose 379 Amazon Virtual Private Cloud User Guide 8. On the Add permissions page, select the checkbox for the policy that you created earlier in this procedure, and then choose Next. 9. Enter a name for your role and optionally provide a description. 10. Choose Create role. Create a flow log that publishes to Amazon Data Firehose You can create flow logs for your VPCs, subnets, or network interfaces. Prerequisites • Create the destination Amazon Data Firehose delivery stream. Use Direct Put as the source. For more information, see Creating an Amazon Data Firehose delivery stream. • If you're publishing flow logs to a different account, create the required IAM roles, as described in the section called “IAM roles for cross account delivery”. To create a flow log that publishes to Amazon Data Firehose 1. Do one of the following:
vpc-ug-138
vpc-ug.pdf
138
provide a description. 10. Choose Create role. Create a flow log that publishes to Amazon Data Firehose You can create flow logs for your VPCs, subnets, or network interfaces. Prerequisites • Create the destination Amazon Data Firehose delivery stream. Use Direct Put as the source. For more information, see Creating an Amazon Data Firehose delivery stream. • If you're publishing flow logs to a different account, create the required IAM roles, as described in the section called “IAM roles for cross account delivery”. To create a flow log that publishes to Amazon Data Firehose 1. Do one of the following: • • • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. In the navigation pane, choose Network Interfaces. Select the checkbox for the network interface. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Your VPCs. Select the checkbox for the VPC. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. In the navigation pane, choose Subnets. Select the checkbox for the subnet. 2. Choose Actions, Create flow log. 3. For Filter, specify the type of traffic to log. • Accept – Log only accepted traffic • Reject – Log only rejected traffic • All – Log accepted and rejected traffic 4. For Maximum aggregation interval, choose the maximum period of time during which a flow is captured and aggregated into one flow log record. 5. For Destination, choose either of the following options: Publish to Amazon Data Firehose 380 Amazon Virtual Private Cloud User Guide • Send to Amazon Data Firehose in the same account – The delivery stream and the resource to monitor are in the same account. 6. 7. • Send to Amazon Data Firehose in a different account – The delivery stream and the resource to monitor are in different accounts. For Amazon Data Firehose stream name, choose the delivery stream that you created. [Cross account delivery only] For Service access, choose an existing IAM service role for cross account delivery that has permissions to publish logs or choose Set up permissions to open the IAM console and create a service role. 8. For Log record format, specify the format for the flow log record. • To use the default flow log record format, choose AWS default format. • To create a custom format, choose Custom format. For Log format, choose the fields to include in the flow log record. 9. For Additional metadata, select if you want to include metadata from Amazon ECS in the log format. 10. (Optional) Choose Add tag to apply tags to the flow log. 11. Choose Create flow log. To create a flow log that publishes to Amazon Data Firehose using the command line Use one of the following commands: • create-flow-logs (AWS CLI) • New-EC2FlowLog (AWS Tools for Windows PowerShell) The following AWS CLI example creates a flow log that captures all traffic for the specified VPC and delivers the flow logs to the specified Amazon Data Firehose delivery stream in the same account. aws ec2 create-flow-logs --traffic-type ALL \ --resource-type VPC \ --resource-ids vpc-00112233344556677 \ --log-destination-type kinesis-data-firehose \ --log-destination arn:aws:firehose:us- east-1:123456789012:deliverystream/flowlogs_stream Publish to Amazon Data Firehose 381 Amazon Virtual Private Cloud User Guide The following AWS CLI example creates a flow log that captures all traffic for the specified VPC and delivers the flow logs to the specified Amazon Data Firehose delivery stream in a different account. aws ec2 create-flow-logs --traffic-type ALL \ --resource-type VPC \ --resource-ids vpc-00112233344556677 \ --log-destination-type kinesis-data-firehose \ --log-destination arn:aws:firehose:us- east-1:123456789012:deliverystream/flowlogs_stream \ --deliver-logs-permission-arn arn:aws:iam::source-account:role/mySourceRole \ --deliver-cross-account-role arn:aws:iam::destination-account:role/ AWSLogDeliveryFirehoseCrossAccountRole As a result of creating the flow log, you can get the flow log data from the destination that you configured for the delivery stream. Query flow logs using Amazon Athena Amazon Athena is an interactive query service that enables you to analyze data in Amazon S3, such as your flow logs, using standard SQL. You can use Athena with VPC Flow Logs to quickly get actionable insights about the traffic flowing through your VPC. For example, you can identify which resources in your virtual private clouds (VPCs) are the top talkers or identify the IP addresses with the most rejected TCP connections. Options • You can streamline and automate the integration of your VPC flow logs with Athena by generating a CloudFormation template that creates the required AWS resources and predefined queries that you can run to obtain insights about the traffic flowing through your VPC. • You can create your own queries using Athena. For more information, see Query flow logs using Amazon Athena in the Amazon Athena User Guide. Pricing You incur standard Amazon Athena charges for running queries. You incur standard AWS Lambda charges for the Lambda function that loads new partitions on a recurring schedule (when you specify a partition load frequency but do not specify a start and end date.)
vpc-ug-139
vpc-ug.pdf
139
logs with Athena by generating a CloudFormation template that creates the required AWS resources and predefined queries that you can run to obtain insights about the traffic flowing through your VPC. • You can create your own queries using Athena. For more information, see Query flow logs using Amazon Athena in the Amazon Athena User Guide. Pricing You incur standard Amazon Athena charges for running queries. You incur standard AWS Lambda charges for the Lambda function that loads new partitions on a recurring schedule (when you specify a partition load frequency but do not specify a start and end date.) To use the predefined queries Query using Athena 382 Amazon Virtual Private Cloud User Guide • Generate the CloudFormation template using the console • Generate the CloudFormation template using the AWS CLI • Run a predefined query Generate the CloudFormation template using the console After the first flow logs are delivered to your S3 bucket, you can integrate with Athena by generating a CloudFormation template and using the template to create a stack. Requirements • The selected Region must support AWS Lambda and Amazon Athena. • The Amazon S3 buckets must be in the selected Region. • The log record format for the flow log must include the fields used by the specific predefined queries that you'd like to run. To generate the template using the console 1. Do one of the following: • • • Open the Amazon VPC console. In the navigation pane, choose Your VPCs and then select your VPC. Open the Amazon VPC console. In the navigation pane, choose Subnets and then select your subnet. Open the Amazon EC2 console. In the navigation pane, choose Network Interfaces and then select your network interface. 2. On the Flow logs tab, select a flow log that publishes to Amazon S3 and then choose Actions, Generate Athena integration. 3. Specify the partition load frequency. If you choose None, you must specify the partition start and end date, using dates that are in the past. If you choose Daily, Weekly, or Monthly, the partition start and end dates are optional. If you do not specify start and end dates, the CloudFormation template creates a Lambda function that loads new partitions on a recurring schedule. 4. Select or create an S3 bucket for the generated template, and an S3 bucket for the query results. 5. Choose Generate Athena integration. Query using Athena 383 Amazon Virtual Private Cloud User Guide 6. (Optional) In the success message, choose the link to navigate to the bucket that you specified for the CloudFormation template, and customize the template. 7. In the success message, choose Create CloudFormation stack to open the Create Stack wizard in the AWS CloudFormation console. The URL for the generated CloudFormation template is specified in the Template section. Complete the wizard to create the resources that are specified in the template. Resources created by the CloudFormation template • An Athena database. The database name is vpcflowlogsathenadatabase<flow-logs-subscription- id>. • An Athena workgroup. The workgroup name is <flow-log-subscription-id><partition-load- frequency><start-date><end-date>workgroup • A partitioned Athena table that corresponds to your flow log records. The table name is <flow- log-subscription-id><partition-load-frequency><start-date><end-date>. • A set of Athena named queries. For more information, see Predefined queries. • A Lambda function that loads new partitions to the table on the specified schedule (daily, weekly, or monthly). • An IAM role that grants permission to run the Lambda functions. Generate the CloudFormation template using the AWS CLI After the first flow logs are delivered to your S3 bucket, you can generate and use a CloudFormation template to integrate with Athena. Use the following get-flow-logs-integration-template command to generate the CloudFormation template. aws ec2 get-flow-logs-integration-template --cli-input-json file://config.json The following is an example of the config.json file. { "FlowLogId": "fl-12345678901234567", "ConfigDeliveryS3DestinationArn": "arn:aws:s3:::my-flow-logs-athena-integration/ templates/", Query using Athena 384 Amazon Virtual Private Cloud User Guide "IntegrateServices": { "AthenaIntegrations": [ { "IntegrationResultS3DestinationArn": "arn:aws:s3:::my-flow-logs- analysis/athena-query-results/", "PartitionLoadFrequency": "monthly", "PartitionStartDate": "2021-01-01T00:00:00", "PartitionEndDate": "2021-12-31T00:00:00" } ] } } Use the following create-stack command to create a stack using the generated CloudFormation template. aws cloudformation create-stack --stack-name my-vpc-flow-logs --template-body file:// my-cloudformation-template.json Run a predefined query The generated CloudFormation template provides a set of predefined queries that you can run to quickly get meaningful insights about the traffic in your AWS network. After you create the stack and verify that all resources were created correctly, you can run one of the predefined queries. To run a predefined query using the console 1. Open the Athena console. 2. 3. In the left nav, choose Query editor. Under Workgroup, select the workgroup created by the CloudFormation template. Select Saved queries, select a query, modify the parameters as needed, and run the query. For a list of available predefined queries, see Predefined queries. 4. Under Query results, view the query results. Predefined queries The following is the
vpc-ug-140
vpc-ug.pdf
140
insights about the traffic in your AWS network. After you create the stack and verify that all resources were created correctly, you can run one of the predefined queries. To run a predefined query using the console 1. Open the Athena console. 2. 3. In the left nav, choose Query editor. Under Workgroup, select the workgroup created by the CloudFormation template. Select Saved queries, select a query, modify the parameters as needed, and run the query. For a list of available predefined queries, see Predefined queries. 4. Under Query results, view the query results. Predefined queries The following is the complete list of Athena named queries. The predefined queries that are provided when you generate the template depend on the fields that are part of the log record format for the flow log. Therefore, the template might not contain all of these predefined queries. Query using Athena 385 Amazon Virtual Private Cloud User Guide • VpcFlowLogsAcceptedTraffic – The TCP connections that were allowed based on your security groups and network ACLs. • VpcFlowLogsAdminPortTraffic – The top 10 IP addresses with the most traffic, as recorded by applications serving requests on administrative ports. • VpcFlowLogsIPv4Traffic – The total bytes of IPv4 traffic recorded. • VpcFlowLogsIPv6Traffic – The total bytes of IPv6 traffic recorded. • VpcFlowLogsRejectedTCPTraffic – The TCP connections that were rejected based on your security groups or network ACLs. • VpcFlowLogsRejectedTraffic – The traffic that was rejected based on your security groups or network ACLs. • VpcFlowLogsSshRdpTraffic – The SSH and RDP traffic. • VpcFlowLogsTopTalkers – The 50 IP addresses with the most traffic recorded. • VpcFlowLogsTopTalkersPacketLevel – The 50 packet-level IP addresses with the most traffic recorded. • VpcFlowLogsTopTalkingInstances – The IDs of the 50 instances with the most traffic recorded. • VpcFlowLogsTopTalkingSubnets – The IDs of the 50 subnets with the most traffic recorded. • VpcFlowLogsTopTCPTraffic – All TCP traffic recorded for a source IP address. • VpcFlowLogsTotalBytesTransferred – The 50 pairs of source and destination IP addresses with the most bytes recorded. • VpcFlowLogsTotalBytesTransferredPacketLevel – The 50 pairs of packet-level source and destination IP addresses with the most bytes recorded. • VpcFlowLogsTrafficFrmSrcAddr – The traffic recorded for a specific source IP address. • VpcFlowLogsTrafficToDstAddr – The traffic recorded for a specific destination IP address. Troubleshoot VPC Flow Logs The following are possible issues you might have when working with flow logs. Issues • Incomplete flow log records • Flow log is active, but no flow log records or log group • 'LogDestinationNotFoundException' or 'Access Denied for LogDestination' error • Exceeding the Amazon S3 bucket policy limit Troubleshoot 386 Amazon Virtual Private Cloud • LogDestination undeliverable • Flow logs data size mismatch with billing data Incomplete flow log records Problem User Guide Your flow log records are incomplete or are no longer being published. Cause There might be a problem delivering the flow logs to the CloudWatch Logs log group or SkipData entries may be present. Solution In either the Amazon EC2 console or the Amazon VPC console, choose the Flow Logs tab for the relevant resource. The flow logs table displays any errors in the Status column. Alternatively, use the describe-flow-logs command, and check the value that's returned in the DeliverLogsErrorMessage field. One of the following errors might be displayed: • Rate limited: This error can occur if CloudWatch Logs throttling has been applied — when the number of flow log records for a network interface is higher than the maximum number of records that can be published within a specific timeframe. This error can also occur if you've reached the quota for the number of CloudWatch Logs log groups that you can create. For more information, see CloudWatch service quotas in the Amazon CloudWatch User Guide. • Access error: This error can occur for one of the following reasons: • The IAM role for your flow log does not have sufficient permissions to publish flow log records to the CloudWatch log group • The IAM role does not have a trust relationship with the flow logs service • The trust relationship does not specify the flow logs service as the principal For more information, see IAM role for publishing flow logs to CloudWatch Logs. • Unknown error: An internal error has occurred in the flow logs service. Flow log is active, but no flow log records or log group Problem Troubleshoot 387 Amazon Virtual Private Cloud User Guide You created a flow log, and the Amazon VPC or Amazon EC2 console displays the flow log as Active. However, you cannot see any log streams in CloudWatch Logs or log files in your Amazon S3 bucket. Possible causes • The flow log is still being created. In some cases, it can take ten minutes or more after you create the flow log for the log group to
vpc-ug-141
vpc-ug.pdf
141
error: An internal error has occurred in the flow logs service. Flow log is active, but no flow log records or log group Problem Troubleshoot 387 Amazon Virtual Private Cloud User Guide You created a flow log, and the Amazon VPC or Amazon EC2 console displays the flow log as Active. However, you cannot see any log streams in CloudWatch Logs or log files in your Amazon S3 bucket. Possible causes • The flow log is still being created. In some cases, it can take ten minutes or more after you create the flow log for the log group to be created, and for data to be displayed. • There has been no traffic recorded for your network interfaces yet. The log group in CloudWatch Logs is only created when traffic is recorded. Solution Wait a few minutes for the log group to be created, or for traffic to be recorded. 'LogDestinationNotFoundException' or 'Access Denied for LogDestination' error Problem You get a Access Denied for LogDestination or a LogDestinationNotFoundException error when you create a flow log. Possible causes • When creating a flow log that publishes data to an Amazon S3 bucket, this error indicates that the specified S3 bucket could not be found or that the bucket policy does not allow logs to be delivered to the bucket. • When creating a flow log that publishes data to Amazon CloudWatch Logs, this error indicates that the IAM role does not allow logs to be delivered to the log group. Solution • When publishing to Amazon S3, ensure that you have specified the ARN for an existing S3 bucket, and that the ARN is in the correct format. If you do not own the S3 bucket, verify that the bucket policy has the required permissions and uses the correct account ID and bucket name in the ARN. • When publishing to CloudWatch Logs, verify that the IAM role has the required permissions. Troubleshoot 388 Amazon Virtual Private Cloud User Guide Exceeding the Amazon S3 bucket policy limit Problem You get the following error when you try to create a flow log: LogDestinationPermissionIssueException. Possible causes Amazon S3 bucket policies are limited to 20 KB in size. Each time that you create a flow log that publishes to an Amazon S3 bucket, we automatically add the specified bucket ARN, which includes the folder path, to the Resource element in the bucket's policy. Creating multiple flow logs that publish to the same bucket could cause you to exceed the bucket policy limit. Solution • Clean up the bucket policy by removing the flow log entries that are no longer needed. • Grant permissions to the entire bucket by replacing the individual flow log entries with the following. arn:aws:s3:::bucket_name/* If you grant permissions to the entire bucket, new flow log subscriptions do not add new permissions to the bucket policy. LogDestination undeliverable Problem You get the following error when you try to create a flow log: LogDestination <bucket name> is undeliverable. Possible causes The target Amazon S3 bucket is encrypted using server-side encryption with AWS KMS (SSE-KMS) and the default encryption of the bucket is a KMS key ID. Solution Troubleshoot 389 Amazon Virtual Private Cloud User Guide The value must be a KMS key ARN. Change the default S3 encryption type from KMS key ID to KMS key ARN. For more information, see Configuring default encryption in the Amazon Simple Storage Service User Guide. Flow logs data size mismatch with billing data Problem The total data size of your flow logs does not match the size reported by billing data. Possible causes There may be SKIPDATA entries in your flow logs. See No data and skipped records for an explanation of SKIPDATA entries. Solution Confirm that SKIPDATA entries are present in your log entries by querying your logs for different entries in the log-status field. Sample queries to check for SKIPDATA: CW Insights: fields @timestamp, @message, @logStream, @log | filter interfaceId = 'eni-123' | stats count(*) by interfaceId, logStatus | sort by interfaceId, logStatus Athena: SELECT log_status, interface_id, count(1) FROM vpc_flow_logs WHERE interface_id IN ('eni-1', 'eni-2', 'eni-3') GROUP BY log_status, interface_id CloudWatch metrics for your VPCs Amazon VPC publishes data about your VPCs to Amazon CloudWatch. You can retrieve statistics about your VPCs as an ordered set of time-series data, known as metrics. Think of a metric as a CloudWatch metrics 390 Amazon Virtual Private Cloud User Guide variable to monitor and the data as the value of that variable over time. For more information, see the Amazon CloudWatch User Guide. Contents • NAU metrics and dimensions • Enable or disable NAU monitoring • NAU CloudWatch alarm example NAU metrics and dimensions Network Address Usage (NAU) is a metric applied to resources in your virtual network to help you plan for and monitor
vpc-ug-142
vpc-ug.pdf
142
to Amazon CloudWatch. You can retrieve statistics about your VPCs as an ordered set of time-series data, known as metrics. Think of a metric as a CloudWatch metrics 390 Amazon Virtual Private Cloud User Guide variable to monitor and the data as the value of that variable over time. For more information, see the Amazon CloudWatch User Guide. Contents • NAU metrics and dimensions • Enable or disable NAU monitoring • NAU CloudWatch alarm example NAU metrics and dimensions Network Address Usage (NAU) is a metric applied to resources in your virtual network to help you plan for and monitor the size of your VPC. There is no cost to monitor NAU. Monitoring NAU is helpful because if you exhaust the NAU or peered NAU quotas for your VPC, you can't launch new EC2 instances or provision new resources, such as Network Load Balancers, VPC endpoints, Lambda functions, transit gateway attachments, and NAT gateways. If you've enabled Network Address Usage monitoring for a VPC, Amazon VPC sends metrics related to NAU to Amazon CloudWatch. The size of a VPC is measured by the number of Network Address Usage (NAU) units that the VPC contains. You can use these metrics to understand the rate of your VPC growth, forecast when your VPC will reach its size limit, or create alarms when size thresholds are crossed. The AWS/EC2namespace includes the following metrics for monitoring NAU. Metric Description NetworkAddressUsage The NAU count per VPC. Reporting criteria • Every 24 hours. Dimensions • Name: Per-VPC Metrics, Value: The VPC ID. NAU metrics and dimensions 391 Amazon Virtual Private Cloud User Guide Metric Description NetworkAddressUsagePeered The NAU count for the VPC and all VPCs that it's peered with. Reporting criteria • Every 24 hours. Dimensions • Name: Per-VPC Metrics, Value: The VPC ID. The AWS/Usagenamespace includes the following metrics for monitoring NAU. Metric Description ResourceCount The NAU count per VPC. Reporting criteria • Every 24 hours. Dimensions • Name: Service, Value: EC2 • Name: Type, Value: Resource • Name: Resource, Value: The VPC ID. • Name: Class, Value: NetworkAd dressUsage ResourceCount The NAU count for the VPC and all VPCs that it's peered with. Reporting criteria • Every 24 hours. NAU metrics and dimensions 392 Amazon Virtual Private Cloud Metric User Guide Description Dimensions • Name: Service, Value: EC2 • Name: Type, Value: Resource • Name: Resource, Value: The VPC ID. • Name: Class, Value: NetworkAd dressUsagePeered ResourceCount A combined view of NAU usage across VPCs. Reporting criteria • Every 24 hours. Dimensions • Name: Service, Value: EC2 • Name: Type, Value: Resource • Name: Resource, Value: VPC • Name: Class, Value: NetworkAd dressUsage NAU metrics and dimensions 393 Amazon Virtual Private Cloud Metric ResourceCount User Guide Description A combined view of NAU usage across peered VPCs. Reporting criteria • Every 24 hours. Dimensions • Name: Service, Value: EC2 • Name: Type, Value: Resource • Name: Resource, Value: VPC • Name: Class, Value: NetworkAd dressUsagePeered Enable or disable NAU monitoring To view NAU metrics in CloudWatch, you must first enable monitoring on each VPC to monitor. To enable or disable monitoring NAU 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Your VPCs. Select the check box for the VPC. Select Actions, Edit VPC settings. 5. Do one of the following: • To enable monitoring, select Network mapping units metrics settings, Enable network address usage metrics. • To disable monitoring, clear Network mapping units metrics settings, Enable network address usage metrics. Enable or disable NAU monitoring 394 Amazon Virtual Private Cloud User Guide To enable or disable monitoring using the command line • modify-vpc-attribute (AWS CLI) • Edit-EC2VpcAttribute (AWS Tools for Windows PowerShell) NAU CloudWatch alarm example You can use the following AWS CLI command and example .json to create an Amazon CloudWatch alarm and SNS notification that tracks NAU utilization of the VPC with 50,000 NAUs as the threshold. This sample requires you to first create an Amazon SNS topic. For more information, see Getting started with Amazon SNS in the Amazon Simple Notification Service Developer Guide. aws cloudwatch put-metric-alarm --cli-input-json file://nau-alarm.json The following is an example of nau-alarm.json. { "Namespace": "AWS/EC2", "MetricName": "NetworkAddressUsage", "Dimensions": [{ "Name": "Per-VPC Metrics", "Value": "vpc-0123456798" }], "AlarmActions": ["arn:aws:sns:us-west-1:123456789012:my_sns_topic"], "ComparisonOperator": "GreaterThanThreshold", "Period": 86400, "EvaluationPeriods": 1, "Threshold": 50000, "AlarmDescription": "Tracks NAU utilization of the VPC with 50k NAUs as the threshold", "AlarmName": "VPC NAU Utilization", "Statistic": "Maximum" } NAU CloudWatch alarm example 395 Amazon Virtual Private Cloud User Guide Managing security responsibilities for Amazon Virtual Private Cloud Cloud security at AWS is the highest priority. As an AWS customer, you benefit from a data center and network architecture that is built to meet the requirements of the most security-sensitive organizations. Security is a shared responsibility between AWS and you. The shared responsibility model
vpc-ug-143
vpc-ug.pdf
143
"Per-VPC Metrics", "Value": "vpc-0123456798" }], "AlarmActions": ["arn:aws:sns:us-west-1:123456789012:my_sns_topic"], "ComparisonOperator": "GreaterThanThreshold", "Period": 86400, "EvaluationPeriods": 1, "Threshold": 50000, "AlarmDescription": "Tracks NAU utilization of the VPC with 50k NAUs as the threshold", "AlarmName": "VPC NAU Utilization", "Statistic": "Maximum" } NAU CloudWatch alarm example 395 Amazon Virtual Private Cloud User Guide Managing security responsibilities for Amazon Virtual Private Cloud Cloud security at AWS is the highest priority. As an AWS customer, you benefit from a data center and network architecture that is built to meet the requirements of the most security-sensitive organizations. Security is a shared responsibility between AWS and you. The shared responsibility model describes this as security of the cloud and security in the cloud: • Security of the cloud – AWS is responsible for protecting the infrastructure that runs AWS services in the AWS Cloud. AWS also provides you with services that you can use securely. Third- party auditors regularly test and verify the effectiveness of our security as part of the AWS Compliance Programs. To learn about the compliance programs that apply to Amazon Virtual Private Cloud, see AWS Services in Scope by Compliance Program. • Security in the cloud – Your responsibility is determined by the AWS service that you use. You are also responsible for other factors including the sensitivity of your data, your company’s requirements, and applicable laws and regulations. This documentation helps you understand how to apply the shared responsibility model when using Amazon VPC. The following topics show you how to configure Amazon VPC to meet your security and compliance objectives. You also learn how to use other AWS services that help you to monitor and secure your Amazon VPC resources. Contents • Ensure data protection in Amazon Virtual Private Cloud • Identity and access management for Amazon VPC • Infrastructure security in Amazon VPC • Control traffic to your AWS resources using security groups • Control subnet traffic with network access control lists • Resilience in Amazon Virtual Private Cloud • Compliance validation for Amazon Virtual Private Cloud • Block public access to VPCs and subnets 396 Amazon Virtual Private Cloud User Guide • Security best practices for your VPC Ensure data protection in Amazon Virtual Private Cloud The AWS shared responsibility model applies to data protection in Amazon Virtual Private Cloud. As described in this model, AWS is responsible for protecting the global infrastructure that runs all of the AWS Cloud. You are responsible for maintaining control over your content that is hosted on this infrastructure. You are also responsible for the security configuration and management tasks for the AWS services that you use. For more information about data privacy, see the Data Privacy FAQ. For information about data protection in Europe, see the AWS Shared Responsibility Model and GDPR blog post on the AWS Security Blog. For data protection purposes, we recommend that you protect AWS account credentials and set up individual users with AWS IAM Identity Center or AWS Identity and Access Management (IAM). That way, each user is given only the permissions necessary to fulfill their job duties. We also recommend that you secure your data in the following ways: • Use multi-factor authentication (MFA) with each account. • Use SSL/TLS to communicate with AWS resources. We require TLS 1.2 and recommend TLS 1.3. • Set up API and user activity logging with AWS CloudTrail. For information about using CloudTrail trails to capture AWS activities, see Working with CloudTrail trails in the AWS CloudTrail User Guide. • Use AWS encryption solutions, along with all default security controls within AWS services. • Use advanced managed security services such as Amazon Macie, which assists in discovering and securing sensitive data that is stored in Amazon S3. • If you require FIPS 140-3 validated cryptographic modules when accessing AWS through a command line interface or an API, use a FIPS endpoint. For more information about the available FIPS endpoints, see Federal Information Processing Standard (FIPS) 140-3. We strongly recommend that you never put confidential or sensitive information, such as your customers' email addresses, into tags or free-form text fields such as a Name field. This includes when you work with Amazon VPC or other AWS services using the console, API, AWS CLI, or AWS SDKs. Any data that you enter into tags or free-form text fields used for names may be used for billing or diagnostic logs. If you provide a URL to an external server, we strongly recommend that you do not include credentials information in the URL to validate your request to that server. Data protection 397 Amazon Virtual Private Cloud User Guide Ensure internetwork traffic privacy in Amazon VPC Amazon Virtual Private Cloud provides features that you can use to increase and monitor the security for your virtual private cloud (VPC): • Security groups: Security groups allow specific inbound and outbound
vpc-ug-144
vpc-ug.pdf
144
SDKs. Any data that you enter into tags or free-form text fields used for names may be used for billing or diagnostic logs. If you provide a URL to an external server, we strongly recommend that you do not include credentials information in the URL to validate your request to that server. Data protection 397 Amazon Virtual Private Cloud User Guide Ensure internetwork traffic privacy in Amazon VPC Amazon Virtual Private Cloud provides features that you can use to increase and monitor the security for your virtual private cloud (VPC): • Security groups: Security groups allow specific inbound and outbound traffic at the resource level (such as an EC2 instance). When you launch an instance, you can associate it with one or more security groups. Each instance in your VPC could belong to a different set of security groups. If you don't specify a security group when you launch an instance, the instance is automatically associated with the default security group for its VPC. For more information, see Security groups. • Network access control lists (ACL): Network ACLs allow or deny specific inbound and outbound traffic at the subnet level. For more information, see Control subnet traffic with network access control lists. • Flow logs: Flow logs capture information about the IP traffic going to and from network interfaces in your VPC. You can create a flow log for a VPC, subnet, or individual network interface. Flow log data is published to CloudWatch Logs or Amazon S3, and it can help you diagnose overly restrictive or overly permissive security group and network ACL rules. For more information, see Logging IP traffic using VPC Flow Logs. • Traffic mirroring: You can copy network traffic from an elastic network interface of an Amazon EC2 instance. You can then send the traffic to out-of-band security and monitoring appliances. For more information, see the Traffic Mirroring Guide. Identity and access management for Amazon VPC AWS Identity and Access Management (IAM) is an AWS service that helps an administrator securely control access to AWS resources. IAM administrators control who can be authenticated (signed in) and authorized (have permissions) to use Amazon VPC resources. IAM is an AWS service that you can use with no additional charge. Contents • Audience • Authenticate with identities • Manage access using policies • How Amazon VPC works with IAM Internetwork traffic privacy 398 Amazon Virtual Private Cloud • Amazon VPC policy examples • Troubleshoot Amazon VPC identity and access • AWS managed policies for Amazon Virtual Private Cloud Audience User Guide How you use AWS Identity and Access Management (IAM) differs, depending on the work you do in Amazon VPC. Service user – If you use the Amazon VPC service to do your job, your administrator provides you with the credentials and permissions that you need. As you use more Amazon VPC features to do your work, you might need additional permissions. Understanding how access is managed can help you request the right permissions from your administrator. If you cannot access a feature in Amazon VPC, see Troubleshoot Amazon VPC identity and access. Service administrator – If you're in charge of Amazon VPC resources at your company, you probably have full access to Amazon VPC. It's your job to determine which Amazon VPC features and resources your employees should access. You submit requests to your IAM administrator to change the permissions of your service users. Review the information on this page to understand the basic concepts of IAM. To learn more about how your company can use IAM with Amazon VPC, see How Amazon VPC works with IAM. IAM administrator – If you're an IAM administrator, you might want to learn details about how you can write policies to manage access to Amazon VPC. To view example policies, see Amazon VPC policy examples. Authenticate with identities Authentication is how you sign in to AWS using your identity credentials. You must be authenticated (signed in to AWS) as the AWS account root user, as an IAM user, or by assuming an IAM role. You can sign in to AWS as a federated identity by using credentials provided through an identity source. AWS IAM Identity Center (IAM Identity Center) users, your company's single sign-on authentication, and your Google or Facebook credentials are examples of federated identities. When you sign in as a federated identity, your administrator previously set up identity federation using IAM roles. When you access AWS by using federation, you are indirectly assuming a role. Audience 399 Amazon Virtual Private Cloud User Guide Depending on the type of user you are, you can sign in to the AWS Management Console or the AWS access portal. For more information about signing in to AWS, see How to sign in to your AWS account in the AWS Sign-In User Guide. If
vpc-ug-145
vpc-ug.pdf
145
company's single sign-on authentication, and your Google or Facebook credentials are examples of federated identities. When you sign in as a federated identity, your administrator previously set up identity federation using IAM roles. When you access AWS by using federation, you are indirectly assuming a role. Audience 399 Amazon Virtual Private Cloud User Guide Depending on the type of user you are, you can sign in to the AWS Management Console or the AWS access portal. For more information about signing in to AWS, see How to sign in to your AWS account in the AWS Sign-In User Guide. If you access AWS programmatically, AWS provides a software development kit (SDK) and a command line interface (CLI) to cryptographically sign your requests by using your credentials. If you don't use AWS tools, you must sign requests yourself. For more information about using the recommended method to sign requests yourself, see AWS Signature Version 4 for API requests in the IAM User Guide. Regardless of the authentication method that you use, you might be required to provide additional security information. For example, AWS recommends that you use multi-factor authentication (MFA) to increase the security of your account. To learn more, see Multi-factor authentication in the AWS IAM Identity Center User Guide and AWS Multi-factor authentication in IAM in the IAM User Guide. AWS account root user When you create an AWS account, you begin with one sign-in identity that has complete access to all AWS services and resources in the account. This identity is called the AWS account root user and is accessed by signing in with the email address and password that you used to create the account. We strongly recommend that you don't use the root user for your everyday tasks. Safeguard your root user credentials and use them to perform the tasks that only the root user can perform. For the complete list of tasks that require you to sign in as the root user, see Tasks that require root user credentials in the IAM User Guide. IAM users and groups An IAM user is an identity within your AWS account that has specific permissions for a single person or application. Where possible, we recommend relying on temporary credentials instead of creating IAM users who have long-term credentials such as passwords and access keys. However, if you have specific use cases that require long-term credentials with IAM users, we recommend that you rotate access keys. For more information, see Rotate access keys regularly for use cases that require long- term credentials in the IAM User Guide. An IAM group is an identity that specifies a collection of IAM users. You can't sign in as a group. You can use groups to specify permissions for multiple users at a time. Groups make permissions easier to manage for large sets of users. For example, you could have a group named IAMAdmins and give that group permissions to administer IAM resources. Authenticate with identities 400 Amazon Virtual Private Cloud User Guide Users are different from roles. A user is uniquely associated with one person or application, but a role is intended to be assumable by anyone who needs it. Users have permanent long-term credentials, but roles provide temporary credentials. To learn more, see Use cases for IAM users in the IAM User Guide. IAM roles An IAM role is an identity within your AWS account that has specific permissions. It is similar to an IAM user, but is not associated with a specific person. To temporarily assume an IAM role in the AWS Management Console, you can switch from a user to an IAM role (console). You can assume a role by calling an AWS CLI or AWS API operation or by using a custom URL. For more information about methods for using roles, see Methods to assume a role in the IAM User Guide. IAM roles with temporary credentials are useful in the following situations: • Federated user access – To assign permissions to a federated identity, you create a role and define permissions for the role. When a federated identity authenticates, the identity is associated with the role and is granted the permissions that are defined by the role. For information about roles for federation, see Create a role for a third-party identity provider (federation) in the IAM User Guide. If you use IAM Identity Center, you configure a permission set. To control what your identities can access after they authenticate, IAM Identity Center correlates the permission set to a role in IAM. For information about permissions sets, see Permission sets in the AWS IAM Identity Center User Guide. • Temporary IAM user permissions – An IAM user or role can assume an IAM role to temporarily take on different permissions for a specific task. • Cross-account access –
vpc-ug-146
vpc-ug.pdf
146
For information about roles for federation, see Create a role for a third-party identity provider (federation) in the IAM User Guide. If you use IAM Identity Center, you configure a permission set. To control what your identities can access after they authenticate, IAM Identity Center correlates the permission set to a role in IAM. For information about permissions sets, see Permission sets in the AWS IAM Identity Center User Guide. • Temporary IAM user permissions – An IAM user or role can assume an IAM role to temporarily take on different permissions for a specific task. • Cross-account access – You can use an IAM role to allow someone (a trusted principal) in a different account to access resources in your account. Roles are the primary way to grant cross- account access. However, with some AWS services, you can attach a policy directly to a resource (instead of using a role as a proxy). To learn the difference between roles and resource-based policies for cross-account access, see Cross account resource access in IAM in the IAM User Guide. • Cross-service access – Some AWS services use features in other AWS services. For example, when you make a call in a service, it's common for that service to run applications in Amazon EC2 or store objects in Amazon S3. A service might do this using the calling principal's permissions, using a service role, or using a service-linked role. • Forward access sessions (FAS) – When you use an IAM user or role to perform actions in AWS, you are considered a principal. When you use some services, you might perform an action that then initiates another action in a different service. FAS uses the permissions of the Authenticate with identities 401 Amazon Virtual Private Cloud User Guide principal calling an AWS service, combined with the requesting AWS service to make requests to downstream services. FAS requests are only made when a service receives a request that requires interactions with other AWS services or resources to complete. In this case, you must have permissions to perform both actions. For policy details when making FAS requests, see Forward access sessions. • Service role – A service role is an IAM role that a service assumes to perform actions on your behalf. An IAM administrator can create, modify, and delete a service role from within IAM. For more information, see Create a role to delegate permissions to an AWS service in the IAM User Guide. • Service-linked role – A service-linked role is a type of service role that is linked to an AWS service. The service can assume the role to perform an action on your behalf. Service-linked roles appear in your AWS account and are owned by the service. An IAM administrator can view, but not edit the permissions for service-linked roles. • Applications running on Amazon EC2 – You can use an IAM role to manage temporary credentials for applications that are running on an EC2 instance and making AWS CLI or AWS API requests. This is preferable to storing access keys within the EC2 instance. To assign an AWS role to an EC2 instance and make it available to all of its applications, you create an instance profile that is attached to the instance. An instance profile contains the role and enables programs that are running on the EC2 instance to get temporary credentials. For more information, see Use an IAM role to grant permissions to applications running on Amazon EC2 instances in the IAM User Guide. Manage access using policies You control access in AWS by creating policies and attaching them to AWS identities or resources. A policy is an object in AWS that, when associated with an identity or resource, defines their permissions. AWS evaluates these policies when a principal (user, root user, or role session) makes a request. Permissions in the policies determine whether the request is allowed or denied. Most policies are stored in AWS as JSON documents. For more information about the structure and contents of JSON policy documents, see Overview of JSON policies in the IAM User Guide. Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions. By default, users and roles have no permissions. To grant users permission to perform actions on the resources that they need, an IAM administrator can create IAM policies. The administrator can then add the IAM policies to roles, and users can assume the roles. Manage access using policies 402 Amazon Virtual Private Cloud User Guide IAM policies define permissions for an action regardless of the method that you use to perform the operation. For example, suppose that you have a policy that allows the iam:GetRole action. A user with
vpc-ug-147
vpc-ug.pdf
147
principal can perform actions on what resources, and under what conditions. By default, users and roles have no permissions. To grant users permission to perform actions on the resources that they need, an IAM administrator can create IAM policies. The administrator can then add the IAM policies to roles, and users can assume the roles. Manage access using policies 402 Amazon Virtual Private Cloud User Guide IAM policies define permissions for an action regardless of the method that you use to perform the operation. For example, suppose that you have a policy that allows the iam:GetRole action. A user with that policy can get role information from the AWS Management Console, the AWS CLI, or the AWS API. Identity-based policies Identity-based policies are JSON permissions policy documents that you can attach to an identity, such as an IAM user, group of users, or role. These policies control what actions users and roles can perform, on which resources, and under what conditions. To learn how to create an identity-based policy, see Define custom IAM permissions with customer managed policies in the IAM User Guide. Identity-based policies can be further categorized as inline policies or managed policies. Inline policies are embedded directly into a single user, group, or role. Managed policies are standalone policies that you can attach to multiple users, groups, and roles in your AWS account. Managed policies include AWS managed policies and customer managed policies. To learn how to choose between a managed policy or an inline policy, see Choose between managed policies and inline policies in the IAM User Guide. Resource-based policies Resource-based policies are JSON policy documents that you attach to a resource. Examples of resource-based policies are IAM role trust policies and Amazon S3 bucket policies. In services that support resource-based policies, service administrators can use them to control access to a specific resource. For the resource where the policy is attached, the policy defines what actions a specified principal can perform on that resource and under what conditions. You must specify a principal in a resource-based policy. Principals can include accounts, users, roles, federated users, or AWS services. Resource-based policies are inline policies that are located in that service. You can't use AWS managed policies from IAM in a resource-based policy. Access control lists (ACLs) Access control lists (ACLs) control which principals (account members, users, or roles) have permissions to access a resource. ACLs are similar to resource-based policies, although they do not use the JSON policy document format. Manage access using policies 403 Amazon Virtual Private Cloud User Guide Amazon S3, AWS WAF, and Amazon VPC are examples of services that support ACLs. To learn more about ACLs, see Access control list (ACL) overview in the Amazon Simple Storage Service Developer Guide. Other policy types AWS supports additional, less-common policy types. These policy types can set the maximum permissions granted to you by the more common policy types. • Permissions boundaries – A permissions boundary is an advanced feature in which you set the maximum permissions that an identity-based policy can grant to an IAM entity (IAM user or role). You can set a permissions boundary for an entity. The resulting permissions are the intersection of an entity's identity-based policies and its permissions boundaries. Resource-based policies that specify the user or role in the Principal field are not limited by the permissions boundary. An explicit deny in any of these policies overrides the allow. For more information about permissions boundaries, see Permissions boundaries for IAM entities in the IAM User Guide. • Service control policies (SCPs) – SCPs are JSON policies that specify the maximum permissions for an organization or organizational unit (OU) in AWS Organizations. AWS Organizations is a service for grouping and centrally managing multiple AWS accounts that your business owns. If you enable all features in an organization, then you can apply service control policies (SCPs) to any or all of your accounts. The SCP limits permissions for entities in member accounts, including each AWS account root user. For more information about Organizations and SCPs, see Service control policies in the AWS Organizations User Guide. • Resource control policies (RCPs) – RCPs are JSON policies that you can use to set the maximum available permissions for resources in your accounts without updating the IAM policies attached to each resource that you own. The RCP limits permissions for resources in member accounts and can impact the effective permissions for identities, including the AWS account root user, regardless of whether they belong to your organization. For more information about Organizations and RCPs, including a list of AWS services that support RCPs, see Resource control policies (RCPs) in the AWS Organizations User Guide. • Session policies – Session policies are advanced policies that you pass as a parameter when you programmatically create a temporary
vpc-ug-148
vpc-ug.pdf
148
the maximum available permissions for resources in your accounts without updating the IAM policies attached to each resource that you own. The RCP limits permissions for resources in member accounts and can impact the effective permissions for identities, including the AWS account root user, regardless of whether they belong to your organization. For more information about Organizations and RCPs, including a list of AWS services that support RCPs, see Resource control policies (RCPs) in the AWS Organizations User Guide. • Session policies – Session policies are advanced policies that you pass as a parameter when you programmatically create a temporary session for a role or federated user. The resulting session's permissions are the intersection of the user or role's identity-based policies and the session policies. Permissions can also come from a resource-based policy. An explicit deny in any of these policies overrides the allow. For more information, see Session policies in the IAM User Guide. Manage access using policies 404 Amazon Virtual Private Cloud Multiple policy types User Guide When multiple types of policies apply to a request, the resulting permissions are more complicated to understand. To learn how AWS determines whether to allow a request when multiple policy types are involved, see Policy evaluation logic in the IAM User Guide. How Amazon VPC works with IAM Before you use IAM to manage access to Amazon VPC, you should understand what IAM features are available to use with Amazon VPC. To get a high-level view of how Amazon VPC and other AWS services work with IAM, see AWS services that work with IAM in the IAM User Guide. Contents • Actions • Resources • Condition keys • Amazon VPC resource-based policies • Authorization based on tags • IAM roles With IAM identity-based policies, you can specify allowed or denied actions. For some actions, you can specify the resources and conditions under which actions are allowed or denied. Amazon VPC supports specific actions, resources, and condition keys. To learn about all of the elements that you use in a JSON policy, see IAM JSON policy elements reference in the IAM User Guide. Actions Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions. The Action element of a JSON policy describes the actions that you can use to allow or deny access in a policy. Policy actions usually have the same name as the associated AWS API operation. There are some exceptions, such as permission-only actions that don't have a matching API operation. There are also some operations that require multiple actions in a policy. These additional actions are called dependent actions. Include actions in a policy to grant permissions to perform the associated operation. How Amazon VPC works with IAM 405 Amazon Virtual Private Cloud User Guide Amazon VPC shares its API namespace with Amazon EC2. Policy actions in Amazon VPC use the following prefix before the action: ec2:. For example, to grant a user permission to create a VPC using the CreateVpc API operation, you grant access to the ec2:CreateVpc action. Policy statements must include either an Action or NotAction element. To specify multiple actions in a single statement, separate them with commas as shown in the following example. "Action": [ "ec2:action1", "ec2:action2" ] You can specify multiple actions using wildcards (*). For example, to specify all actions that begin with the word Describe, include the following action. "Action": "ec2:Describe*" To see a list of Amazon VPC actions, see Actions defined by Amazon EC2 in the Service Authorization Reference. Resources Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions. The Resource JSON policy element specifies the object or objects to which the action applies. Statements must include either a Resource or a NotResource element. As a best practice, specify a resource using its Amazon Resource Name (ARN). You can do this for actions that support a specific resource type, known as resource-level permissions. For actions that don't support resource-level permissions, such as listing operations, use a wildcard (*) to indicate that the statement applies to all resources. "Resource": "*" The VPC resource has the ARN shown in the following example. arn:${Partition}:ec2:${Region}:${Account}:vpc/${VpcId} How Amazon VPC works with IAM 406 Amazon Virtual Private Cloud User Guide For example, to specify the vpc-1234567890abcdef0 VPC in your statement, use the ARN shown in the following example. "Resource": "arn:aws:ec2:us-east-1:123456789012:vpc/vpc-1234567890abcdef0" To specify all VPCs in a specific Region that belong to a specific account, use the wildcard (*). "Resource": "arn:aws:ec2:us-east-1:123456789012:vpc/*" Some Amazon VPC actions, such as those for creating resources, cannot be performed on a specific resource. In those cases, you must use the wildcard (*). "Resource": "*" Many Amazon
vpc-ug-149
vpc-ug.pdf
149
to all resources. "Resource": "*" The VPC resource has the ARN shown in the following example. arn:${Partition}:ec2:${Region}:${Account}:vpc/${VpcId} How Amazon VPC works with IAM 406 Amazon Virtual Private Cloud User Guide For example, to specify the vpc-1234567890abcdef0 VPC in your statement, use the ARN shown in the following example. "Resource": "arn:aws:ec2:us-east-1:123456789012:vpc/vpc-1234567890abcdef0" To specify all VPCs in a specific Region that belong to a specific account, use the wildcard (*). "Resource": "arn:aws:ec2:us-east-1:123456789012:vpc/*" Some Amazon VPC actions, such as those for creating resources, cannot be performed on a specific resource. In those cases, you must use the wildcard (*). "Resource": "*" Many Amazon EC2 API actions involve multiple resources. To specify multiple resources in a single statement, separate the ARNs with commas. "Resource": [ "resource1", "resource2" ] To see a list of Amazon VPC resource types and their ARNs, see Resource types defined by Amazon EC2 in the Service Authorization Reference. Condition keys Administrators can use AWS JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions. The Condition element (or Condition block) lets you specify conditions in which a statement is in effect. The Condition element is optional. You can create conditional expressions that use condition operators, such as equals or less than, to match the condition in the policy with values in the request. If you specify multiple Condition elements in a statement, or multiple keys in a single Condition element, AWS evaluates them using a logical AND operation. If you specify multiple values for a single condition key, AWS evaluates the condition using a logical OR operation. All of the conditions must be met before the statement's permissions are granted. How Amazon VPC works with IAM 407 Amazon Virtual Private Cloud User Guide You can also use placeholder variables when you specify conditions. For example, you can grant an IAM user permission to access a resource only if it is tagged with their IAM user name. For more information, see IAM policy elements: variables and tags in the IAM User Guide. AWS supports global condition keys and service-specific condition keys. To see all AWS global condition keys, see AWS global condition context keys in the IAM User Guide. All Amazon EC2 actions support the aws:RequestedRegion and ec2:Region condition keys. For more information, see Example: Restrict access to a specific Region. Amazon VPC defines its own set of condition keys and also supports using some global condition keys. To see a list of Amazon VPC condition keys, see Condition keys for Amazon EC2 in the Service Authorization Reference. To learn with which actions and resources you can use a condition key, see Actions defined by Amazon EC2. Amazon VPC resource-based policies Resource-based policies are JSON policy documents that specify what actions a specified principal can perform on the Amazon VPC resource and under what conditions. To enable cross-account access, you can specify an entire account or IAM entities in another account as the principal in a resource-based policy. Adding a cross-account principal to a resource- based policy is only half of establishing the trust relationship. When the principal and the resource are in different AWS accounts, you must also grant the principal entity permission to access the resource. Grant permission by attaching an identity-based policy to the entity. However, if a resource-based policy grants access to a principal in the same account, no additional identity-based policy is required. For more information, see Cross account resource access in IAM in the IAM User Guide. Authorization based on tags You can attach tags to Amazon VPC resources or pass tags in a request. To control access based on tags, you provide tag information in the condition element of a policy using condition keys. For more information, see Grant permission to tag resources during creation in the Amazon EC2 User Guide. To view an example identity-based policy for limiting access to a resource based on the tags on that resource, see Launch instances into a specific VPC. How Amazon VPC works with IAM 408 Amazon Virtual Private Cloud IAM roles User Guide An IAM role is an entity within your AWS account that has specific permissions. Use temporary credentials You can use temporary credentials to sign in with federation, assume an IAM role, or to assume a cross-account role. You obtain temporary security credentials by calling AWS STS API operations such as AssumeRole or GetFederationToken. Amazon VPC supports using temporary credentials. Service-linked roles Service-linked roles allow AWS services to access resources in other services to complete an action on your behalf. Service-linked roles appear in your IAM account and are owned by the service. An IAM administrator can view but not edit the permissions for service-linked roles. Transit gateways support service-linked roles. Service roles This feature allows a service to assume
vpc-ug-150
vpc-ug.pdf
150
use temporary credentials to sign in with federation, assume an IAM role, or to assume a cross-account role. You obtain temporary security credentials by calling AWS STS API operations such as AssumeRole or GetFederationToken. Amazon VPC supports using temporary credentials. Service-linked roles Service-linked roles allow AWS services to access resources in other services to complete an action on your behalf. Service-linked roles appear in your IAM account and are owned by the service. An IAM administrator can view but not edit the permissions for service-linked roles. Transit gateways support service-linked roles. Service roles This feature allows a service to assume a service role on your behalf. This role allows the service to access resources in other services to complete an action on your behalf. Service roles appear in your IAM account and are owned by the account. This means that an IAM administrator can change the permissions for this role. However, doing so might break the functionality of the service. Amazon VPC supports service roles for flow logs. When you create a flow log, you must choose a role that allows the flow logs service to access CloudWatch Logs. For more information, see the section called “IAM role for publishing flow logs to CloudWatch Logs”. Amazon VPC policy examples By default, IAM roles don't have permission to create or modify VPC resources. They also can't perform tasks using the AWS Management Console, AWS CLI, or AWS API. An IAM administrator must create IAM policies that grant roles permission to perform specific API operations on the specified resources they need. The administrator must then attach those policies to the IAM roles that require those permissions. To learn how to create an IAM identity-based policy using these example JSON policy documents, see Creating IAM policies in the IAM User Guide. Policy examples 409 User Guide Amazon Virtual Private Cloud Contents • Policy best practices • Use the Amazon VPC console • Create a VPC with a public subnet • Modify and delete VPC resources • Manage security groups • Manage security group rules • Launch instances into a specific subnet • Launch instances into a specific VPC • Block public access to VPCs and subnets • Additional Amazon VPC policy examples Policy best practices Identity-based policies determine whether someone can create, access, or delete Amazon VPC resources in your account. These actions can incur costs for your AWS account. When you create or edit identity-based policies, follow these guidelines and recommendations: • Get started with AWS managed policies and move toward least-privilege permissions – To get started granting permissions to your users and workloads, use the AWS managed policies that grant permissions for many common use cases. They are available in your AWS account. We recommend that you reduce permissions further by defining AWS customer managed policies that are specific to your use cases. For more information, see AWS managed policies or AWS managed policies for job functions in the IAM User Guide. • Apply least-privilege permissions – When you set permissions with IAM policies, grant only the permissions required to perform a task. You do this by defining the actions that can be taken on specific resources under specific conditions, also known as least-privilege permissions. For more information about using IAM to apply permissions, see Policies and permissions in IAM in the IAM User Guide. • Use conditions in IAM policies to further restrict access – You can add a condition to your policies to limit access to actions and resources. For example, you can write a policy condition to specify that all requests must be sent using SSL. You can also use conditions to grant access to service actions if they are used through a specific AWS service, such as AWS CloudFormation. For more information, see IAM JSON policy elements: Condition in the IAM User Guide. Policy examples 410 Amazon Virtual Private Cloud User Guide • Use IAM Access Analyzer to validate your IAM policies to ensure secure and functional permissions – IAM Access Analyzer validates new and existing policies so that the policies adhere to the IAM policy language (JSON) and IAM best practices. IAM Access Analyzer provides more than 100 policy checks and actionable recommendations to help you author secure and functional policies. For more information, see Validate policies with IAM Access Analyzer in the IAM User Guide. • Require multi-factor authentication (MFA) – If you have a scenario that requires IAM users or a root user in your AWS account, turn on MFA for additional security. To require MFA when API operations are called, add MFA conditions to your policies. For more information, see Secure API access with MFA in the IAM User Guide. For more information about best practices in IAM, see Security best practices in IAM in the IAM User Guide. Use the Amazon VPC
vpc-ug-151
vpc-ug.pdf
151
author secure and functional policies. For more information, see Validate policies with IAM Access Analyzer in the IAM User Guide. • Require multi-factor authentication (MFA) – If you have a scenario that requires IAM users or a root user in your AWS account, turn on MFA for additional security. To require MFA when API operations are called, add MFA conditions to your policies. For more information, see Secure API access with MFA in the IAM User Guide. For more information about best practices in IAM, see Security best practices in IAM in the IAM User Guide. Use the Amazon VPC console To access the Amazon VPC console, you must have a minimum set of permissions. These permissions must allow you to list and view details about the Amazon VPC resources in your AWS account. If you create an identity-based policy that is more restrictive than the minimum required permissions, the console won't function as intended for entities (IAM roles) with that policy. The following policy grants a role permission to list resources in the VPC console, but not to create, update, or delete them. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:DescribeAccountAttributes", "ec2:DescribeAddresses", "ec2:DescribeAvailabilityZones", "ec2:DescribeClassicLinkInstances", "ec2:DescribeClientVpnEndpoints", "ec2:DescribeCustomerGateways", "ec2:DescribeDhcpOptions", "ec2:DescribeEgressOnlyInternetGateways", "ec2:DescribeFlowLogs", "ec2:DescribeInternetGateways", Policy examples 411 Amazon Virtual Private Cloud User Guide "ec2:DescribeManagedPrefixLists", "ec2:DescribeMovingAddresses", "ec2:DescribeNatGateways", "ec2:DescribeNetworkAcls", "ec2:DescribeNetworkInterfaceAttribute", "ec2:DescribeNetworkInterfacePermissions", "ec2:DescribeNetworkInterfaces", "ec2:DescribePrefixLists", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroupReferences", "ec2:DescribeSecurityGroups", "ec2:DescribeSecurityGroupRules", "ec2:DescribeStaleSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeTags", "ec2:DescribeTrafficMirrorFilters", "ec2:DescribeTrafficMirrorSessions", "ec2:DescribeTrafficMirrorTargets", "ec2:DescribeTransitGateways", "ec2:DescribeTransitGatewayVpcAttachments", "ec2:DescribeTransitGatewayRouteTables", "ec2:DescribeVpcAttribute", "ec2:DescribeVpcClassicLink", "ec2:DescribeVpcClassicLinkDnsSupport", "ec2:DescribeVpcEndpoints", "ec2:DescribeVpcEndpointConnectionNotifications", "ec2:DescribeVpcEndpointConnections", "ec2:DescribeVpcEndpointServiceConfigurations", "ec2:DescribeVpcEndpointServicePermissions", "ec2:DescribeVpcEndpointServices", "ec2:DescribeVpcPeeringConnections", "ec2:DescribeVpcs", "ec2:DescribeVpnConnections", "ec2:DescribeVpnGateways", "ec2:GetManagedPrefixListAssociations", "ec2:GetManagedPrefixListEntries" ], "Resource": "*" } ] } Policy examples 412 Amazon Virtual Private Cloud User Guide You don't need to allow minimum console permissions for roles that are making calls only to the AWS CLI or the AWS API. Instead, allow access only to actions that match the API operation that the role needs to perform. Create a VPC with a public subnet The following example enables roles to create VPCs, subnets, route tables, and internet gateways. Roles can also attach an internet gateway to a VPC and create routes in route tables. The ec2:ModifyVpcAttribute action enables roles to enable DNS hostnames for the VPC, so that each instance launched into a VPC receives a DNS hostname. { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones", "ec2:CreateRouteTable", "ec2:CreateRoute", "ec2:CreateInternetGateway", "ec2:AttachInternetGateway", "ec2:AssociateRouteTable", "ec2:ModifyVpcAttribute" ], "Resource": "*" } ] } The preceding policy also enables roles to create a VPC in the Amazon VPC console. Modify and delete VPC resources You might want to control the VPC resources that roles can modify or delete. For example, the following policy allows roles to work with and delete route tables that have the tag Purpose=Test. The policy also specifies that roles can only delete internet gateways that have the tag Purpose=Test. Roles cannot work with route tables or internet gateways that do not have this tag. { Policy examples 413 Amazon Virtual Private Cloud User Guide "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "ec2:DeleteInternetGateway", "Resource": "arn:aws:ec2:*:*:internet-gateway/*", "Condition": { "StringEquals": { "ec2:ResourceTag/Purpose": "Test" } } }, { "Effect": "Allow", "Action": [ "ec2:DeleteRouteTable", "ec2:CreateRoute", "ec2:ReplaceRoute", "ec2:DeleteRoute" ], "Resource": "arn:aws:ec2:*:*:route-table/*", "Condition": { "StringEquals": { "ec2:ResourceTag/Purpose": "Test" } } } ] } Manage security groups The following policy allows roles to manage security groups. The first statement allows roles to delete any security group with the tag Stack=test and to manage the inbound and outbound rules for any security group with the tag Stack=test. The second statement requires roles to tag any security groups that they create with the tag Stack=Test. The third statement allows roles to create tags when creating a security group. The fourth statement allows roles to view any security group and security group rule. The fifth statement allows roles to create a security group in a VPC. Policy examples 414 Amazon Virtual Private Cloud User Guide Note This policy cannot be used by the AWS CloudFormation service to create a security group with required tags. If you remove the condition on the ec2:CreateSecurityGroup action that requires the tag, the policy will work. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:RevokeSecurityGroupIngress", "ec2:AuthorizeSecurityGroupEgress", "ec2:AuthorizeSecurityGroupIngress", "ec2:UpdateSecurityGroupRuleDescriptionsEgress", "ec2:RevokeSecurityGroupEgress", "ec2:DeleteSecurityGroup", "ec2:ModifySecurityGroupRules", "ec2:UpdateSecurityGroupRuleDescriptionsIngress" ], "Resource": "arn:aws:ec2:*:*:security-group/*", "Condition": { "StringEquals": { "ec2:ResourceTag/Stack": "test" } } }, { "Effect": "Allow", "Action": "ec2:CreateSecurityGroup", "Resource": "arn:aws:ec2:*:*:security-group/*", "Condition": { "StringEquals": { "aws:RequestTag/Stack": "test" }, "ForAnyValue:StringEquals": { "aws:TagKeys": "Stack" } } }, Policy examples 415 Amazon Virtual Private Cloud { "Effect": "Allow", "Action": "ec2:CreateTags", "Resource": "arn:aws:ec2:*:*:security-group/*", "Condition": { "StringEquals": { "ec2:CreateAction": "CreateSecurityGroup" User Guide } } }, { "Effect": "Allow", "Action": [ "ec2:DescribeSecurityGroupRules", "ec2:DescribeVpcs", "ec2:DescribeSecurityGroups" ], "Resource": "*" }, { "Effect": "Allow", "Action": "ec2:CreateSecurityGroup", "Resource": "arn:aws:ec2:*:*:vpc/*" } ] } To allow roles to change the security group that's associated with an instance, add the ec2:ModifyInstanceAttribute action to your policy. To allow roles to change security groups for a network interface, add
vpc-ug-152
vpc-ug.pdf
152
{ "Effect": "Allow", "Action": "ec2:CreateSecurityGroup", "Resource": "arn:aws:ec2:*:*:security-group/*", "Condition": { "StringEquals": { "aws:RequestTag/Stack": "test" }, "ForAnyValue:StringEquals": { "aws:TagKeys": "Stack" } } }, Policy examples 415 Amazon Virtual Private Cloud { "Effect": "Allow", "Action": "ec2:CreateTags", "Resource": "arn:aws:ec2:*:*:security-group/*", "Condition": { "StringEquals": { "ec2:CreateAction": "CreateSecurityGroup" User Guide } } }, { "Effect": "Allow", "Action": [ "ec2:DescribeSecurityGroupRules", "ec2:DescribeVpcs", "ec2:DescribeSecurityGroups" ], "Resource": "*" }, { "Effect": "Allow", "Action": "ec2:CreateSecurityGroup", "Resource": "arn:aws:ec2:*:*:vpc/*" } ] } To allow roles to change the security group that's associated with an instance, add the ec2:ModifyInstanceAttribute action to your policy. To allow roles to change security groups for a network interface, add the ec2:ModifyNetworkInterfaceAttribute action to your policy. Manage security group rules The following policy grants roles permission to view all security groups and security group rules, add and remove inbound and outbound rules for the security groups for a specific VPC, and modify rule descriptions for the specified VPC. The first statement uses the ec2:Vpc condition key to scope permissions to a specific VPC. The second statement grants roles permission to describe all security groups, security group rules, and tags. This enables roles to view security group rules in order to modify them. Policy examples 416 Amazon Virtual Private Cloud User Guide { "Version": "2012-10-17", "Statement":[{ "Effect":"Allow", "Action": [ "ec2:AuthorizeSecurityGroupIngress", "ec2:RevokeSecurityGroupIngress", "ec2:UpdateSecurityGroupRuleDescriptionsIngress", "ec2:AuthorizeSecurityGroupEgress", "ec2:RevokeSecurityGroupEgress", "ec2:UpdateSecurityGroupRuleDescriptionsEgress", "ec2:ModifySecurityGroupRules" ], "Resource": "arn:aws:ec2:region:account-id:security-group/*", "Condition": { "ArnEquals": { "ec2:Vpc": "arn:aws:ec2:region:account-id:vpc/vpc-id" } } }, { "Effect": "Allow", "Action": [ "ec2:DescribeSecurityGroups", "ec2:DescribeSecurityGroupRules", "ec2:DescribeTags" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ec2:ModifySecurityGroupRules" ], "Resource": "arn:aws:ec2:region:account-id:security-group-rule/*" } ] } Launch instances into a specific subnet The following policy grants roles permission to launch instances into a specific subnet and to use a specific security group in the request. The policy does this by specifying the ARN for the subnet Policy examples 417 Amazon Virtual Private Cloud User Guide and the ARN for the security group. If roles attempt to launch an instance into a different subnet or using a different security group, the request will fail (unless another policy or statement grants roles permission to do so). The policy also grants permission to use the network interface resource. When launching into a subnet, the RunInstances request creates a primary network interface by default, so the role needs permission to create this resource when launching the instance. { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": [ "arn:aws:ec2:region::image/ami-*", "arn:aws:ec2:region:account:instance/*", "arn:aws:ec2:region:account:subnet/subnet-id", "arn:aws:ec2:region:account:network-interface/*", "arn:aws:ec2:region:account:volume/*", "arn:aws:ec2:region:account:key-pair/*", "arn:aws:ec2:region:account:security-group/sg-id" ] } ] } Launch instances into a specific VPC The following policy grants roles permission to launch instances into any subnet within a specific VPC. The policy does this by applying a condition key (ec2:Vpc) to the subnet resource. The policy also grants roles permission to launch instances using only AMIs that have the tag "department=dev". { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": "arn:aws:ec2:region:account-id:subnet/*", "Condition": { "ArnEquals": { Policy examples 418 Amazon Virtual Private Cloud User Guide "ec2:Vpc": "arn:aws:ec2:region:account-id:vpc/vpc-id" } } }, { "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": "arn:aws:ec2:region::image/ami-*", "Condition": { "StringEquals": { "ec2:ResourceTag/department": "dev" } } }, { "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": [ "arn:aws:ec2:region:account:instance/*", "arn:aws:ec2:region:account:volume/*", "arn:aws:ec2:region:account:network-interface/*", "arn:aws:ec2:region:account:key-pair/*", "arn:aws:ec2:region:account:security-group/*" ] } ] } Block public access to VPCs and subnets The following policy examples grant roles permission to work with the VPC Block Public Access (BPA) feature to block public access to resources in VPCs and subnets. Example 1 - Allow read-only access to VPC BPA account-wide settings and VPC BPA exclusions. { "Version": "2012-10-17", "Statement": [ { "Sid": "VPCBPAReadOnlyAccess", "Action": [ "ec2:DescribeVpcBlockPublicAccessOptions", "ec2:DescribeVpcBlockPublicAccessExclusions" Policy examples 419 Amazon Virtual Private Cloud ], "Effect": "Allow", "Resource": "*" } ] } User Guide Example 2 - Allow full read and write access to VPC BPA account-wide settings and VPC BPA exclusions. { "Version": "2012-10-17", "Statement": [ { "Sid": "VPCBPAFullAccess", "Action": [ "ec2:DescribeVpcBlockPublicAccessOptions", "ec2:DescribeVpcBlockPublicAccessExclusions", "ec2:ModifyVpcBlockPublicAccessOptions", "ec2:CreateVpcBlockPublicAccessExclusion", "ec2:ModifyVpcBlockPublicAccessExclusion", "ec2:DeleteVpcBlockPublicAccessExclusion" ], "Effect": "Allow", "Resource": "*" } ] } Example 3 - Allow access to all EC2 APIs except modifying VPC BPA settings and creating exclusions. { "Version": "2012-10-17", "Statement": [ { "Sid": "EC2FullAccess" "Action": [ "ec2:*", ], "Effect": "Allow", "Resource": "*" }, Policy examples 420 User Guide Amazon Virtual Private Cloud { "Sid": "VPCBPAPartialAccess", "Action": [ "ec2:ModifyVpcBlockPublicAccessOptions", "ec2:CreateVpcBlockPublicAccessExclusion" ], "Effect": "Deny", "Resource": "*" } ] } Additional Amazon VPC policy examples You can find additional example IAM policies related to Amazon VPC in the following documentation: • Managed prefix lists • Traffic mirroring • Transit gateways • VPC endpoints and VPC endpoint services (AWS PrivateLink) • VPC peering Troubleshoot Amazon VPC identity and access Use the following information to help you diagnose and fix common issues that you might encounter when working with Amazon VPC and IAM. Issues • I am not authorized to perform an action in Amazon VPC • I am not authorized to perform iam:PassRole • I want to allow people outside of my AWS account to access my Amazon VPC
vpc-ug-153
vpc-ug.pdf
153
additional example IAM policies related to Amazon VPC in the following documentation: • Managed prefix lists • Traffic mirroring • Transit gateways • VPC endpoints and VPC endpoint services (AWS PrivateLink) • VPC peering Troubleshoot Amazon VPC identity and access Use the following information to help you diagnose and fix common issues that you might encounter when working with Amazon VPC and IAM. Issues • I am not authorized to perform an action in Amazon VPC • I am not authorized to perform iam:PassRole • I want to allow people outside of my AWS account to access my Amazon VPC resources I am not authorized to perform an action in Amazon VPC If the AWS Management Console tells you that you're not authorized to perform an action, then you must contact your administrator for assistance. Your administrator is the person that provided you with your sign-in credentials. Troubleshoot 421 Amazon Virtual Private Cloud User Guide The following example error occurs when the mateojackson IAM user tries to use the console to view details about a subnet but belongs to an IAM role that does not have ec2:DescribeSubnets permissions. User: arn:aws:iam::123456789012:user/mateojackson is not authorized to perform: ec2:DescribeSubnets on resource: subnet-id In this case, Mateo asks his administrator to update the policy to allow him to access the subnet. I am not authorized to perform iam:PassRole If you receive an error that you're not authorized to perform the iam:PassRole action, your policies must be updated to allow you to pass a role to Amazon VPC. Some AWS services allow you to pass an existing role to that service instead of creating a new service role or service-linked role. To do this, you must have permissions to pass the role to the service. The following example error occurs when an IAM user named marymajor tries to use the console to perform an action in Amazon VPC. However, the action requires the service to have permissions that are granted by a service role. Mary does not have permissions to pass the role to the service. User: arn:aws:iam::123456789012:user/marymajor is not authorized to perform: iam:PassRole In this case, Mary's policies must be updated to allow her to perform the iam:PassRole action. If you need help, contact your AWS administrator. Your administrator is the person who provided you with your sign-in credentials. I want to allow people outside of my AWS account to access my Amazon VPC resources You can create a role that users in other accounts or people outside of your organization can use to access your resources. You can specify who is trusted to assume the role. For services that support resource-based policies or access control lists (ACLs), you can use those policies to grant people access to your resources. To learn more, consult the following: Troubleshoot 422 Amazon Virtual Private Cloud User Guide • To learn whether Amazon VPC supports these features, see How Amazon VPC works with IAM. • To learn how to provide access to your resources across AWS accounts that you own, see Providing access to an IAM user in another AWS account that you own in the IAM User Guide. • To learn how to provide access to your resources to third-party AWS accounts, see Providing access to AWS accounts owned by third parties in the IAM User Guide. • To learn how to provide access through identity federation, see Providing access to externally authenticated users (identity federation) in the IAM User Guide. • To learn the difference between using roles and resource-based policies for cross-account access, see Cross account resource access in IAM in the IAM User Guide. AWS managed policies for Amazon Virtual Private Cloud An AWS managed policy is a standalone policy that is created and administered by AWS. AWS managed policies are designed to provide permissions for many common use cases so that you can start assigning permissions to users, groups, and roles. Keep in mind that AWS managed policies might not grant least-privilege permissions for your specific use cases because they're available for all AWS customers to use. We recommend that you reduce permissions further by defining customer managed policies that are specific to your use cases. You cannot change the permissions defined in AWS managed policies. If AWS updates the permissions defined in an AWS managed policy, the update affects all principal identities (users, groups, and roles) that the policy is attached to. AWS is most likely to update an AWS managed policy when a new AWS service is launched or new API operations become available for existing services. For more information, see AWS managed policies in the IAM User Guide. AWS managed policy: AmazonVPCFullAccess You can attach the AmazonVPCFullAccess policy to your IAM identities. This policy grants permissions that allow full access to Amazon VPC. To view the permissions for this policy,
vpc-ug-154
vpc-ug.pdf
154
AWS managed policies. If AWS updates the permissions defined in an AWS managed policy, the update affects all principal identities (users, groups, and roles) that the policy is attached to. AWS is most likely to update an AWS managed policy when a new AWS service is launched or new API operations become available for existing services. For more information, see AWS managed policies in the IAM User Guide. AWS managed policy: AmazonVPCFullAccess You can attach the AmazonVPCFullAccess policy to your IAM identities. This policy grants permissions that allow full access to Amazon VPC. To view the permissions for this policy, see AmazonVPCFullAccess in the AWS Managed Policy Reference. AWS managed policies 423 Amazon Virtual Private Cloud User Guide AWS managed policy: AmazonVPCReadOnlyAccess You can attach the AmazonVPCReadOnlyAccess policy to your IAM identities. This policy grants permissions that allow read-only access to Amazon VPC. To view the permissions for this policy, see AmazonVPCReadOnlyAccess in the AWS Managed Policy Reference. AWS managed policy: AmazonVPCCrossAccountNetworkInterfaceOperations You can attach the AmazonVPCCrossAccountNetworkInterfaceOperations policy to your IAM identities. This policy grants permissions that allow the identity to create network interfaces and attach them to cross-account resources. To view the permissions for this policy, see AmazonVPCCrossAccountNetworkInterfaceOperations in the AWS Managed Policy Reference. Amazon VPC updates to AWS managed policies View details about updates to AWS managed policies for Amazon VPC since this service began tracking these changes in March 2021. Change Description Date the section called “AmazonVP CFullAccess” – Update to an Added the AssociateSecurityG roupVpc, DescribeSecurityGr December 9, 2024 existing policy oupVpcAssociations, and DisassociateSecurityGroupVp c actions, which allow you to associate, disassociate, and view security group associati ons with VPCs. Added the DescribeSecurityGr oupVpcAssociations action, which allows you to view security group associations with VPCs. December 9, 2024 the section called “AmazonVP CReadOnlyAccess” – Update to an existing policy AWS managed policies 424 Amazon Virtual Private Cloud User Guide Change Description Date the section called “AmazonVP CFullAccess” – Update to an Added the GetSecuri tyGroupsForVpc action, which February 8, 2024 existing policy allows you to get security groups that are usable in your VPC. the section called “AmazonVP CReadOnlyAccess” – Update Added the GetSecuri tyGroupsForVpc action, which February 8, 2024 to an existing policy allows you to get security groups that are usable in your VPC. the section called “AmazonVP CCrossAccountNetworkInterfa Added the AssignIpv 6Addresses and UnassignI ceOperations” – Update to an pv6Addresses actions, which existing policy allow you to manage the IPv6 September 25, 2023 addresses associated with network interfaces. the section called “AmazonVP CReadOnlyAccess” – Update Added the DescribeSecurityGr oupRules action, which allows August 2, 2021 to an existing policy you to view security group the section called “AmazonVP CFullAccess” – Update to an existing policy the section called “AmazonVP CFullAccess” – Update to an existing policy rules. Added the DescribeSecurityGr oupRules and ModifySec urityGroupRules actions, which allow you to view and modify security group rules. Added actions for carrier gateways, IPv6 pools, local gateways, and local gateway route tables. August 2, 2021 June 23, 2021 AWS managed policies 425 Amazon Virtual Private Cloud User Guide Change Description Date the section called “AmazonVP CReadOnlyAccess” – Update Added actions for carrier gateways, IPv6 pools, local to an existing policy gateways, and local gateway June 23, 2021 route tables. Infrastructure security in Amazon VPC As a managed service, Amazon Virtual Private Cloud is protected by AWS global network security. For information about AWS security services and how AWS protects infrastructure, see AWS Cloud Security. To design your AWS environment using the best practices for infrastructure security, see Infrastructure Protection in Security Pillar AWS Well‐Architected Framework. You use AWS published API calls to access Amazon VPC through the network. Clients must support the following: • Transport Layer Security (TLS). We require TLS 1.2 and recommend TLS 1.3. • Cipher suites with perfect forward secrecy (PFS) such as DHE (Ephemeral Diffie-Hellman) or ECDHE (Elliptic Curve Ephemeral Diffie-Hellman). Most modern systems such as Java 7 and later support these modes. Additionally, requests must be signed by using an access key ID and a secret access key that is associated with an IAM principal. Or you can use the AWS Security Token Service (AWS STS) to generate temporary security credentials to sign requests. Network isolation A virtual private cloud (VPC) is a virtual network in your own logically isolated area in the AWS Cloud. Use separate VPCs to isolate infrastructure by workload or organizational entity. A subnet is a range of IP addresses in a VPC. When you launch an instance, you launch it into a subnet in your VPC. Use subnets to isolate the tiers of your application (for example, web, application, and database) within a single VPC. Use private subnets for your instances if they should not be accessed directly from the internet. Infrastructure security 426 Amazon Virtual
vpc-ug-155
vpc-ug.pdf
155
to sign requests. Network isolation A virtual private cloud (VPC) is a virtual network in your own logically isolated area in the AWS Cloud. Use separate VPCs to isolate infrastructure by workload or organizational entity. A subnet is a range of IP addresses in a VPC. When you launch an instance, you launch it into a subnet in your VPC. Use subnets to isolate the tiers of your application (for example, web, application, and database) within a single VPC. Use private subnets for your instances if they should not be accessed directly from the internet. Infrastructure security 426 Amazon Virtual Private Cloud User Guide You can use AWS PrivateLink to enable resources in your VPC to connect to AWS services using private IP addresses, as if those services were hosted directly in your VPC. Therefore, you do not need to use an internet gateway or NAT device to access AWS services. Control network traffic Consider the following options for controlling network traffic to the resources in your VPC, such as EC2 instances: • Use security groups as the primary mechanism for controlling network access to your VPCs. When necessary, use network ACLs to provide stateless, coarse-grain network control. Security groups are more versatile than network ACLs, due to their ability to perform stateful packet filtering and create rules that reference other security groups. Network ACLs can be effective as a secondary control (for example, to deny a specific subset of traffic) or as high-level subnet guard rails. Also, because network ACLs apply to an entire subnet, they can be used as defense- in-depth in case an instance is ever launched without the correct security group. • Use private subnets for your instances if they should not be accessed directly from the internet. Use a bastion host or NAT gateway for internet access from instances in private subnets. • Configure subnet route tables with the minimum network routes to support your connectivity requirements. • Consider using additional security groups or network interfaces to control and audit Amazon EC2 instance management traffic separately from regular application traffic. Therefore, you can implement special IAM policies for change control, making it easier to audit changes to security group rules or automated rule-verification scripts. Multiple network interfaces also provide additional options for controlling network traffic, including the ability to create host-based routing policies or leverage different VPC subnet routing rules based on an network interfaces assigned to a subnet. • Use AWS Virtual Private Network or AWS Direct Connect to establish private connections from your remote networks to your VPCs. For more information, see Network-to-Amazon VPC connectivity options. • Use VPC Flow Logs to monitor the traffic that reaches your instances. • Use AWS Security Hub to check for unintended network accessibility from your instances. • Use AWS Network Firewall to protect the subnets in your VPC from common network threats. Control network traffic 427 Amazon Virtual Private Cloud User Guide Compare security groups and network ACLs The following table summarizes the basic differences between security groups and network ACLs. Characteristic Security group Instance level Network ACL Subnet level Level of operation Scope Applies to all instances associated with the security group Applies to all instances in the associated subnets Rule type Allow rules only Allow and deny rules Rule evaluation Evaluates all rules before deciding whether to allow traffic Evaluates rules in ascending order until a match for the traffic is found Return traffic Automatically allowed (stateful) Must be explicitly allowed (stateless) The following diagram illustrates the layers of security provided by security groups and network ACLs. For example, traffic from an internet gateway is routed to the appropriate subnet using the routes in the routing table. The rules of the network ACL that is associated with the subnet control which traffic is allowed to the subnet. The rules of the security group that is associated with an instance control which traffic is allowed to the instance. Compare security groups and network ACLs 428 Amazon Virtual Private Cloud User Guide You can secure your instances using only security groups. However, you can add network ACLs as an additional layer of defense. For more information, see Example: Control access to instances in a subnet. Control traffic to your AWS resources using security groups A security group controls the traffic that is allowed to reach and leave the resources that it is associated with. For example, after you associate a security group with an EC2 instance, it controls the inbound and outbound traffic for the instance. When you create a VPC, it comes with a default security group. You can create additional security groups for a VPC, each with their own inbound and outbound rules. You can specify the source, Security groups 429 Amazon Virtual Private Cloud User Guide port range, and protocol for each inbound
vpc-ug-156
vpc-ug.pdf
156
traffic to your AWS resources using security groups A security group controls the traffic that is allowed to reach and leave the resources that it is associated with. For example, after you associate a security group with an EC2 instance, it controls the inbound and outbound traffic for the instance. When you create a VPC, it comes with a default security group. You can create additional security groups for a VPC, each with their own inbound and outbound rules. You can specify the source, Security groups 429 Amazon Virtual Private Cloud User Guide port range, and protocol for each inbound rule. You can specify the destination, port range, and protocol for each outbound rule. The following diagram shows a VPC with a subnet, an internet gateway, and a security group. The subnet contains an EC2 instance. The security group is assigned to the instance. The security group acts as a virtual firewall. The only traffic that reaches the instance is the traffic allowed by the security group rules. For example, if the security group contains a rule that allows ICMP traffic to the instance from your network, then you could ping the instance from your computer. If the security group does not contain a rule that allows SSH traffic, then you could not connect to your instance using SSH. Contents • Security group basics • Security group example • Security group rules • Default security groups for your VPCs • Create a security group for your VPC • Configure security group rules • Delete a security group • Associate security groups with multiple VPCs • Share security groups with AWS Organizations Pricing Security groups 430 Amazon Virtual Private Cloud User Guide There is no additional charge for using security groups. Security group basics • You can assign a security group to resources created in the same VPC as the security group or to resources in other VPCs if using the Security Group VPC Association feature to associate the security group to other VPCs in the same Region. You can also assign multiple security groups to a single resource. • When you create a security group, you must provide it with a name and a description. The following rules apply: • A security group name must be unique within the VPC. • Security group names are not case-sensitive. • Names and descriptions can be up to 255 characters in length. • Names and descriptions are limited to the following characters: a-z, A-Z, 0-9, spaces, and ._-:/ ()#,@[]+=&;{}!$*. • When the name contains trailing spaces, we trim the space at the end of the name. For example, if you enter "Test Security Group " for the name, we store it as "Test Security Group". • A security group name can't start with sg-. • Security groups are stateful. For example, if you send a request from an instance, the response traffic for that request is allowed to reach the instance regardless of the inbound security group rules. Responses to allowed inbound traffic are allowed to leave the instance, regardless of the outbound rules. • Security groups do not filter traffic destined to and from the following: • Amazon Domain Name Services (DNS) • Amazon Dynamic Host Configuration Protocol (DHCP) • Amazon EC2 instance metadata • Amazon ECS task metadata endpoints • License activation for Windows instances • Amazon Time Sync Service • Reserved IP addresses used by the default VPC router • There are quotas on the number of security groups that you can create per VPC, the number of rules that you can add to each security group, and the number of security groups that you can associate with a network interface. For more information, see Amazon VPC quotas. Security group basics 431 Amazon Virtual Private Cloud Best practices User Guide • Authorize only specific IAM principals to create and modify security groups. • Create the minimum number of security groups that you need, to decrease the risk of error. Use each security group to manage access to resources that have similar functions and security requirements. • When you add inbound rules for ports 22 (SSH) or 3389 (RDP) so that you can access your EC2 instances, authorize only specific IP address ranges. If you specify 0.0.0.0/0 (IPv4) and ::/ (IPv6), this enables anyone to access your instances from any IP address using the specified protocol. • Do not open large port ranges. Ensure that access through each port is restricted to the sources or destinations that require it. • Consider creating network ACLs with rules similar to your security groups, to add an additional layer of security to your VPC. For more information about the differences between security groups and network ACLs, see Compare security groups and network ACLs. Security group example The following diagram shows a VPC with two
vpc-ug-157
vpc-ug.pdf
157
address ranges. If you specify 0.0.0.0/0 (IPv4) and ::/ (IPv6), this enables anyone to access your instances from any IP address using the specified protocol. • Do not open large port ranges. Ensure that access through each port is restricted to the sources or destinations that require it. • Consider creating network ACLs with rules similar to your security groups, to add an additional layer of security to your VPC. For more information about the differences between security groups and network ACLs, see Compare security groups and network ACLs. Security group example The following diagram shows a VPC with two security groups and two subnets. The instances in subnet A have the same connectivity requirements, so they are associated with security group 1. The instances in subnet B have the same connectivity requirements, so they are associated with security group 2. The security group rules allow traffic as follows: • The first inbound rule in security group 1 allows SSH traffic to the instances in subnet A from the specified address range (for example, a range in your own network). • The second inbound rule in security group 1 allows the instances in subnet A to communicate with each other using any protocol and port. • The first inbound rule in security group 2 allows the instances in subnet B to communicate with each other using any protocol and port. • The second inbound rule in security group 2 allows the instances in subnet A to communicate with the instances in subnet B using SSH. • Both security groups use the default outbound rule, which allows all traffic. Security group example 432 Amazon Virtual Private Cloud User Guide Security group rules The rules of a security group control the inbound traffic that's allowed to reach the resources that are associated with the security group. The rules also control the outbound traffic that's allowed to leave them. You can add or remove rules for a security group (also referred to as authorizing or revoking inbound or outbound access). A rule applies either to inbound traffic (ingress) or outbound traffic (egress). You can grant access to a specific source or destination. Contents • Security group rule basics • Components of a security group rule • Security group referencing • Security group size • Stale security group rules Security group rules 433 Amazon Virtual Private Cloud Security group rule basics The following are the characteristics of security group rules: • You can specify allow rules, but not deny rules. User Guide • When you first create a security group, it has no inbound rules. Therefore, no inbound traffic is allowed until you add inbound rules to the security group. • When you first create a security group, it has an outbound rule that allows all outbound traffic from the resource. You can remove the rule and add outbound rules that allow specific outbound traffic only. If your security group has no outbound rules, no outbound traffic is allowed. • When you associate multiple security groups with a resource, the rules from each security group are aggregated to form a single set of rules that are used to determine whether to allow access. • When you add, update, or remove rules, your changes are automatically applied to all resources associated with the security group. For instructions, see Configure security group rules. • The effect of some rule changes can depend on how the traffic is tracked. For more information, see Connection tracking in the Amazon EC2 User Guide. • When you create a security group rule, AWS assigns a unique ID to the rule. You can use the ID of a rule when you use the API or CLI to modify or delete the rule. Limitation Security groups cannot block DNS requests to or from the Route 53 Resolver, sometimes referred to as the 'VPC+2 IP address' (see Amazon Route 53 Resolver in the Amazon Route 53 Developer Guide), or as AmazonProvidedDNS. To filter DNS requests through the Route 53 Resolver, use Route 53 Resolver DNS Firewall. Components of a security group rule The following are the components of inbound and outbound security group rules: • Protocol: The protocol to allow. The most common protocols are 6 (TCP), 17 (UDP), and 1 (ICMP). • Port range: For TCP, UDP, or a custom protocol, the range of ports to allow. You can specify a single port number (for example, 22), or range of port numbers (for example, 7000-8000). • ICMP type and code: For ICMP, the ICMP type and code. For example, use type 8 for ICMP Echo Request or type 128 for ICMPv6 Echo Request. For more information, see Rules for ping/ICMP in the Amazon EC2 User Guide. Security group rules 434 Amazon Virtual Private Cloud User Guide • Source or destination: The source
vpc-ug-158
vpc-ug.pdf
158
protocols are 6 (TCP), 17 (UDP), and 1 (ICMP). • Port range: For TCP, UDP, or a custom protocol, the range of ports to allow. You can specify a single port number (for example, 22), or range of port numbers (for example, 7000-8000). • ICMP type and code: For ICMP, the ICMP type and code. For example, use type 8 for ICMP Echo Request or type 128 for ICMPv6 Echo Request. For more information, see Rules for ping/ICMP in the Amazon EC2 User Guide. Security group rules 434 Amazon Virtual Private Cloud User Guide • Source or destination: The source (inbound rules) or destination (outbound rules) for the traffic to allow. Specify one of the following: • A single IPv4 address. You must use the /32 prefix length. For example, 203.0.113.1/32. • A single IPv6 address. You must use the /128 prefix length. For example, 2001:db8:1234:1a00::123/128. • A range of IPv4 addresses, in CIDR block notation. For example, 203.0.113.0/24. • A range of IPv6 addresses, in CIDR block notation. For example, 2001:db8:1234:1a00::/64. • The ID of a prefix list. For example, pl-1234abc1234abc123. For more information, see Managed prefix lists. • The ID of a security group. For example, sg-1234567890abcdef0. For more information, see the section called “Security group referencing”. • (Optional) Description: You can add a description for the rule, which can help you identify it later. A description can be up to 255 characters in length. Allowed characters are a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=;{}!$*. For examples, see Security group rules for different use cases in the Amazon EC2 User Guide. Security group referencing When you specify a security group as the source or destination for a rule, the rule affects all instances that are associated with the security groups. The instances can communicate in the specified direction, using the private IP addresses of the instances, over the specified protocol and port. For example, the following represents an inbound rule for a security group that references security group sg-0abcdef1234567890. This rule allows inbound SSH traffic from the instances associated with sg-0abcdef1234567890. Source Protocol Port range sg-0abcdef1234567890 TCP 22 When referencing a security group in a security group rule, note the following: • You can reference a security group in the inbound rule of another security group if any of the following is true: Security group rules 435 Amazon Virtual Private Cloud User Guide • The security groups are associated with the same VPC. • There is a peering connection between the VPCs that the security groups are associated with. • There is a transit gateway between the VPCs that the security groups are associated with. • You can reference a security group in the outbound rule if any of the following is true: • The security groups are associated with the same VPC. • There is a peering connection between the VPCs that the security groups are associated with. • No rules from the referenced security group are added to the security group that references it. • For inbound rules, the EC2 instances associated with a security group can receive inbound traffic from the private IP addresses of the EC2 instances associated with the referenced security group. • For outbound rules, the EC2 instances associated with a security group can send outbound traffic to the private IP addresses of the EC2 instances associated with the referenced security group. Limitation If you configure routes to forward the traffic between two instances in different subnets through a middlebox appliance, you must ensure that the security groups for both instances allow traffic to flow between the instances. The security group for each instance must reference the private IP address of the other instance or the CIDR range of the subnet that contains the other instance as the source. If you reference the security group of the other instance as the source, this does not allow traffic to flow between the instances. Example The following diagram shows a VPC with subnets in two Availability Zones, an internet gateway, and an Application Load Balancer. Each Availability Zone has a public subnet for web servers and a private subnet for database servers. There are separate security groups for the load balancer, the web servers, and the database servers. Create the following security group rules to allow traffic. • Add rules to the load balancer security group to allow HTTP and HTTPS traffic from the internet. The source is 0.0.0.0/0. • Add rules to the security group for the web servers to allow HTTP and HTTPS traffic only from the load balancer. The source is the security group for the load balancer. • Add rules to the security group for the database servers to allow database requests from the web servers. The source is the security group for the web servers. Security group rules 436 Amazon
vpc-ug-159
vpc-ug.pdf
159
the database servers. Create the following security group rules to allow traffic. • Add rules to the load balancer security group to allow HTTP and HTTPS traffic from the internet. The source is 0.0.0.0/0. • Add rules to the security group for the web servers to allow HTTP and HTTPS traffic only from the load balancer. The source is the security group for the load balancer. • Add rules to the security group for the database servers to allow database requests from the web servers. The source is the security group for the web servers. Security group rules 436 Amazon Virtual Private Cloud User Guide Security group size The type of source or destination determines how each rule counts toward the maximum number of rules that you can have per security group. • A rule that references a CIDR block counts as one rule. • A rule that references another security group counts as one rule, no matter the size of the referenced security group. • A rule that references a customer-managed prefix list counts as the maximum size of the prefix list. For example, if the maximum size of your prefix list is 20, a rule that references this prefix list counts as 20 rules. • A rule that references an AWS-managed prefix list counts as the weight of the prefix list. For example, if the weight of the prefix list is 10, a rule that references this prefix list counts as 10 rules. For more information, see the section called “Available AWS-managed prefix lists”. Stale security group rules If your VPC has a VPC peering connection with another VPC, or if it uses a VPC shared by another account, a security group rule in your VPC can reference a security group in that peer VPC or shared VPC. This allows resources that are associated with the referenced security group and those that Security group rules 437 Amazon Virtual Private Cloud User Guide are associated with the referencing security group to communicate with each other. For more information, see Update your security groups to reference peer security groups in the Amazon VPC Peering Guide. If you have a security group rule that references a security group in a peer VPC or shared VPC and the security group in the shared VPC is deleted or the VPC peering connection is deleted, the security group rule is marked as stale. You can delete stale security group rules as you would any other security group rule. Default security groups for your VPCs Your default VPCs and any VPCs that you create come with a default security group. The name of the default security group is "default". We recommend that you create security groups for specific resources or groups of resources instead of using the default security group. However, if you don't associate a security group with some resources at creation time, we associate them with the default security group. For example, if you don't specify a security group when you launch an EC2 instance, we associate the instance with the default security group for its VPC. Default security group basics • You can change the rules for a default security group. • You can't delete a default security group. If you try to delete a default security group, we return the following error code: Client.CannotDelete. Default rules The following table describes the default inbound rules for a default security group. Source Protocol Port range Description sg-1234567890abcdef0 All All Allows inbound traffic from all resources that are assigned to this security group. The source is the ID of this security group. The following table describes the default outbound rules for a default security group. Default security groups 438 Amazon Virtual Private Cloud User Guide Destination Protocol Port range Description 0.0.0.0/0 ::/0 All All All All Allows all outbound IPv4 traffic. Allows all outbound IPv6 traffic. This rule is added only if your VPC has an associated IPv6 CIDR block. Example The following diagram shows a VPC with a default security group, an internet gateway, and a NAT gateway. The default security contains only its default rules, and it is associated with two EC2 instances running in the VPC. In this scenario, each instance can receive inbound traffic from the other instance on all ports and protocols. The default rules do not allow the instances to receive traffic from the internet gateway or the NAT gateway. If your instances must receive additional traffic, we recommend that you create a security group with the required rules and associate the new security group with the instances instead of the default security group. Default security groups 439 Amazon Virtual Private Cloud User Guide Create a security group for your VPC Your virtual private cloud (VPC) comes with a default security group. You can create additional security groups.
vpc-ug-160
vpc-ug.pdf
160
can receive inbound traffic from the other instance on all ports and protocols. The default rules do not allow the instances to receive traffic from the internet gateway or the NAT gateway. If your instances must receive additional traffic, we recommend that you create a security group with the required rules and associate the new security group with the instances instead of the default security group. Default security groups 439 Amazon Virtual Private Cloud User Guide Create a security group for your VPC Your virtual private cloud (VPC) comes with a default security group. You can create additional security groups. Security groups can be used only with resources in the VPC for which it is created. By default, new security groups start with only an outbound rule that allows all traffic to leave the resource. You must add rules to enable any inbound traffic or to restrict the outbound traffic. You can add rules when you create a security group or later on. For more information, see Security group rules. Required permissions Before you begin, ensure that you have the required permissions. For more information, see the following: • Manage security groups • Manage security group rules To create a security group using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Security groups. 3. Choose Create security group. 4. Enter a name and description for the security group. You can't change the name and description of a security group after it is created. 5. 6. 7. For VPC, choose the VPC in which you'll create the resources to which you'll associate the security group. (Optional) To add inbound rules, choose Inbound rules. For each rule, choose Add rule and specify the protocol, port, and source. For more information, see Configure security group rules. (Optional) To add outbound rules, choose Outbound rules. For each rule, choose Add rule and specify the protocol, port, and destination. 8. (Optional) To add a tag, choose Add new tag and enter the tag key and value. 9. Choose Create security group. To create a security group using the AWS CLI Create a security group 440 Amazon Virtual Private Cloud User Guide Use the create-security-group command. Alternately, you can create a new security group by copying an existing one. When you copy a security group, we automatically add the same inbound and outbound rules as the original security group and use the same VPC as the original security group. You can enter a name and description for the new security group. You can optionally choose a different VPC, and you can modify the inbound and outbound rules as needed. However, you can't copy a security group from one Region to another Region. To create a security group based on an existing one 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Security groups. Select a security group. 4. Choose Actions, Copy to new security group. 5. 6. 7. Enter a name and description for the security group. (Optional) Choose a different VPC if needed. (Optional) Add, remove, or edit the security group rules as needed. 8. Choose Create security group. Configure security group rules After you create a security group, you can add, update, and delete its security group rules. When you add, update, or delete a rule, the change is automatically applied to the resources that are associated with the security group. Required permissions Before you begin, ensure that you have the required permissions. For more information, see Manage security group rules. Sources and destinations You can specify the following as sources for inbound rules or destinations for outbound rules. • Custom – A IPv4 CIDR block, and IPv6 CIDR block, another security group, or a prefix list. • Anywhere-IPv4 – The 0.0.0.0/0 IPv4 CIDR block. • Anywhere-IPv6 – The ::/0 IPv6 CIDR block. Configure security group rules 441 Amazon Virtual Private Cloud User Guide • My IP – The public IPv4 address of your local computer. Warning If you choose Anywhere-IPv4, you allow traffic from all IPv4 addresses. If you choose Anywhere-IPv6, you allow traffic from all IPv6 addresses. It is a best practice to authorize only the specific IP address ranges that need access to your resources. To configure security group rules using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Security groups. Select the security group. To edit the inbound rules, choose Edit inbound rules from Actions or the Inbound rules tab. a. To add a rule, choose Add rule and enter the type, protocol, port, and source for the rule. If the type is TCP or UDP, you must enter the port range to allow. For custom ICMP, you must choose the ICMP type name from Protocol,
vpc-ug-161
vpc-ug.pdf
161
address ranges that need access to your resources. To configure security group rules using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Security groups. Select the security group. To edit the inbound rules, choose Edit inbound rules from Actions or the Inbound rules tab. a. To add a rule, choose Add rule and enter the type, protocol, port, and source for the rule. If the type is TCP or UDP, you must enter the port range to allow. For custom ICMP, you must choose the ICMP type name from Protocol, and, if applicable, the code name from Port range. For any other type, the protocol and port range are configured for you. b. To update a rule, change its protocol, description, and source as needed. However, you can't change the source type. For example, if the source is an IPv4 CIDR block, you can't specify an IPv6 CIDR block, a prefix list, or a security group. c. To delete a rule, choose its Delete button. 5. To edit the outbound rules, choose Edit outbound rules from Actions or the Outbound rules tab. a. To add a rule, choose Add rule and enter the type, protocol, port, and destination for the rule. You can also enter an optional description. If the type is TCP or UDP, you must enter the port range to allow. For custom ICMP, you must choose the ICMP type name from Protocol, and, if applicable, the code name from Port range. For any other type, the protocol and port range are configured for you. b. To update a rule, change its protocol, description, and source as needed. However, you can't change the source type. For example, if the source is an IPv4 CIDR block, you can't specify an IPv6 CIDR block, a prefix list, or a security group. Configure security group rules 442 Amazon Virtual Private Cloud User Guide c. To delete a rule, choose its Delete button. 6. Choose Save rules. To configure security group rules using the AWS CLI • Add – Use the authorize-security-group-ingress and authorize-security-group-egress commands. • Remove – Use the revoke-security-group-ingress and revoke-security-group-egress commands. • Modify – Use the modify-security-group-rules, update-security-group-rule-descriptions-ingress, and update-security-group-rule-descriptions-egresscommands. Delete a security group When you are finished with a security group that you created, you can delete it. Requirements • The security group can't be associated with any resources. • The security group can't be referenced by a rule in another security group. • The security group can't be the default security group for a VPC. To delete a security group using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Security groups. Select the security group and choose Actions, Delete security groups. If you selected more than one security group, you are prompted for confirmation. If some of the security groups can't be deleted, we display the status of each security group, which indicates whether it will be deleted. To confirm deletion, enter Delete. 5. Choose Delete. To delete a security group using the AWS CLI Use the delete-security-group command. Delete a security group 443 Amazon Virtual Private Cloud User Guide Associate security groups with multiple VPCs If you have workloads running in multiple VPCs that share network security requirements, you can use the Security Group VPC Associations feature to associate a security group with multiple VPCs in the same Region. This enables you to manage and maintain security groups in one place for multiple VPCs in your account. The diagram above shows AWS account A with two VPCs in it. Each of the VPCs has workloads running in a private subnet. In this case, workloads in VPC A and B subnets share the same network traffic requirements, so Account A can use the Security Group VPC associations feature to associate the security group in VPC A with VPC B. Any updates made to the associated security group are automatically applied to the traffic to workloads in the VPC B subnet. Requirements of the Security Group VPC Associations feature • You must own the VPC or have one of the VPC subnets shared with you to associate a security group with the VPC. • The VPC and security group must be in the same AWS Region. • You cannot associate a default security group with another VPC or associate a security group with a default VPC. • Both the security group owner and the VPC owner can view the security group VPC associations. Associate security groups with multiple VPCs 444 Amazon Virtual Private Cloud User Guide Services that support this feature • Amazon API Gateway (REST APIs only) • AWS Auto Scaling • AWS CloudFormation • Amazon EC2 • Amazon EFS • Amazon EKS • Amazon FSx •
vpc-ug-162
vpc-ug.pdf
162
security group with the VPC. • The VPC and security group must be in the same AWS Region. • You cannot associate a default security group with another VPC or associate a security group with a default VPC. • Both the security group owner and the VPC owner can view the security group VPC associations. Associate security groups with multiple VPCs 444 Amazon Virtual Private Cloud User Guide Services that support this feature • Amazon API Gateway (REST APIs only) • AWS Auto Scaling • AWS CloudFormation • Amazon EC2 • Amazon EFS • Amazon EKS • Amazon FSx • AWS PrivateLink • Amazon Route 53 • Elastic Load Balancing • Application Load Balancer • Network Load Balancer Associate a security group with another VPC This section explains how to use the AWS Management Console and the AWS CLI to associate a security group with VPCs. AWS Management Console To associate a security group with another VPC 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Security groups. 3. Choose a security group to view the details. 4. Choose the VPC associations tab. 5. Choose Associate VPC. 6. Under VPC ID, choose a VPC to associate with the security group. 7. Choose Associate VPC. Associate security groups with multiple VPCs 445 Amazon Virtual Private Cloud Command line User Guide To associate a security group with another VPC 1. Create a VPC association with associate-security-group-vpc. 2. Check the status of a VPC association with describe-security-group-vpc-associations and wait for the status to be associated. The VPC is now associated with the security group. Once you’ve associated the VPC with the security group, you can, for example, launch an instance into the VPC and choose this new security group or reference this security group in an existing security group rule. Disassociate a security group from another VPC This section explains how to use the AWS Management Console and the AWS CLI to disassociate a security group from VPCs. You may want to do this if your goal is to delete the security group. Security groups cannot be deleted if they are associated. You can only diassociate a security group if there are no network interfaces in the associated VPC using that security group. AWS Management Console To disassociate a security group from a VPC 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Security groups. 3. Choose a security group to view the details. 4. Choose the VPC associations tab. 5. Choose Disassociate VPC. 6. Under VPC ID, choose a VPC to disassociate from the security group. 7. Choose Disassociate VPC. 8. View the Status of the disassociation in the VPC associations tab and wait for the status to be disassociated. Associate security groups with multiple VPCs 446 Amazon Virtual Private Cloud Command line To disassociate a security group from a VPC User Guide 1. Disassociate a VPC association with disassociate-security-group-vpc. 2. Check the status of a VPC disassociation with describe-security-group-vpc-associations and wait for the status to be disassociated. The VPC is now disassociated with the security group. Share security groups with AWS Organizations The Shared Security Group feature enables you to share a security group with other AWS Organizations accounts within the same AWS Region and make the security group available to be used by those accounts. The following diagram demonstrates how you can use the Shared Security Group feature to simplify security group management across accounts in your AWS Organizations: Share security groups with AWS Organizations 447 Amazon Virtual Private Cloud User Guide This diagram shows three accounts that are part of the same Organization. Account A shares a VPC subnet with Accounts B and C. Account A shares the security group with Accounts B and C using the Shared Security Group feature. Accounts B and C then use that security group when they launch instances in the shared subnet. This enables Account A to manage the security group; any updates to the security group apply to the resources that Accounts B and C have running in the shared VPC subnet. Requirements of the Shared Security Group feature • This feature is only available for accounts in the same Organization in AWS Organizations. Resource sharing must be enabled in AWS Organizations. • The account that shares the security group must own both the VPC and the security group. Share security groups with AWS Organizations 448 Amazon Virtual Private Cloud User Guide • You cannot share default security groups. • You cannot share security groups that are in a default VPC. • Participant accounts can create security groups in a shared VPC but they cannot share those security groups. • A minimum set of permissions is required for an IAM principal to share a security group with AWS RAM. Use
vpc-ug-163
vpc-ug.pdf
163
Organization in AWS Organizations. Resource sharing must be enabled in AWS Organizations. • The account that shares the security group must own both the VPC and the security group. Share security groups with AWS Organizations 448 Amazon Virtual Private Cloud User Guide • You cannot share default security groups. • You cannot share security groups that are in a default VPC. • Participant accounts can create security groups in a shared VPC but they cannot share those security groups. • A minimum set of permissions is required for an IAM principal to share a security group with AWS RAM. Use the AmazonEC2FullAccess and AWSResourceAccessManagerFullAccess managed IAM policies to ensure your IAM principals have the required permissions to share and use shared security groups. If you use a custom IAM policy, the c2:PutResourcePolicy and ec2:DeleteResourcePolicy actions are required. These are permission-only IAM actions. If an IAM principal doesn’t have these permissions granted, an error will occur when attempting to share the security group using the AWS RAM. Services that support this feature • Amazon API Gateway • Amazon EC2 • Amazon ECS • Amazon EFS • Amazon EKS • Amazon EMR • Amazon FSx • Amazon ElastiCache • AWS Elastic Beanstalk • AWS Glue • Amazon MQ • Amazon SageMaker AI • Elastic Load Balancing • Application Load Balancer • Network Load Balancer How this feature affects existing quotas Share security groups with AWS Organizations 449 Amazon Virtual Private Cloud User Guide Security group quotas apply. For the 'Security groups per network interface' quota, however, if a participant uses both owned and shared groups on an Elastic network interface (ENI), the minimum of owner and participant's quota applies. Example to demonstrate how the quota is affected by this feature: • Owner account quota: 4 security groups per interface • Participant account quota: 5 security groups per interface. • Owner shares groups SG-O1, SG-O2, SG-O3, SG-O4, SG-O5 with participant. Participant already has groups of their own in the VPC: SG-P1, SG-P2, SG-P3, SG-P4, SG-P5. • If participant creates an ENI and uses only their owned groups, they can associate all 5 security groups (SG-P1, SG-P2, SG-P3, SG-P4, SG-P5) because that's their quota. • If the participant creates an ENI and uses any shared groups on it, they can only associate up to 4 groups. In this case, the quota for such an ENI is the minimum of owner and participant's quotas. Possible valid configurations will look like this: • SG-O1, SG-P1, SG-P2, SG-P3 • SG-O1, SG-O2, SG-O3, SG-O4 Share a security group This section explains how to use the AWS Management Console and the AWS CLI to share a security group with other accounts in your Organization. AWS Management Console To share a security group 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Security groups. 3. Choose a security group to view the details. 4. Choose the Sharing tab. 5. Choose Share security group. 6. Choose Create resource share. As a result, the AWS RAM console opens where you’ll create the resource share for the security group. 7. Enter a Name for the resource share. Share security groups with AWS Organizations 450 Amazon Virtual Private Cloud User Guide 8. Under Resources - optional, choose Security Groups. 9. Choose a security group. The security group cannot be a default security group and cannot be associated with the default VPC. 10. Choose Next. 11. Review the actions that principals will be allowed to perform and choose Next. 12. Under Principals - optional, choose Allow sharing only within your organization. 13. Under Principals, select one of the following principal types and enter the appropriate numbers: • AWS account: The account number of an account in your Organization. • Organization: The AWS Organizations ID. • Organizational unit (OU): The ID of an OU in the Organization. • IAM role: The ARN of an IAM role. The account that created the role must be a member of the same Organization as the account creating this resource share. • IAM user: The ARN of an IAM user. The account that created the user must be a member of the same Organization as the account creating this resource share. • Service principal: You cannot share a security group with a service principal. 14. Choose Add. 15. Choose Next. 16. Choose Create resource share. 17. Under Shared resources, wait to see the Status of Associated. If there is a security group association failure, it may be due to one of the limitations listed above. View the details of the security group and the Sharing tab on the details page to see any messages related to why a security group may not be shareable. 18. Return to the VPC console security group list. 19. Choose the security group you shared. 20. Choose the Sharing
vpc-ug-164
vpc-ug.pdf
164
You cannot share a security group with a service principal. 14. Choose Add. 15. Choose Next. 16. Choose Create resource share. 17. Under Shared resources, wait to see the Status of Associated. If there is a security group association failure, it may be due to one of the limitations listed above. View the details of the security group and the Sharing tab on the details page to see any messages related to why a security group may not be shareable. 18. Return to the VPC console security group list. 19. Choose the security group you shared. 20. Choose the Sharing tab. Your AWS RAM resource should be visible there. If it’s not, the resource share creation may have failed and you may need to recreate it. Share security groups with AWS Organizations 451 Amazon Virtual Private Cloud Command line To share a security group User Guide 1. You must first create a resource share for the security group that you want to share with AWS RAM. For steps on how to create a resource share with AWS RAM using the AWS CLI, see Creating a resource share in AWS RAM in the AWS RAM User Guide 2. To view created resource share associations, use get-resource-share-associations. The security group is now shared. You can select the security group when launching an EC2 instance in a shared subnet within the same VPC. Stop sharing a security group This section explains how to use the AWS Management Console and the AWS CLI to stop sharing a security group with other accounts in your Organization. AWS Management Console To stop sharing a security group 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Security groups. 3. Choose a security group to view the details. 4. Choose the Sharing tab. 5. Choose a security group resource share and choose Stop sharing. 6. Choose Yes, stop sharing. Command line To stop sharing a security group Delete the resource share with delete-resource-share. The security group is no longer being shared. After the owner stops sharing a security group, the following rules apply: Share security groups with AWS Organizations 452 Amazon Virtual Private Cloud User Guide • Existing participant Elastic Network Interfaces (ENIs) continue to get any security group rule updates that are made to unshared security groups. Unsharing only prevents the participant from creating new associations with the unshared group. • Participants can no longer associate the unshared security group with any ENIs they own. • Participants can describe and delete the ENIs that are still associated with unshared security groups. • If participants still have ENIs associated with the unshared security group, the owner cannot delete the unshared security group. The owner can only delete the security group after participants disassociate (remove) the security group from all their ENIs. • Participants cannot launch new EC2 instances using an ENI associated with an unshared security group. Control subnet traffic with network access control lists A network access control list (ACL) allows or denies specific inbound or outbound traffic at the subnet level. You can use the default network ACL for your VPC, or you can create a custom network ACL for your VPC with rules that are similar to the rules for your security groups in order to add an additional layer of security to your VPC. There is no additional charge for using network ACLs. The following diagram shows a VPC with two subnets. Each subnet has a network ACL. When traffic enters the VPC (for example, from a peered VPC, VPN connection, or the internet), the router sends the traffic to its destination. Network ACL A determines which traffic destined for subnet 1 is allowed to enter subnet 1, and which traffic destined for a location outside subnet 1 is allowed to leave subnet 1. Similarly, network ACL B determines which traffic is allowed to enter and leave subnet 2. Network ACLs 453 Amazon Virtual Private Cloud User Guide For information about the differences between security groups and network ACLs, see Compare security groups and network ACLs. Contents • Network ACL basics • Network ACL rules • Default network ACL for a VPC • Custom network ACLs for your VPC • Path MTU Discovery and network ACLs • Create a network ACL for your VPC • Manage network ACL associations for your VPC • Delete a network ACL for your VPC • Example: Control access to instances in a subnet Network ACL basics The following are the basic things to know about network ACLs before you begin. Network ACL basics 454 Amazon Virtual Private Cloud Network ACL associations User Guide • Each subnet in your VPC must be associated with a network ACL. If you don't explicitly associate a subnet with a network ACL, the subnet is automatically associated
vpc-ug-165
vpc-ug.pdf
165
VPC • Path MTU Discovery and network ACLs • Create a network ACL for your VPC • Manage network ACL associations for your VPC • Delete a network ACL for your VPC • Example: Control access to instances in a subnet Network ACL basics The following are the basic things to know about network ACLs before you begin. Network ACL basics 454 Amazon Virtual Private Cloud Network ACL associations User Guide • Each subnet in your VPC must be associated with a network ACL. If you don't explicitly associate a subnet with a network ACL, the subnet is automatically associated with the default network ACL. • You can create a custom network ACL and associate it with a subnet to allow or deny specific inbound or outbound traffic at the subnet level. • You can associate a network ACL with multiple subnets. However, a subnet can be associated with only one network ACL at a time. When you associate a network ACL with a subnet, the previous association is removed. Network ACL rules • A network ACL has inbound rules and outbound rules. Each rule can either allow or deny traffic. Each rule has a number from 1 to 32766. We evaluate the rules in order, starting with the lowest numbered rule, when deciding whether allow or deny traffic. If the traffic matches a rule, the rule is applied and we do not evaluate any additional rules. We recommend that you start by creating rules in increments (for example, increments of 10 or 100) so that you can insert new rules later on, if needed. • We evaluate the network ACL rules when traffic enters and leaves the subnet, not as it is routed within a subnet. • NACLs are stateless, which means that information about previously sent or received traffic is not saved. If, for example, you create a NACL rule to allow specific inbound traffic to a subnet, responses to that traffic are not automatically allowed. This is in contrast to how security groups work. Security groups are stateful, which means that information about previously sent or received traffic is saved. If, for example, a security group allows inbound traffic to an EC2 instance, responses are automatically allowed regardless of outbound security group rules. Limitations • There are quotas (also known as limits) for the number of network ACLs per VPC. For more information, see Amazon VPC quotas. • Network ACLs can't block DNS requests to or from the Route 53 Resolver (also known as the VPC +2 IP address or AmazonProvidedDNS). To filter DNS requests through the Route 53 Resolver, you can enable Route 53 Resolver DNS Firewall. Network ACL basics 455 Amazon Virtual Private Cloud User Guide • Network ACLs can't block traffic to the Instance Metadata Service (IMDS). To manage access to IMDS, see Configure the instance metadata options in the Amazon EC2 User Guide. • Network ACLs do not filter traffic destined to and from the following: • Amazon Domain Name Services (DNS) • Amazon Dynamic Host Configuration Protocol (DHCP) • Amazon EC2 instance metadata • Amazon ECS task metadata endpoints • License activation for Windows instances • Amazon Time Sync Service • Reserved IP addresses used by the default VPC router Network ACL rules You can add or remove rules from the default network ACL, or create additional network ACLs for your VPC. When you add or remove rules from a network ACL, the changes are automatically applied to the subnets that it's associated with. The following are the parts of a network ACL rule: • Rule number. Rules are evaluated starting with the lowest numbered rule. As soon as a rule matches traffic, it's applied regardless of any higher-numbered rule that might contradict it. • Type. The type of traffic; for example, SSH. You can also specify all traffic or a custom range. • Protocol. You can specify any protocol that has a standard protocol number. For more information, see Protocol Numbers. If you specify ICMP as the protocol, you can specify any or all of the ICMP types and codes. • Port range. The listening port or port range for the traffic. For example, 80 for HTTP traffic. • Source. [Inbound rules only] The source of the traffic (CIDR range). • Destination. [Outbound rules only] The destination for the traffic (CIDR range). • Allow/Deny. Whether to allow or deny the specified traffic. For example rules, see the section called “Example: Control access to instances in a subnet”. Network ACL rules 456 Amazon Virtual Private Cloud Considerations User Guide • There are quotas (also known as limits) for the number of rules per network ACLs. For more information, see Amazon VPC quotas. • When you add or delete a rule from an ACL, any subnets that are associated with the ACL are
vpc-ug-166
vpc-ug.pdf
166
rules only] The source of the traffic (CIDR range). • Destination. [Outbound rules only] The destination for the traffic (CIDR range). • Allow/Deny. Whether to allow or deny the specified traffic. For example rules, see the section called “Example: Control access to instances in a subnet”. Network ACL rules 456 Amazon Virtual Private Cloud Considerations User Guide • There are quotas (also known as limits) for the number of rules per network ACLs. For more information, see Amazon VPC quotas. • When you add or delete a rule from an ACL, any subnets that are associated with the ACL are subject to the change. The changes take effect after a short period. • If you add a rule using a command line tool or the Amazon EC2 API, the CIDR range is automatically modified to its canonical form. For example, if you specify 100.68.0.18/18 for the CIDR range, we create a rule with a 100.68.0.0/18 CIDR range. • You might want to add a deny rule in a situation where you must open a wide range of ports, but there are certain ports within the range that you want to deny. Be sure to give the deny rule a lower number than the rule that allows the wider range of port traffic. • If you add and delete rules from a network ACL at the same time, be careful. If you delete inbound or outbound rules and then add more new entries than are allowed (see Amazon VPC quotas, the entries selected for deletion are removed and new entries are not added. This can cause unexpected connectivity issues and prevent access to and from your VPC. Default network ACL for a VPC Your virtual private cloud (VPC) automatically comes with a default network ACL. A default network ACL is configured to allow all traffic to flow in and out of the subnets with which it is associated. Each network ACL also includes rules where the rule number is an asterisk (*). These rules ensure that if a packet doesn't match any of the other numbered rules, it's denied. You can modify a default network ACL by adding rules or removing the default numbered rules. You can't delete a rule where the rule number is an asterisk. Default inbound rules The following table shows the default inbound rules for a default network ACL. The rules for IPv6 are added only if you create the VPC with an associated IPv6 CIDR block or associate an IPv6 CIDR block with the VPC. However, if you've modified the inbound rules of a default network ACL, we do not add the rule that allows all inbound IPv6 traffic when you associate an IPv6 block with the VPC. Default network ACL 457 Amazon Virtual Private Cloud User Guide Rule # Type Protocol Port range Source Allow/Deny 100 101 * * All IPv4 traffic All IPv6 traffic All traffic All IPv6 traffic All All All All Default outbound rules All All All All 0.0.0.0/0 ALLOW ::/0 ALLOW 0.0.0.0/0 DENY ::/0 DENY The following table shows the default outbound rules for a default network ACL. The rules for IPv6 are added only if you create the VPC with an associated IPv6 CIDR block or associate an IPv6 CIDR block with the VPC. However, if you've modified the outbound rules of a default network ACL, we do not add the rule that allows all outbound IPv6 traffic when you associate an IPv6 block with the VPC. Rule # Type Protocol Port range Destination Allow/Deny 100 101 * * All traffic All IPv6 traffic All traffic All IPv6 traffic All All All All All All All All 0.0.0.0/0 ALLOW ::/0 ALLOW 0.0.0.0/0 DENY ::/0 DENY Default network ACL 458 Amazon Virtual Private Cloud User Guide Custom network ACLs for your VPC You can create a custom network ACL and associate it with a subnet to allow or deny specific inbound or outbound traffic at the subnet level. For more information, see the section called “Create a network ACL”. Each network ACL includes a default inbound rule and a default outbound rule whose rule number is an asterisk (*). These rules ensure that if a packet doesn't match any of the other rules, it's denied. You can modify a network ACL by adding or removing rules. You can't delete a rule where the rule number is an asterisk. For every rule that you add, there must be an inbound or outbound rule that allows response traffic. For more information about how to select the appropriate ephemeral port range, see Ephemeral ports. Example inbound rules The following table shows example inbound rules for a network ACL. The rules for IPv6 are added only if the VPC has an associated IPv6 CIDR block. IPv4 and IPv6 traffic are evaluated separately. Therefore, none of
vpc-ug-167
vpc-ug.pdf
167
other rules, it's denied. You can modify a network ACL by adding or removing rules. You can't delete a rule where the rule number is an asterisk. For every rule that you add, there must be an inbound or outbound rule that allows response traffic. For more information about how to select the appropriate ephemeral port range, see Ephemeral ports. Example inbound rules The following table shows example inbound rules for a network ACL. The rules for IPv6 are added only if the VPC has an associated IPv6 CIDR block. IPv4 and IPv6 traffic are evaluated separately. Therefore, none of the rules for IPv4 traffic apply to IPv6 traffic. You can add IPv6 rules next to the corresponding IPv4 rules, or add the IPv6 rules after the last IPv4 rule. As a packet comes to the subnet, we evaluate it against the inbound rules of the network ACL that is associated with the subnet, starting with the lowest numbered rule. For example, suppose there is IPv4 traffic destined for the HTTPS port (443). The packet doesn't match rule 100 or 105. It matches rule 110, which allows the traffic into the subnet. If the packet had been destined for port 139 (NetBIOS), it wouldn't match any of the numbered rules, so the * rule for IPv4 traffic ultimately denies the packet. Rule # Type Protocol Port range Source Allow/ Deny Comments 100 HTTP TCP 80 0.0.0.0/0 ALLOW Allows inbound HTTP traffic from any IPv4 address. Custom network ACLs 459 Amazon Virtual Private Cloud User Guide Rule # Type Protocol Port range Source Allow/ Deny Comments 105 HTTP TCP 80 ::/0 ALLOW 110 HTTPS TCP 443 0.0.0.0/0 ALLOW 115 HTTPS TCP 443 ::/0 ALLOW 120 SSH TCP 22 192.0.2.0 ALLOW /24 140 Custom TCP TCP 32768-655 0.0.0.0/0 ALLOW 35 145 Custom TCP TCP 32768-655 ::/0 ALLOW 35 Allows inbound HTTP traffic from any IPv6 address. Allows inbound HTTPS traffic from any IPv4 address. Allows inbound HTTPS traffic from any IPv6 address. Allows inbound SSH traffic from your home network's public IPv4 address range (over the internet gateway). Allows inbound return IPv4 traffic from the internet (for requests that originate in the subnet). Allows inbound return IPv6 traffic from the internet (for requests that originate in the subnet). Custom network ACLs 460 Amazon Virtual Private Cloud User Guide Rule # Type Protocol Port range Source Allow/ Deny Comments * * All traffic All All 0.0.0.0/0 DENY All traffic All All ::/0 DENY Denies all inbound IPv4 traffic not already handled by a preceding rule (not modifiable). Denies all inbound IPv6 traffic not already handled by a preceding rule (not modifiable). Example outbound rules The following table shows example outbound rules for a custom network ACL. The rules for IPv6 are added only if the VPC has an associated IPv6 CIDR block. IPv4 and IPv6 traffic are evaluated separately. Therefore, none of the rules for IPv4 traffic apply to IPv6 traffic. You can add IPv6 rules next to the corresponding IPv4 rules, or add the IPv6 rules after the last IPv4 rule. Rule # Type Protocol Port range Destinati on Allow/ Deny Comments 100 HTTP TCP 80 0.0.0.0/0 ALLOW 105 HTTP TCP 80 ::/0 ALLOW 110 HTTPS TCP 443 0.0.0.0/0 ALLOW Allows outbound IPv4 HTTP traffic from the subnet to the internet. Allows outbound IPv6 HTTP traffic from the subnet to the internet. Allows outbound IPv4 HTTPS traffic from Custom network ACLs 461 Amazon Virtual Private Cloud User Guide Rule # Type Protocol Port range Destinati on Allow/ Deny Comments 115 HTTPS TCP 443 ::/0 ALLOW 120 140 Custom TCP TCP 1024-6553 192.0.2.0 ALLOW 5 /24 Custom TCP TCP 32768-655 0.0.0.0/0 ALLOW 35 145 Custom TCP TCP 32768-655 ::/0 ALLOW 35 * * All traffic All All 0.0.0.0/0 DENY All traffic All All ::/0 DENY the subnet to the internet. Allows outbound IPv6 HTTPS traffic from the subnet to the internet. Allows outbound responses to SSH traffic from your home network. Allows outbound IPv4 responses to clients on the internet (for example, serving webpages). Allows outbound IPv6 responses to clients on the internet (for example, serving webpages). Denies all outbound IPv4 traffic not already handled by a preceding rule. Denies all outbound IPv6 traffic not already handled by a preceding rule. Custom network ACLs 462 Amazon Virtual Private Cloud Ephemeral ports User Guide The example network ACL in the preceding section uses an ephemeral port range of 32768-65535. However, you might want to use a different range for your network ACLs depending on the type of client that you're using or with which you're communicating. The client that initiates the request chooses the ephemeral port range. The range varies depending on the client's operating system. • Many Linux kernels (including the Amazon Linux kernel) use ports 32768-61000. • Requests originating from Elastic Load
vpc-ug-168
vpc-ug.pdf
168
traffic not already handled by a preceding rule. Custom network ACLs 462 Amazon Virtual Private Cloud Ephemeral ports User Guide The example network ACL in the preceding section uses an ephemeral port range of 32768-65535. However, you might want to use a different range for your network ACLs depending on the type of client that you're using or with which you're communicating. The client that initiates the request chooses the ephemeral port range. The range varies depending on the client's operating system. • Many Linux kernels (including the Amazon Linux kernel) use ports 32768-61000. • Requests originating from Elastic Load Balancing use ports 1024-65535. • Windows operating systems through Windows Server 2003 use ports 1025-5000. • Windows Server 2008 and later versions use ports 49152-65535. • A NAT gateway uses ports 1024-65535. • AWS Lambda functions use ports 1024-65535. For example, if a request comes into a web server in your VPC from a Windows 10 client on the internet, your network ACL must have an outbound rule to enable traffic destined for ports 49152-65535. If an instance in your VPC is the client initiating a request, your network ACL must have an inbound rule to enable traffic destined for the ephemeral ports specific to the operating system of the instance. In practice, to cover the different types of clients that might initiate traffic to public-facing instances in your VPC, you can open ephemeral ports 1024-65535. However, you can also add rules to the ACL to deny traffic on any malicious ports within that range. Ensure that you place the deny rules earlier in the table than the allow rules that open the wide range of ephemeral ports. Custom network ACLs and other AWS services If you create a custom network ACL, be aware of how it might affect resources that you create using other AWS services. With Elastic Load Balancing, if the subnet for your backend instances has a network ACL in which you've added a deny rule for all traffic with a source of either 0.0.0.0/0 or the subnet's CIDR, your load balancer can't carry out health checks on the instances. For more information about the recommended network ACL rules for your load balancers and backend instances, see the following: Custom network ACLs 463 Amazon Virtual Private Cloud User Guide • Network ACLs for your Application Load Balancer • Network ACLs for your Network Load Balancer • Network ACLs for your Classic Load Balancer Troubleshoot reachability issues Reachability Analyzer is a static configuration analysis tool. Use Reachability Analyzer to analyze and debug network reachability between two resources in your VPC. Reachability Analyzer produces hop-by-hop details of the virtual path between these resources when they are reachable, and identifies the blocking component otherwise. For example, it can identify missing or misconfigured network ACL rules. For more information, see the Reachability Analyzer Guide. Path MTU Discovery and network ACLs Path MTU Discovery is used to determine the path MTU between two devices. The path MTU is the maximum packet size that's supported on the path between the originating host and the receiving host. For IPv4, when a host sends a packet that's larger than the MTU of the receiving host or that's larger than the MTU of a device along the path, the receiving host or device drops the packet, and then returns the following ICMP message: Destination Unreachable: Fragmentation Needed and Don't Fragment was Set (Type 3, Code 4). This instructs the transmitting host to split the payload into multiple smaller packets, and then retransmit them. The IPv6 protocol does not support fragmentation in the network. When a host sends a packet that's larger than the MTU of the receiving host or that's larger than the MTU of a device along the path, the receiving host or device drops the packet, and then returns the following ICMP message: ICMPv6 Packet Too Big (PTB) (Type 2). This instructs the transmitting host to split the payload into multiple smaller packets, and then retransmit them. If the maximum transmission unit (MTU) between hosts in your subnets is different, or your instances communicate with peers over the internet, you must add the following network ACL rule, both inbound and outbound. This ensures that Path MTU Discovery can function correctly and prevent packet loss. Select Custom ICMP Rule for the type and Destination Unreachable, fragmentation required, and DF flag set for the port range (type 3, code 4). If you use traceroute, Path MTU Discovery 464 Amazon Virtual Private Cloud User Guide also add the following rule: select Custom ICMP Rule for the type and Time Exceeded, TTL expired transit for the port range (type 11, code 0). For more information, see Network maximum transmission unit (MTU) for your EC2 instance in the Amazon EC2 User Guide. Create a network ACL for your VPC
vpc-ug-169
vpc-ug.pdf
169
Path MTU Discovery can function correctly and prevent packet loss. Select Custom ICMP Rule for the type and Destination Unreachable, fragmentation required, and DF flag set for the port range (type 3, code 4). If you use traceroute, Path MTU Discovery 464 Amazon Virtual Private Cloud User Guide also add the following rule: select Custom ICMP Rule for the type and Time Exceeded, TTL expired transit for the port range (type 11, code 0). For more information, see Network maximum transmission unit (MTU) for your EC2 instance in the Amazon EC2 User Guide. Create a network ACL for your VPC The following tasks show you how to create a network ACL, add rules to the network ACL, and then associate the network ACL with a subnet. Tasks • Step 1: Create a network ACL • Step 2: Add rules • Step 3: Associate a subnet with a network ACL • (Optional) Manage network ACLs using Firewall Manager Step 1: Create a network ACL You can create a custom network ACL for your VPC. The initial rules for a custom network ACL block all inbound and outbound traffic. Your new custom network ACL is not associated with a subnet by default and must be explicitly associated with subnets. To create a network ACL using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Network ACLs. 3. Choose Create network ACL. 4. 5. 6. (Optional) For Name, enter a name for your network ACL. For VPC, select the VPC. (Optional) For Tags, choose Add tag and then enter a tag key and a tag value. 7. Choose Create network ACL. To create a network ACL using the command line • create-network-acl (AWS CLI) • New-EC2NetworkAcl (AWS Tools for Windows PowerShell) Create a network ACL 465 Amazon Virtual Private Cloud Step 2: Add rules User Guide You can add rules that allow or deny inbound or outbound traffic. We process the rules in order, starting with the rule with the lowest number. We recommend that you leave gaps between the rule numbers (such as 100, 200, 300), rather than using sequential numbers (101, 102, 103). This makes it easier add a new rule without having to renumber the existing rules. If you're using the Amazon EC2 API or a command line tool, you can't modify rules. You can only add and delete rules. If you're using the Amazon VPC console, you can modify the entries for existing rules. The console removes the existing rule and adds a new rule for you. If you need to change the order of a rule in the ACL, you must add a new rule with the new rule number, and then delete the original rule. To add rules to a network ACL using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Network ACLs. Select the network ACL. To add an inbound rule, do the following: a. Choose the Inbound rules tab. b. Choose Edit inbound rules, Add new rule. c. Enter a rule number that is not already in use, a type, protocol, port range, source, and whether to allow or deny the traffic. For some types, we fill in the protocol and port for you. If you are prompted for a port range, enter a port number or a port range (for example, 49152-65535). To use a protocol that's not listed, choose Custom Protocol for the type and then select the protocol. For more information, see IANA Protocol Numbers. d. Choose Save changes. 5. To add an outbound rule, do the following: a. Choose the Outbound rules tab. b. Choose Edit outbound rules, Add new rule. c. Enter a rule number that is not already in use, a type, protocol, port range, source, and whether to allow or deny the traffic. For some types, we fill in the protocol and port Create a network ACL 466 Amazon Virtual Private Cloud User Guide for you. If you are prompted for a port range, enter a port number or a port range (for example, 49152-65535). To use a protocol that's not listed, choose Custom Protocol for the type and then select the protocol. For more information, see IANA Protocol Numbers. d. Choose Save changes. To add a rule to a network ACL using the command line • create-network-acl-entry (AWS CLI) • New-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) To replace a rule in a network ACL using the command line • replace-network-acl-entry (AWS CLI) • Set-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) To delete a rule from a network ACL using the command line • delete-network-acl-entry (AWS CLI) • Remove-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) Step 3: Associate a subnet with a network ACL To apply the rules of a network ACL to
vpc-ug-170
vpc-ug.pdf
170
the protocol. For more information, see IANA Protocol Numbers. d. Choose Save changes. To add a rule to a network ACL using the command line • create-network-acl-entry (AWS CLI) • New-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) To replace a rule in a network ACL using the command line • replace-network-acl-entry (AWS CLI) • Set-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) To delete a rule from a network ACL using the command line • delete-network-acl-entry (AWS CLI) • Remove-EC2NetworkAclEntry (AWS Tools for Windows PowerShell) Step 3: Associate a subnet with a network ACL To apply the rules of a network ACL to a particular subnet, you must associate the subnet with the network ACL. You can associate a network ACL with multiple subnets. However, a subnet can be associated with only one network ACL. Any subnet that is not associated with a particular ACL is associated with the default network ACL by default. To associate a subnet with a network ACL 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Network ACLs, and then select the network ACL. In the details pane, on the Subnet Associations tab, choose Edit. Select the Associate check box for the subnet to associate with the network ACL, and then choose Save. Create a network ACL 467 Amazon Virtual Private Cloud User Guide (Optional) Manage network ACLs using Firewall Manager AWS Firewall Manager simplifies your network ACL administration and maintenance tasks across multiple accounts and subnets. You can use Firewall Manager to monitor accounts and subnets in your organization and to automatically apply the network ACL configurations that you've defined. Firewall Manager is particularly useful when you want to protect your entire organization, or if you frequently add new subnets that you want to automatically protect from a central administrator account. With a Firewall Manager network ACL policy, using a single administrator account, you can configure, monitor, and manage the minimum rule sets that you want to have defined in the network ACLs that you use across your organization. You specify which accounts and subnets in your organization are within scope of the Firewall Manager policy. Firewall Manager reports the compliance status of the network ACLs for in-scope subnets, and you can configure Firewall Manager to automate the remediation of noncompliant network ACLs. For more information, see the following resources in the AWS Firewall Manager Developer Guide: • AWS Firewall Manager prerequisites • Setting up AWS Firewall Manager network ACL policies • Using network ACL policies with Firewall Manager Manage network ACL associations for your VPC Each subnet is associated with one network ACL. When you first create a subnet, it is associated with the default network ACL for the VPC. You can create a custom network ACL and associate it with one or more subnets, replacing the previous network ACL association. Tasks • Describe your network ACL associations • Change the subnets associated with a network ACL • Change the network ACL associated with a subnet Describe your network ACL associations You can describe the network ACL that's associated with a subnet and you can also describe which subnets are associated with a network ACL. Manage network ACL associations 468 Amazon Virtual Private Cloud User Guide To describe the network ACL associated with a subnet using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Subnets. Select the subnet. Select the Network ACL tab. To describe the network ACL associated with a subnet using the AWS CLI Use the following describe-network-acls command to list the network ACL associated with the specified subnet. aws ec2 describe-network-acls --filters Name=association.subnet- id,Values=subnet-0d2d1b81e0bc9c6d4 --query NetworkAcls[*].NetworkAclId The following is example output. [ "acl-03701d1f82d8c3fd6" ] To describe the subnets associated with a network ACL using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. 4. In the navigation pane, choose Network ACLs. Select the network ACL. Select the Subnet associations tab. To describe the subnets associated with a network ACL using the AWS CLI Use the following describe-network-acls command to list the subnets associated with the specified network ACL. aws ec2 describe-network-acls --network-acl-ids acl-060415a18fcc9afde --query NetworkAcls[*].Associations[].SubnetId The following is example output. Manage network ACL associations 469 Amazon Virtual Private Cloud User Guide [ "subnet-0d2d1b81e0bc9c6d4", "subnet-0e990c67809773b19", "subnet-0eb17d85f5dfd33b1", "subnet-0e01d500780bb7468" ] Change the subnets associated with a network ACL You can disassociate a custom network ACL from a subnet. After you disassociate a subnet from a custom network ACL, we automatically associate it with the default network ACL for the VPC. The changes take effect after a short period of time. To change the subnets associated with a network ACL 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Network ACLs. Select the network ACL. 4. Choose Actions, Edit subnet associations. 5.
vpc-ug-171
vpc-ug.pdf
171
469 Amazon Virtual Private Cloud User Guide [ "subnet-0d2d1b81e0bc9c6d4", "subnet-0e990c67809773b19", "subnet-0eb17d85f5dfd33b1", "subnet-0e01d500780bb7468" ] Change the subnets associated with a network ACL You can disassociate a custom network ACL from a subnet. After you disassociate a subnet from a custom network ACL, we automatically associate it with the default network ACL for the VPC. The changes take effect after a short period of time. To change the subnets associated with a network ACL 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Network ACLs. Select the network ACL. 4. Choose Actions, Edit subnet associations. 5. Remove the subnet from Selected subnets. 6. Choose Save changes. Change the network ACL associated with a subnet You can change the network ACL that's associated with a subnet. For example, when you create a subnet, it is initially associated with the default network ACL for the VPC. If you create a custom network ACL, you apply the network ACL rules by associating the network ACL with one or more subnets. After you change the network ACL for a subnet, the changes take effect after a short period of time. To change the network ACL associated with a subnet 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Subnets. Select the subnet. Manage network ACL associations 470 Amazon Virtual Private Cloud User Guide 4. Choose Actions, Edit network ACL association. 5. For Network ACL ID, select the network ACL to associate with the subnet, and review the inbound and outbound rules for the selected network ACL. 6. Choose Save. To replace a network ACL association using the command line • replace-network-acl-association (AWS CLI) • Set-EC2NetworkAclAssociation (AWS Tools for Windows PowerShell) Delete a network ACL for your VPC When you are finished with a network ACL, you can delete it. You can't delete a network ACL if there are subnets associated with it. You can't delete the default network ACL. To remove subnet associations from a network ACL using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. In the navigation pane, choose Network ACLs. The Associated with column indicates the number of subnets associated with each network ACL. This column is - if there are no associated subnets. 3. Select the network ACL. 4. Choose Actions, Edit subnet associations. 5. Remove the subnet associations. 6. Choose Save changes. To describe your network ACLs, including associations, using the command line • describe-network-acls (AWS CLI) • Get-EC2NetworkAcl (AWS Tools for Windows PowerShell) To replace a network ACL association using the command line • replace-network-acl-association (AWS CLI) • Set-EC2NetworkAclAssociation (AWS Tools for Windows PowerShell) Delete a network ACL 471 Amazon Virtual Private Cloud User Guide To delete a network ACL using the console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. 3. In the navigation pane, choose Network ACLs. Select the network ACL. 4. Choose Actions, Delete network ACLs. 5. When prompted for confirmation, enter delete and then choose Delete. To delete a network ACL using the command line • delete-network-acl (AWS CLI) • Remove-EC2NetworkAcl (AWS Tools for Windows PowerShell) Example: Control access to instances in a subnet In this example, instances in the subnet can communicate with each other, and are accessible from a trusted remote computer in order to perform administrative tasks. The remote computer might be a computer in your local network, as shown in the diagram, or it might be an instance in a different subnet or VPC. The network ACL rules for the subnet, and the security group rules for the instances, allow access from the IP address of your remote computer. All other traffic from the internet or other networks is denied. Using a network ACL gives you the flexibility to change the security groups or security group rules for your instances while relying on the network ACL as a backup layer of defense. For example, Example: Control access to instances in a subnet 472 Amazon Virtual Private Cloud User Guide if you accidentally update the security group to allow inbound SSH access from anywhere, but the network ACL allows access only from the IP address range of the remote computer, then the network ACL denies inbound SSH traffic from any other IP addresses. Network ACL rules The following are example inbound rules for the network ACL associated with the subnet. These rules apply to all instances in the subnet. Rule # Type Protocol Port range Source Allow/Den y Comments 100 SSH TCP 22 172.31.1. ALLOW 2/32 * All traffic All All 0.0.0.0/0 DENY Allow inbound traffic from the remote computer. Deny all other inbound traffic. The following are example outbound rules for the network ACL associated with the subnet. Network ACLs are stateless. Therefore, you must include a rule that allows responses to the inbound traffic. Rule
vpc-ug-172
vpc-ug.pdf
172
traffic from any other IP addresses. Network ACL rules The following are example inbound rules for the network ACL associated with the subnet. These rules apply to all instances in the subnet. Rule # Type Protocol Port range Source Allow/Den y Comments 100 SSH TCP 22 172.31.1. ALLOW 2/32 * All traffic All All 0.0.0.0/0 DENY Allow inbound traffic from the remote computer. Deny all other inbound traffic. The following are example outbound rules for the network ACL associated with the subnet. Network ACLs are stateless. Therefore, you must include a rule that allows responses to the inbound traffic. Rule # Type Protocol Port range Destinati on Allow/Den y Comments 100 Custom TCP TCP 1024-6553 5 172.31.1. ALLOW 2/32 Allows outbound responses to the remote computer. Example: Control access to instances in a subnet 473 Amazon Virtual Private Cloud User Guide Rule # Type Protocol Port range Destinati on Allow/Den y Comments * All traffic All All 0.0.0.0/0 DENY Denies all other outbound traffic. Security group rules The following are example inbound rules for the security group associated with the instances. These rules apply to all instances associated with the security group. A user with the private key for the key pair associated with the instances can connect to the instances from the remote computer using SSH. Protocol type Protocol Port range Source Comments All traffic All All SSH TCP 22 sg-123456 7890abcde f0 172.31.1. 2/32 Allow communica tion between the instances associated with this security group. Allow inbound SSH access from the remote computer. The following are example outbound bound rules for the security group associated with the instances. Security groups are stateful. Therefore, you don't need a rule that allows responses to inbound traffic. Example: Control access to instances in a subnet 474 Amazon Virtual Private Cloud User Guide Protocol Type Protocol Port range Destination Comments All traffic All All sg-123456 7890abcde f0 Allow communica tion between the instances associated with this security group. Differences between network ACLs and security groups The following table summarizes the basic differences between network ACLs and security groups. Characteristic Network ACL Subnet level Level of operation Scope Security group Instance level Applies to all instances in the associated subnets Applies to all instances associated with the security group Rule type Allow and deny rules Allow rules only Rule evaluation Evaluates rules in ascending order until a match for the traffic is found Evaluates all rules before deciding whether to allow traffic Return traffic Must be explicitly allowed (stateless) Automatically allowed (stateful) Resilience in Amazon Virtual Private Cloud The AWS global infrastructure is built around AWS Regions and Availability Zones. AWS Regions provide multiple physically separated and isolated Availability Zones, which are connected using low-latency, high-throughput, and highly redundant networking. With Availability Zones, you can design and operate applications and databases that automatically fail over between zones Resilience 475 Amazon Virtual Private Cloud User Guide without interruption. Availability Zones are more highly available, fault tolerant, and scalable than traditional single or multiple data center infrastructures. AWS Regions are the primary building blocks, each representing a distinct geographical location housing multiple physically separated and isolated Availability Zones. These Availability Zones are connected through a low-latency, high-throughput, and highly redundant networking fabric, enabling seamless communication and data transfer between them. The architecture of Availability Zones is a key differentiator, as they are designed to be far more robust and fault-tolerant than traditional single or multiple data center setups. By distributing resources across multiple Availability Zones within a Region, applications and databases can be engineered to automatically fail over between zones without any interruption to service. This level of redundancy and high availability is a critical requirement for mission-critical workloads and enables organizations to build resilient cloud-native solutions. Furthermore, the scale and global reach of the AWS infrastructure empower customers to deploy their applications closer to end-users, reducing latency and improving the overall user experience. The availability of multiple Regions across the world also allows for effective data sovereignty and compliance, as customers can store and process data within the geographical boundaries required by their specific regulatory and business needs. By leveraging the AWS global infrastructure, organizations can architect their cloud environments to be highly available, fault-tolerant, and scalable, with the flexibility to adapt to changing requirements and evolving business needs. This robust foundation is a key enabler for the successful implementation of modern, cloud-based applications and services. For more information about AWS Regions and Availability Zones, see AWS Global Infrastructure. You can configure your VPCs to meet the resilience requirements for your workloads. For more information, see the following: • Understand resiliency patterns and trade-offs (AWS Architecture Blog) • Plan your network topology (AWS Well-Architected Framework) • Amazon Virtual Private Cloud Connectivity Options (AWS Whitepapers) Resilience 476 Amazon Virtual Private Cloud User Guide Compliance validation
vpc-ug-173
vpc-ug.pdf
173
fault-tolerant, and scalable, with the flexibility to adapt to changing requirements and evolving business needs. This robust foundation is a key enabler for the successful implementation of modern, cloud-based applications and services. For more information about AWS Regions and Availability Zones, see AWS Global Infrastructure. You can configure your VPCs to meet the resilience requirements for your workloads. For more information, see the following: • Understand resiliency patterns and trade-offs (AWS Architecture Blog) • Plan your network topology (AWS Well-Architected Framework) • Amazon Virtual Private Cloud Connectivity Options (AWS Whitepapers) Resilience 476 Amazon Virtual Private Cloud User Guide Compliance validation for Amazon Virtual Private Cloud To learn whether an AWS service is within the scope of specific compliance programs, see AWS services in Scope by Compliance Program and choose the compliance program that you are interested in. For general information, see AWS Compliance Programs. You can download third-party audit reports using AWS Artifact. For more information, see Downloading Reports in AWS Artifact. Your compliance responsibility when using AWS services is determined by the sensitivity of your data, your company's compliance objectives, and applicable laws and regulations. AWS provides the following resources to help with compliance: • Security Compliance & Governance – These solution implementation guides discuss architectural considerations and provide steps for deploying security and compliance features. • HIPAA Eligible Services Reference – Lists HIPAA eligible services. Not all AWS services are HIPAA eligible. • AWS Compliance Resources – This collection of workbooks and guides might apply to your industry and location. • AWS Customer Compliance Guides – Understand the shared responsibility model through the lens of compliance. The guides summarize the best practices for securing AWS services and map the guidance to security controls across multiple frameworks (including National Institute of Standards and Technology (NIST), Payment Card Industry Security Standards Council (PCI), and International Organization for Standardization (ISO)). • Evaluating Resources with Rules in the AWS Config Developer Guide – The AWS Config service assesses how well your resource configurations comply with internal practices, industry guidelines, and regulations. • AWS Security Hub – This AWS service provides a comprehensive view of your security state within AWS. Security Hub uses security controls to evaluate your AWS resources and to check your compliance against security industry standards and best practices. For a list of supported services and controls, see Security Hub controls reference. • Amazon GuardDuty – This AWS service detects potential threats to your AWS accounts, workloads, containers, and data by monitoring your environment for suspicious and malicious activities. GuardDuty can help you address various compliance requirements, like PCI DSS, by meeting intrusion detection requirements mandated by certain compliance frameworks. Compliance validation 477 Amazon Virtual Private Cloud User Guide • AWS Audit Manager – This AWS service helps you continuously audit your AWS usage to simplify how you manage risk and compliance with regulations and industry standards. Block public access to VPCs and subnets VPC Block Public Access (BPA) is a centralized security feature that enables you to authoritatively prevent public internet access to VPC resources across an entire AWS account, ensuring compliance with security requirements while providing flexibility for specific exceptions and audit capabilities. The VPC BPA feature has the following modes: • Bidirectional: All traffic to and from internet gateways and egress-only internet gateways in this Region (except for excluded VPCs and subnets) is blocked. • Ingress-only: All internet traffic to the VPCs in this Region (except for VPCs or subnets which are excluded) is blocked. Only traffic to and from NAT gateways and egress-only internet gateways is allowed because these gateways only allow outbound connections to be established. You can also create "exclusions" for this feature for traffic you don't want to block. An exclusion is a mode that can be applied to a single VPC or subnet that exempts it from the account's VPC BPA mode and will allow bidirectional or egress-only access. Exclusions can have either of the following modes: • Bidirectional: All internet traffic to and from the excluded VPCs and subnets is allowed. • Egress-only: Outbound internet traffic from the excluded VPCs and subnets is allowed. Inbound internet traffic to the excluded VPCs and subnets is blocked. This only applies when VPC BPA is set to Bidirectional. Contents • VPC BPA basics • Assess impact of VPC BPA and monitor VPC BPA • Advanced example Block public access to VPCs and subnets 478 Amazon Virtual Private Cloud VPC BPA basics User Guide This section covers important details about VPC BPA, including which services support it and how you can work with it. Contents • Regional availability • AWS service impact and support • VPC BPA limitations • Control access to VPC BPA with an IAM policy • Enable VPC BPA bidirectional mode for your account • Change VPC BPA mode to ingress-only •
vpc-ug-174
vpc-ug.pdf
174
is set to Bidirectional. Contents • VPC BPA basics • Assess impact of VPC BPA and monitor VPC BPA • Advanced example Block public access to VPCs and subnets 478 Amazon Virtual Private Cloud VPC BPA basics User Guide This section covers important details about VPC BPA, including which services support it and how you can work with it. Contents • Regional availability • AWS service impact and support • VPC BPA limitations • Control access to VPC BPA with an IAM policy • Enable VPC BPA bidirectional mode for your account • Change VPC BPA mode to ingress-only • Create and delete exclusions • Enable VPC BPA at the Organization level Regional availability VPC BPA is available in all commercial AWS Regions including GovCloud and China Regions. In this guide, you'll also find information about using Network Access Analyzer and Reachability Analyzer with VPC BPA. Note that Network Access Analyzer and Reachability Analyzer are not available in all commercial Regions. For information about the regional availability of Network Access Analyzer and Reachability Analyzer, see Limitations in the Network Access Analyzer Guide and Considerations in the Reachability Analyzer Guide. AWS service impact and support The following resources and services support VPC BPA and traffic to these services and resources is impacted by VPC BPA: • Internet gateway: All inbound and outbound traffic is blocked. • Egress-only internet gateway: All outbound traffic is blocked. Egress-only internet gateways do not allow inbound traffic. • Gateway Load Balancer (GWLB): All inbound and outbound traffic is blocked even if the subnet containing GWLB endpoints is excluded. VPC BPA basics 479 Amazon Virtual Private Cloud User Guide • NAT gateway: All inbound and outbound traffic is blocked. NAT gateways require an internet gateway for internet connectivity. • Internet-facing Network Load Balancer: All inbound and outbound traffic is blocked. Internet- facing Network Load Balancers require an internet gateway for internet connectivity. • Internet-facing Application Load Balancer: All inbound and outbound traffic is blocked. Internet-facing Application Load Balancers require an internet gateway for internet connectivity. • Amazon CloudFront VPC Origins: All inbound and outbound traffic is blocked. • AWS Direct Connect: All inbound and outbound traffic that uses public virtual interfaces (public IPv4 or global unicast IPv6 addresses) is blocked. This traffic uses the internet gateway (or egress-only internet-gateway) for connectivity. • AWS Global Accelerator: Inbound traffic to VPCs is blocked, whether or not the target is otherwise accessible from the internet. • AWS Network Firewall: All inbound and outbound traffic is blocked even if the subnet containing firewall endpoints is excluded. • AWS Wavelength carrier gateway: All inbound and outbound traffic is blocked. Traffic related to private connectivity, such as traffic for the following services and resources, is not blocked or impacted by VPC BPA: • AWS Client VPN • AWS CloudWAN • AWS Outposts local gateway • AWS Site-to-Site VPN • Transit gateway • AWS Verified Access Important • If you are routing incoming and outgoing traffic through an appliance (such as a 3rd- party security or monitoring tool) running on an EC2 instance in a subnet, when using VPC BPA, that subnet needs to be an exclusion for traffic to flow in and out of it. Other subnets sending traffic to the appliance subnet and not to the internet gateway do not need to be added as exclusions. VPC BPA basics 480 Amazon Virtual Private Cloud User Guide • Traffic sent privately from resources in your VPC to other services running in your VPC, such as the EC2 DNS Resolver or Amazon OpenSearch Service, is allowed even when VPC BPA is turned on because it does not pass through an internet gateway in your VPC. It is possible that these services may make requests to resources outside of the VPC on your behalf, for example, in order to resolve a DNS query, and may expose information about the activity of resources within your VPC if not mitigated through other security controls. VPC BPA limitations VPC BPA ingress-only mode is not supported in Local Zones (LZs) where NAT gateways and egress- only internet gateways are not allowed. Control access to VPC BPA with an IAM policy For examples of IAM policies that allow/deny access to the VPC BPA feature, see Block public access to VPCs and subnets. Enable VPC BPA bidirectional mode for your account VPC BPA bidirectional mode blocks all traffic to and from internet gateways and egress-only internet gateways in this Region (except for excluded VPCs and subnets). For more information about exclusions, see Create and delete exclusions. Important We strongly recommend that you thoroughly review the workloads that require Internet access prior to enabling VPC BPA in your production accounts. Note • To enable VPC BPA on the VPCs and subnets in your account, you must own the VPCs and subnets. •
vpc-ug-175
vpc-ug.pdf
175
the VPC BPA feature, see Block public access to VPCs and subnets. Enable VPC BPA bidirectional mode for your account VPC BPA bidirectional mode blocks all traffic to and from internet gateways and egress-only internet gateways in this Region (except for excluded VPCs and subnets). For more information about exclusions, see Create and delete exclusions. Important We strongly recommend that you thoroughly review the workloads that require Internet access prior to enabling VPC BPA in your production accounts. Note • To enable VPC BPA on the VPCs and subnets in your account, you must own the VPCs and subnets. • If you are currently sharing VPC subnets with other accounts, the VPC BPA mode enforced by the subnet owner applies to participant traffic as well, but participants can't control the VPC BPA settings that impact the shared subnet. VPC BPA basics 481 Amazon Virtual Private Cloud AWS Management Console User Guide 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. Choose Edit public access settings. 4. Choose Turn on block public access and Bidirectional, then choose Save changes. 5. Wait for the Status to change to On. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. VPC BPA Bidirectional mode is now on. AWS CLI 1. Turn on VPC BPA: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-bidirectional It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. View the status of VPC BPA: aws ec2 --region us-east-2 describe-vpc-block-public-access-options Change VPC BPA mode to ingress-only VPC BPA ingress-only mode blocks all internet traffic to the VPCs in this Region (except for VPCs or subnets which are excluded). Only traffic to and from NAT gateways and egress-only internet gateways is allowed because these gateways only allow outbound connections to be established. AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. Choose Edit public access settings. 4. Change the direction to Ingress-only. VPC BPA basics 482 Amazon Virtual Private Cloud User Guide 5. Save the changes and wait for the status to be updated. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. AWS CLI 1. Modify the VPC BPA block direction: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-ingress It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. View the status of VPC BPA: aws ec2 --region us-east-2 describe-vpc-block-public-access-options Create and delete exclusions A VPC BPA exclusion is a mode that can be applied to a single VPC or subnet that exempts it from the account’s VPC BPA mode and will allow bidirectional or egress-only access. You can create VPC BPA exclusions for VPCs and subnets even when VPC BPA is not enabled on the account to ensure that there is no traffic disruption to the exclusions when VPC BPA is turned on. An exclusion for a VPC automatically applies to all subnets in the VPC. You can create a maximum of 50 exclusions. For information about requesting a limit increase, see VPC BPA exclusions per account in Amazon VPC quotas. AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. In the Block public access tab, under Exclusions, do one of the following: • To delete an exclusion, select the exclusion and then choose Actions > Delete exclusions. • To create an exclusion, choose Create exclusions and continue with the next steps. 4. Choose a block direction: • Bidirectional: Allows all internet traffic to and from the excluded VPCs and subnets. VPC BPA basics 483 Amazon Virtual Private Cloud User Guide • Egress-only: Allows outbound internet traffic from the excluded VPCs and subnets. Blocks inbound internet traffic to the excluded VPCs and subnets. This setting applies when VPC BPA is set to Bidirectional. 5. Choose a VPC or subnet. 6. Choose Create exclusions. 7. Wait for the Exclusion status to change to Active. You may need to refresh the exclusion table to see the change. The exclusion has been created. AWS CLI 1. Modify the exclusion allow direction: aws ec2 --region us-east-2 create-vpc-block-public-access-exclusion --subnet- id subnet-id --internet-gateway-exclusion-mode allow-bidirectional 2. It can take time for the exclusion status to update. To view the status of the exclusion: aws ec2 --region us-east-2 describe-vpc-block-public-access-exclusions -- exclusion-ids exclusion-id Enable VPC BPA at the Organization level If you are using AWS Organizations to manage accounts in your organization, you can use an AWS Organizations declarative policy to enforce VPC BPA on the accounts in the organization. For more information about the VPC BPA declarative policy,
vpc-ug-176
vpc-ug.pdf
176
table to see the change. The exclusion has been created. AWS CLI 1. Modify the exclusion allow direction: aws ec2 --region us-east-2 create-vpc-block-public-access-exclusion --subnet- id subnet-id --internet-gateway-exclusion-mode allow-bidirectional 2. It can take time for the exclusion status to update. To view the status of the exclusion: aws ec2 --region us-east-2 describe-vpc-block-public-access-exclusions -- exclusion-ids exclusion-id Enable VPC BPA at the Organization level If you are using AWS Organizations to manage accounts in your organization, you can use an AWS Organizations declarative policy to enforce VPC BPA on the accounts in the organization. For more information about the VPC BPA declarative policy, see Supported declarative policies in the AWS Organizations User Guide. Note • You can use the VPC BPA declarative policy to configure if exclusions are allowed, but you cannot create exclusions with the policy. To create exclusions, you still have to create them in the account that owns the VPC. For more information about creating VPC BPA exclusions, see Create and delete exclusions. VPC BPA basics 484 Amazon Virtual Private Cloud User Guide • If the VPC BPA declarative policy is enabled, in Block public access settings, you'll see Managed by Declarative Policy and you won't be able to modify VPC BPA settings at the account level. Assess impact of VPC BPA and monitor VPC BPA This section contains information on you can assess the impact of VPC BPA before you turn it on and how you monitor if traffic is being blocked after you turn it on. Contents • Assess the impact of VPC BPA with Network Access Analyzer • Monitor VPC BPA impact with flow logs • Track exclusion deletion with CloudTrail • Verify connectivity is blocked with Reachability Analyzer Assess the impact of VPC BPA with Network Access Analyzer In this section, you'll use Network Access Analyzer to view the resources in your account that use an internet gateway before you enable VPC BPA and block access. Use this analysis to understand the impact of turning on VPC BPA in your account and blocking traffic. Note • Network Access Analyzer does not support IPv6; so you will not be able to use it to view the potential impact of VPC BPA on egress-only internet gateway outbound IPv6 traffic. • You are charged for the analyses you perform with Network Access Analyzer. For more information, see Pricing in the Network Access Analyzer Guide. • For information about the regional availability of Network Access Analyzer, see Limitations in the Network Access Analyzer Guide. AWS Management Console 1. Open the AWS Network Insights console at https://console.aws.amazon.com/ networkinsights/. Assess impact of VPC BPA and monitor VPC BPA 485 Amazon Virtual Private Cloud User Guide 2. Choose Network Access Analyzer. 3. Choose Create Network Access Scope. 4. Choose Assess impact of VPC Block Public Access and choose Next. 5. The template is already configured to analyze traffic to and from the internet gateways in your account. You can view this under Source and Destination. 6. Choose Next. 7. Choose Create Network Access Scope. 8. Choose the scope you just created and choose Analyze. 9. Wait for the analysis to complete. 10. View the findings of the analysis. Each row under Findings shows a network path that a packet can take in a network to or from an internet gateway in your account. In this case, if you turn on VPC BPA and none of the VPCs and or subnets that appear in these findings are configured as VPC BPA exclusions, traffic to those VPCs and subnets will be restricted. 11. Analyze each finding to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. AWS CLI 1. Create a network access scope: aws ec2 create-network-insights-access-scope --region us-east-2 --match-paths "Source={ResourceStatement={ResourceTypes=["AWS::EC2::InternetGateway"]}}" "Destination={ResourceStatement={ResourceTypes=["AWS::EC2::InternetGateway"]}}" 2. Start the scope analysis: aws ec2 start-network-insights-access-scope-analysis --region us-east-2 -- network-insights-access-scope-id nis-id 3. Get the results of the analysis: aws ec2 get-network-insights-access-scope-analysis-findings --region us-east-2 --network-insights-access-scope-analysis-id nisa-0aa383a1938f94cd1 --max-items 1 Assess impact of VPC BPA and monitor VPC BPA 486 Amazon Virtual Private Cloud User Guide The results show the traffic to and from the internet gateways in all the VPCs in your account. The results are organized as "findings". "FindingId": "AnalysisFinding-1" indicates that this is the first finding in the analysis. Note that there are multiple findings and each indicates a traffic flow that will be impacted by turning on VPC BPA. The first finding will show that traffic started at an internet gateway ("SequenceNumber": 1), passed to an NACL ("SequenceNumber": 2) to a security group ("SequenceNumber": 3) and ended at an instance ("SequenceNumber": 4). 4. Analyze the findings to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. Monitor VPC BPA impact with flow logs VPC Flow Logs is a feature that enables you to capture information about
vpc-ug-177
vpc-ug.pdf
177
first finding in the analysis. Note that there are multiple findings and each indicates a traffic flow that will be impacted by turning on VPC BPA. The first finding will show that traffic started at an internet gateway ("SequenceNumber": 1), passed to an NACL ("SequenceNumber": 2) to a security group ("SequenceNumber": 3) and ended at an instance ("SequenceNumber": 4). 4. Analyze the findings to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. Monitor VPC BPA impact with flow logs VPC Flow Logs is a feature that enables you to capture information about the IP traffic going to and from Elastic network interfaces in your VPC. You can use this feature to monitor traffic that is blocked by VPC BPA from reaching your instance network interfaces. Create a flow log for your VPC using the steps in Work with flow logs. When you create the flow log, make sure you use a custom format that includes the field reject- reason. When you view the flow logs, if traffic to an ENI is rejected due to VPC BPA, you'll see a reject- reason of BPA in the flow log entry. In addition to the standard limitations for VPC flow logs, note the following limitations specific to VPC BPA: • Flow logs for VPC BPA do not include skipped records. • Flow logs for VPC BPA do not include bytes even if you include the bytes field in your flow log. Track exclusion deletion with CloudTrail This section explains how you can use AWS CloudTrail to monitor and track the deletion of VPC BPA exclusions. Assess impact of VPC BPA and monitor VPC BPA 487 Amazon Virtual Private Cloud AWS Management Console User Guide You can view any deleted exclusions in the CloudTrail Event history by looking up Resource type > AWS::EC2::VPCBlockPublicAccessExclusion in the AWS CloudTrail console at https://console.aws.amazon.com/cloudtrailv2/. AWS CLI You can use the lookup-events command to view the events related to deleting exclusions: aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceType,AttributeValue=AWS::EC2::VPCBlockPublicAccessExclusion Verify connectivity is blocked with Reachability Analyzer VPC Reachability Analyzer can be used to evaluate whether or not certain network paths can be reached given your network configuration, including VPC BPA settings. For information about the regional availability of Reachability Analyzer, see Considerations in the Reachability Analyzer Guide. AWS Management Console 1. Open the AWS Network Insights console at https://console.aws.amazon.com/ networkinsights/home#ReachabilityAnalyzer. 2. Click Create and analyze path. 3. 4. For the Source Type, choose Internet Gateways and select the internet gateway you want to block traffic from the Source dropdown. For the Destination Type, choose Instances and select the instance you want to block traffic to from the Destination dropdown. 5. Click Create and analyze path. 6. Wait for the analysis to complete. It could take a few minutes. 7. Once complete, you should see that the Reachability Status is Not reachable and that the Path details shows that VPC_BLOCK_PUBLIC_ACCESS_ENABLED is the cause of this reachability issue. Assess impact of VPC BPA and monitor VPC BPA 488 Amazon Virtual Private Cloud AWS CLI User Guide 1. Create a network path using the ID of the Internet Gateway you want to block traffic from (source) and the ID of the instance you want to block traffic to (destination): aws ec2 --region us-east-2 create-network-insights-path --source igw-id -- destination instance-id --protocol TCP 2. Start an analysis on the network path: aws ec2 --region us-east-2 start-network-insights-analysis --network-insights- path-id nip-id 3. Retrieve the results of the analysis: aws ec2 --region us-east-2 describe-network-insights-analyses --network- insights-analysis-ids nia-id 4. Verify that VPC_BLOCK_PUBLIC_ACCESS_ENABLED is the ExplanationCode for the lack of reachability. Advanced example This section contains an advanced example that will help you understand how VPC Block Public Access feature works in different scenarios. Each scenario builds off the scenario before it, so it's important to complete the steps in order. Important Do not go through this example in a production account. We strongly recommend that you thoroughly review the workloads that require Internet access prior to enabling VPC BPA in your production accounts. Note To fully understand the VPC BPA feature, you'll need certain resources in your account. In this section, we provide an AWS CloudFormation template that you can use to provision the resources you need to fully understand how this feature works. There are costs associated Advanced example 489 Amazon Virtual Private Cloud User Guide with the resources you provision with the CloudFormation template and the analyses you perform with Network Access Analyzer and Reachability Analyzer. If you use the template in this section, ensure that you complete the Cleanup steps when you're done with this example. Contents • Deploy CloudFormation template (optional) • View the impact of VPC BPA with Network Access Analyzer • Scenario 1 - Connect to instances without VPC BPA turned on • Scenario 2 - Turn
vpc-ug-178
vpc-ug.pdf
178
the resources you need to fully understand how this feature works. There are costs associated Advanced example 489 Amazon Virtual Private Cloud User Guide with the resources you provision with the CloudFormation template and the analyses you perform with Network Access Analyzer and Reachability Analyzer. If you use the template in this section, ensure that you complete the Cleanup steps when you're done with this example. Contents • Deploy CloudFormation template (optional) • View the impact of VPC BPA with Network Access Analyzer • Scenario 1 - Connect to instances without VPC BPA turned on • Scenario 2 - Turn on VPC BPA in Bidirectional mode • Scenario 3 - Change VPC BPA to Ingress-only mode • Scenario 4 - Create an exclusion • Scenario 5 - Modify exclusion mode • Scenario 6 - Modify VPC BPA mode • Cleanup Deploy CloudFormation template (optional) To demonstrate how this feature works, you need a VPC, subnets, instances, and other resources. To make it easier to complete this demonstration, we’ve provided an AWS CloudFormation template below that you can use to quickly spin up the resources required for the scenarios in this demo. This step is optional and you may want to just view the diagrams in the Scenarios in this section. Note • There are costs associated with the resources you create in this section with the CloudFormation template, such as the cost of the NAT gateway and public IPv4 addresses. To avoid excess costs, ensure that you complete the Cleanup steps to remove all resources created for the purpose of this example. • This CloudFormation template creates the underlying resources needed for VPC BPA but does not enable the VPC BPA feature itself. The resources deployed here are intended Advanced example 490 Amazon Virtual Private Cloud User Guide to help you understand and test VPC BPA functionality once you choose to enable it separately. The template creates the following resources in your account: • Egress-only internet gateway • Internet gateway • NAT gateway • Two public subnets • One private subnet • Two EC2 instances with public and private IPv4 addresses • One EC2 instance with an IPv6 address and a private IPv4 address • One EC2 instance with a private IPv4 address only • Security group with SSH and ICMP inbound traffic allowed and ALL outbound traffic allowed • VPC flow log • One EC2 Instance Connect endpoint in Subnet B Copy the template below and save it to a .yaml file. AWSTemplateFormatVersion: '2010-09-09' Description: Creates a VPC with public and private subnets, NAT gateway, and EC2 instances for VPC BPA. Parameters: InstanceAMI: Description: ID of the Amazone Machine Image (AMI) to use with the instances launched by this template Type: AWS::EC2::Image::Id InstanceType: Description: EC2 Instance type to use with the instances launched by this template Type: String Default: t2.micro Resources: # VPC VPCBPA: Advanced example 491 Amazon Virtual Private Cloud User Guide Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsHostnames: true EnableDnsSupport: true InstanceTenancy: default Tags: - Key: Name Value: VPC BPA # VPC IPv6 CIDR VPCBPAIpv6CidrBlock: Type: AWS::EC2::VPCCidrBlock Properties: VpcId: !Ref VPCBPA AmazonProvidedIpv6CidrBlock: true # EC2 Key Pair VPCBPAKeyPair: Type: AWS::EC2::KeyPair Properties: KeyName: vpc-bpa-key # Internet Gateway VPCBPAInternetGateway: Type: AWS::EC2::InternetGateway Properties: Tags: - Key: Name Value: VPC BPA Internet Gateway VPCBPAInternetGatewayAttachment: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref VPCBPA InternetGatewayId: !Ref VPCBPAInternetGateway # Egress-Only Internet Gateway VPCBPAEgressOnlyInternetGateway: Type: AWS::EC2::EgressOnlyInternetGateway Properties: VpcId: !Ref VPCBPA # Subnets Advanced example 492 Amazon Virtual Private Cloud User Guide VPCBPAPublicSubnetA: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPCBPA CidrBlock: 10.0.1.0/24 MapPublicIpOnLaunch: true Tags: - Key: Name Value: VPC BPA Public Subnet A VPCBPAPublicSubnetB: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPCBPA CidrBlock: 10.0.2.0/24 MapPublicIpOnLaunch: true Tags: - Key: Name Value: VPC BPA Public Subnet B VPCBPAPrivateSubnetC: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPCBPA CidrBlock: 10.0.3.0/24 MapPublicIpOnLaunch: false Ipv6CidrBlock: !Select [0, !GetAtt VPCBPA.Ipv6CidrBlocks] AssignIpv6AddressOnCreation: true Tags: - Key: Name Value: VPC BPA Private Subnet C # NAT Gateway VPCBPANATGateway: Type: AWS::EC2::NatGateway Properties: AllocationId: !GetAtt VPCBPANATGatewayEIP.AllocationId SubnetId: !Ref VPCBPAPublicSubnetB Tags: - Key: Name Value: VPC BPA NAT Gateway VPCBPANATGatewayEIP: Type: AWS::EC2::EIP Advanced example 493 User Guide Amazon Virtual Private Cloud Properties: Domain: vpc Tags: - Key: Name Value: VPC BPA NAT Gateway EIP # Route Tables VPCBPAPublicRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPCBPA Tags: - Key: Name Value: VPC BPA Public Route Table VPCBPAPublicRoute: Type: AWS::EC2::Route DependsOn: VPCBPAInternetGatewayAttachment Properties: RouteTableId: !Ref VPCBPAPublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref VPCBPAInternetGateway VPCBPAPublicSubnetARouteTableAssoc: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref VPCBPAPublicSubnetA RouteTableId: !Ref VPCBPAPublicRouteTable VPCBPAPublicSubnetBRouteTableAssoc: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref VPCBPAPublicSubnetB RouteTableId: !Ref VPCBPAPublicRouteTable VPCBPAPrivateRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPCBPA Tags: - Key: Name Value: VPC BPA Private Route Table VPCBPAPrivateRoute: Advanced example 494 User Guide Amazon Virtual Private Cloud Type: AWS::EC2::Route Properties: RouteTableId: !Ref VPCBPAPrivateRouteTable DestinationCidrBlock: 0.0.0.0/0 NatGatewayId: !Ref VPCBPANATGateway VPCBPAPrivateSubnetCRoute: Type: AWS::EC2::Route Properties: RouteTableId: !Ref VPCBPAPrivateRouteTable DestinationIpv6CidrBlock: ::/0 EgressOnlyInternetGatewayId: !Ref VPCBPAEgressOnlyInternetGateway VPCBPAPrivateSubnetCRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref
vpc-ug-179
vpc-ug.pdf
179
Tags: - Key: Name Value: VPC BPA Public Route Table VPCBPAPublicRoute: Type: AWS::EC2::Route DependsOn: VPCBPAInternetGatewayAttachment Properties: RouteTableId: !Ref VPCBPAPublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref VPCBPAInternetGateway VPCBPAPublicSubnetARouteTableAssoc: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref VPCBPAPublicSubnetA RouteTableId: !Ref VPCBPAPublicRouteTable VPCBPAPublicSubnetBRouteTableAssoc: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref VPCBPAPublicSubnetB RouteTableId: !Ref VPCBPAPublicRouteTable VPCBPAPrivateRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPCBPA Tags: - Key: Name Value: VPC BPA Private Route Table VPCBPAPrivateRoute: Advanced example 494 User Guide Amazon Virtual Private Cloud Type: AWS::EC2::Route Properties: RouteTableId: !Ref VPCBPAPrivateRouteTable DestinationCidrBlock: 0.0.0.0/0 NatGatewayId: !Ref VPCBPANATGateway VPCBPAPrivateSubnetCRoute: Type: AWS::EC2::Route Properties: RouteTableId: !Ref VPCBPAPrivateRouteTable DestinationIpv6CidrBlock: ::/0 EgressOnlyInternetGatewayId: !Ref VPCBPAEgressOnlyInternetGateway VPCBPAPrivateSubnetCRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref VPCBPAPrivateSubnetC RouteTableId: !Ref VPCBPAPrivateRouteTable # EC2 Instances Security Group VPCBPAInstancesSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupName: VPC BPA Instances Security Group GroupDescription: Allow SSH and ICMP access SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 - IpProtocol: icmp FromPort: -1 ToPort: -1 CidrIp: 0.0.0.0/0 VpcId: !Ref VPCBPA Tags: - Key: Name Value: VPC BPA Instances Security Group # EC2 Instances VPCBPAInstanceA: Type: AWS::EC2::Instance Properties: ImageId: !Ref InstanceAMI Advanced example 495 Amazon Virtual Private Cloud User Guide InstanceType: t2.micro KeyName: !Ref VPCBPAKeyPair SubnetId: !Ref VPCBPAPublicSubnetA SecurityGroupIds: - !Ref VPCBPAInstancesSecurityGroup Tags: - Key: Name Value: VPC BPA Instance A VPCBPAInstanceB: Type: AWS::EC2::Instance Properties: ImageId: !Ref InstanceAMI InstanceType: !Ref InstanceType KeyName: !Ref VPCBPAKeyPair SubnetId: !Ref VPCBPAPublicSubnetB SecurityGroupIds: - !Ref VPCBPAInstancesSecurityGroup Tags: - Key: Name Value: VPC BPA Instance B VPCBPAInstanceC: Type: AWS::EC2::Instance Properties: ImageId: !Ref InstanceAMI InstanceType: !Ref InstanceType KeyName: !Ref VPCBPAKeyPair SubnetId: !Ref VPCBPAPrivateSubnetC SecurityGroupIds: - !Ref VPCBPAInstancesSecurityGroup Tags: - Key: Name Value: VPC BPA Instance C VPCBPAInstanceD: Type: AWS::EC2::Instance Properties: ImageId: !Ref InstanceAMI InstanceType: !Ref InstanceType KeyName: !Ref VPCBPAKeyPair NetworkInterfaces: - DeviceIndex: '0' GroupSet: Advanced example 496 Amazon Virtual Private Cloud User Guide - !Ref VPCBPAInstancesSecurityGroup SubnetId: !Ref VPCBPAPrivateSubnetC Ipv6AddressCount: 1 Tags: - Key: Name Value: VPC BPA Instance D # Flow Logs IAM Role VPCBPAFlowLogRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: vpc-flow-logs.amazonaws.com Action: 'sts:AssumeRole' Tags: - Key: Name Value: VPC BPA Flow Logs Role VPCBPAFlowLogPolicy: Type: AWS::IAM::Policy Properties: PolicyName: VPC-BPA-FlowLogsPolicy PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - 'logs:CreateLogGroup' - 'logs:CreateLogStream' - 'logs:PutLogEvents' - 'logs:DescribeLogGroups' - 'logs:DescribeLogStreams' Resource: '*' Roles: - !Ref VPCBPAFlowLogRole # Flow Logs VPCBPAFlowLog: Type: AWS::EC2::FlowLog Properties: Advanced example 497 Amazon Virtual Private Cloud User Guide ResourceId: !Ref VPCBPA ResourceType: VPC TrafficType: ALL LogDestinationType: cloud-watch-logs LogGroupName: /aws/vpc-flow-logs/VPC-BPA DeliverLogsPermissionArn: !GetAtt VPCBPAFlowLogRole.Arn LogFormat: '${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log- status} ${vpc-id} ${subnet-id} ${instance-id} ${tcp-flags} ${type} ${pkt-srcaddr} ${pkt-dstaddr} ${region} ${az-id} ${sublocation-type} ${sublocation-id} ${pkt-src-aws- service} ${pkt-dst-aws-service} ${flow-direction} ${traffic-path} ${reject-reason}' Tags: - Key: Name Value: VPC BPA Flow Logs # EC2 Instance Connect Endpoint VPCBPAEC2InstanceConnectEndpoint: Type: AWS::EC2::InstanceConnectEndpoint Properties: SecurityGroupIds: - !Ref VPCBPAInstancesSecurityGroup SubnetId: !Ref VPCBPAPublicSubnetB Outputs: VPCBPAVPCId: Description: A reference to the created VPC Value: !Ref VPCBPA Export: Name: vpc-id VPCBPAPublicSubnetAId: Description: The ID of the public subnet A Value: !Ref VPCBPAPublicSubnetA VPCBPAPublicSubnetAName: Description: The name of the public subnet A Value: VPC BPA Public Subnet A VPCBPAPublicSubnetBId: Description: The ID of the public subnet B Value: !Ref VPCBPAPublicSubnetB VPCBPAPublicSubnetBName: Description: The name of the public subnet B Advanced example 498 Amazon Virtual Private Cloud User Guide Value: VPC BPA Public Subnet B VPCBPAPrivateSubnetCId: Description: The ID of the private subnet C Value: !Ref VPCBPAPrivateSubnetC VPCBPAPrivateSubnetCName: Description: The name of the private subnet C Value: VPC BPA Private Subnet C VPCBPAInstanceAId: Description: The ID of instance A Value: !Ref VPCBPAInstanceA VPCBPAInstanceBId: Description: The ID of instance B Value: !Ref VPCBPAInstanceB VPCBPAInstanceCId: Description: The ID of instance C Value: !Ref VPCBPAInstanceC VPCBPAInstanceDId: Description: The ID of instance D Value: !Ref VPCBPAInstanceD AWS Management Console 1. Open the AWS CloudFormation console at https://console.aws.amazon.com/ cloudformation/. 2. Choose Create stack and upload the .yaml template file. 3. Go through the steps to launch the template. You'll need to enter an image ID and an instance type (like t2.micro). You'll also need to allow CloudFormation to create an IAM role for you for the flow log creation and permission to log to Amazon CloudWatch. 4. Once you launch the stack, view the Events tab to view progress and ensure that the stack completes before you continue. AWS CLI 1. Run the following command to create the CloudFormation stack: Advanced example 499 Amazon Virtual Private Cloud User Guide aws cloudformation create-stack --stack-name VPC-BPA-stack --template-body file://sampletemplate.yaml --capabilities CAPABILITY_IAM --region us-east-2 Output: { "StackId": "arn:aws:cloudformation:us-east-2:470889052923:stack/VPC-BPA- stack/8a7a2cc0-8001-11ef-b196-06386a84b72f" } 2. View the progress and ensure that the stack completes before you continue: aws cloudformation describe-stack-events --stack-name VPC-BPA-stack --region us- east-2 View the impact of VPC BPA with Network Access Analyzer In this section, you'll use Network Access Analyzer to view the resources in your account that use the internet gateway. Use this analysis to understand the impact of turning on VPC BPA in your account and blocking traffic. For information about the regional availability of Network Access
vpc-ug-180
vpc-ug.pdf
180
Virtual Private Cloud User Guide aws cloudformation create-stack --stack-name VPC-BPA-stack --template-body file://sampletemplate.yaml --capabilities CAPABILITY_IAM --region us-east-2 Output: { "StackId": "arn:aws:cloudformation:us-east-2:470889052923:stack/VPC-BPA- stack/8a7a2cc0-8001-11ef-b196-06386a84b72f" } 2. View the progress and ensure that the stack completes before you continue: aws cloudformation describe-stack-events --stack-name VPC-BPA-stack --region us- east-2 View the impact of VPC BPA with Network Access Analyzer In this section, you'll use Network Access Analyzer to view the resources in your account that use the internet gateway. Use this analysis to understand the impact of turning on VPC BPA in your account and blocking traffic. For information about the regional availability of Network Access Analyzer, see Limitations in the Network Access Analyzer Guide. AWS Management Console 1. Open the AWS Network Insights console at https://console.aws.amazon.com/ networkinsights/. 2. Choose Network Access Analyzer. 3. Choose Create Network Access Scope. 4. Choose Assess impact of VPC Block Public Access and choose Next. 5. The template is already configured to analyze traffic to and from the internet gateways in your account. You can view this under Source and Destination. 6. Choose Next. 7. Choose Create Network Access Scope. 8. Choose the scope you just created and choose Analyze. Advanced example 500 Amazon Virtual Private Cloud User Guide 9. Wait for the analysis to complete. 10. View the findings of the analysis. Each row under Findings shows a network path that a packet can take in a network to or from an internet gateway in your account. In this case, if you turn on VPC BPA and none of the VPCs and or subnets that appear in these findings are configured as VPC BPA exclusions, traffic to those VPCs and subnets will be restricted. 11. Analyze each finding to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. AWS CLI 1. Create a network access scope: aws ec2 create-network-insights-access-scope --match-paths "Source={ResourceStatement={ResourceTypes=["AWS::EC2::InternetGateway"]}}" "Destination={ResourceStatement={ResourceTypes=["AWS::EC2::InternetGateway"]}}" --region us-east-2 Output: { "NetworkInsightsAccessScope": { "NetworkInsightsAccessScopeId": "nis-04cad3c4b3a1d5e3e", "NetworkInsightsAccessScopeArn": "arn:aws:ec2:us- east-2:470889052923:network-insights-access-scope/nis-04cad3c4b3a1d5e3e", "CreatedDate": "2024-09-30T15:55:53.171000+00:00", "UpdatedDate": "2024-09-30T15:55:53.171000+00:00" }, "NetworkInsightsAccessScopeContent": { "NetworkInsightsAccessScopeId": "nis-04cad3c4b3a1d5e3e", "MatchPaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } }, { Advanced example 501 Amazon Virtual Private Cloud User Guide "Destination": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] } } 2. Start the scope analysis: aws ec2 start-network-insights-access-scope-analysis --network-insights-access- scope-id nis-04cad3c4b3a1d5e3e --region us-east-2 Output: { "NetworkInsightsAccessScopeAnalysis": { "NetworkInsightsAccessScopeAnalysisId": "nisa-0aa383a1938f94cd1", "NetworkInsightsAccessScopeAnalysisArn": "arn:aws:ec2:us- east-2:470889052923:network-insights-access-scope-analysis/ nisa-0aa383a1938f94cd", "NetworkInsightsAccessScopeId": "nis-04cad3c4b3a1d5e3e", "Status": "running", "StartDate": "2024-09-30T15:56:59.109000+00:00", "AnalyzedEniCount": 0 } } 3. Get the results of the analysis: aws ec2 get-network-insights-access-scope-analysis-findings --network-insights- access-scope-analysis-id nisa-0aa383a1938f94cd1 --region us-east-2 --max-items 1 Output: { "AnalysisFindings": [ { Advanced example 502 Amazon Virtual Private Cloud User Guide "NetworkInsightsAccessScopeAnalysisId": "nisa-0aa383a1938f94cd1", "NetworkInsightsAccessScopeId": "nis-04cad3c4b3a1d5e3e", "FindingId": "AnalysisFinding-1", "FindingComponents": [ { "SequenceNumber": 1, "Component": { "Id": "igw-04a5344b4e30486f1", "Arn": "arn:aws:ec2:us-east-2:470889052923:internet-gateway/ igw-04a5344b4e30486f1", "Name": "VPC BPA Internet Gateway" }, "OutboundHeader": { "DestinationAddresses": [ "10.0.1.85/32" ] }, "InboundHeader": { "DestinationAddresses": [ "10.0.1.85/32" ], "DestinationPortRanges": [ { "From": 22, "To": 22 } ], "Protocol": "6", "SourceAddresses": [ "0.0.0.0/5", "100.0.0.0/10", "96.0.0.0/6" ], "SourcePortRanges": [ { "From": 0, "To": 65535 } ] }, "Vpc": { "Id": "vpc-0762547ec48b6888d", "Arn": "arn:aws:ec2:us-east-2:470889052923:vpc/ vpc-0762547ec48b6888d", Advanced example 503 Amazon Virtual Private Cloud User Guide "Name": "VPC BPA" } }, { "SequenceNumber": 2, "AclRule": { "Cidr": "0.0.0.0/0", "Egress": false, "Protocol": "all", "RuleAction": "allow", "RuleNumber": 100 }, "Component": { "Id": "acl-06194fc3a4a03040b", "Arn": "arn:aws:ec2:us-east-2:470889052923:network-acl/ acl-06194fc3a4a03040b" } }, { "SequenceNumber": 3, "Component": { "Id": "sg-093dde06415d03924", "Arn": "arn:aws:ec2:us-east-2:470889052923:security-group/ sg-093dde06415d03924", "Name": "VPC BPA Instances Security Group" }, "SecurityGroupRule": { "Cidr": "0.0.0.0/0", "Direction": "ingress", "PortRange": { "From": 22, "To": 22 }, "Protocol": "tcp" } }, { "SequenceNumber": 4, "AttachedTo": { "Id": "i-058db34f9a0997895", "Arn": "arn:aws:ec2:us-east-2:470889052923:instance/ i-058db34f9a0997895", "Name": "VPC BPA Instance A" }, Advanced example 504 Amazon Virtual Private Cloud User Guide "Component": { "Id": "eni-0fa23f2766f03b286", "Arn": "arn:aws:ec2:us-east-2:470889052923:network-interface/ eni-0fa23f2766f03b286" }, "InboundHeader": { "DestinationAddresses": [ "10.0.1.85/32" ], "DestinationPortRanges": [ { "From": 22, "To": 22 } ], "Protocol": "6", "SourceAddresses": [ "0.0.0.0/5", "100.0.0.0/10", "96.0.0.0/6" ], "SourcePortRanges": [ { "From": 0, "To": 65535 } ] }, "Subnet": { "Id": "subnet-035d235a762eeed04", "Arn": "arn:aws:ec2:us-east-2:470889052923:subnet/ subnet-035d235a762eeed04", "Name": "VPC BPA Public Subnet A" }, "Vpc": { "Id": "vpc-0762547ec48b6888d", "Arn": "arn:aws:ec2:us-east-2:470889052923:vpc/ vpc-0762547ec48b6888d", "Name": "VPC BPA" } } ] } ], Advanced example 505 Amazon Virtual Private Cloud User Guide "AnalysisStatus": "succeeded", "NetworkInsightsAccessScopeAnalysisId": "nisa-0aa383a1938f94cd1", "NextToken": "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxfQ==" } The results show the traffic to and from the internet gateways in all the VPCs in your account. The results are organized as "findings". "FindingId": "AnalysisFinding-1" indicates that this is the first finding in the analysis. Note that there are multiple findings and each indicates a traffic flow that will be impacted by turning on VPC BPA. The first finding will show that traffic started at an internet gateway ("SequenceNumber": 1), passed to an NACL ("SequenceNumber": 2) to a security group ("SequenceNumber": 3) and ended at an instance ("SequenceNumber": 4). 4. Analyze the findings to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. Scenario 1
vpc-ug-181
vpc-ug.pdf
181
the VPCs in your account. The results are organized as "findings". "FindingId": "AnalysisFinding-1" indicates that this is the first finding in the analysis. Note that there are multiple findings and each indicates a traffic flow that will be impacted by turning on VPC BPA. The first finding will show that traffic started at an internet gateway ("SequenceNumber": 1), passed to an NACL ("SequenceNumber": 2) to a security group ("SequenceNumber": 3) and ended at an instance ("SequenceNumber": 4). 4. Analyze the findings to understand the impact of VPC BPA on resources in your VPCs. The impact analysis is complete. Scenario 1 - Connect to instances without VPC BPA turned on In this section, EC2 instances in public subnets A and B are reachable from the internet via the Internet Gateway, which allows both inbound and outbound traffic. Instances C and D in the private subnet can initiate outbound traffic through the NAT Gateway or Egress-Only Internet Gateway, but are not directly reachable from the internet. This setup provides internet access to some resources while protecting others. The purpose of this setup is to set a baseline and ensure that, before you enable VPC BPA, all instances can be reached, you'll connect to all instances and ping a public IP address. Diagram of a VPC without VPC BPA turned on: Advanced example 506 Amazon Virtual Private Cloud User Guide 1.1 Connect to instances Complete this section to connect to your instances with VPC BPA turned off to ensure you can connect without issue. All of the instances created with the CloudFormation for this example have names like, "VPC BPA Instance A". AWS Management Console 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. 2. Open the Instance A details. Advanced example 507 Amazon Virtual Private Cloud User Guide 3. Connect to instance A using the EC2 Instance Connect > Connect using EC2 Instance Connect Endpoint option. 4. Choose Connect. Once you successfully connect to the instance, ping www.amazon.com to verify you can send outbound requests to the internet. 5. Use the same method you used to connect to instance A to connect to instances B, C, and D. From each instance, ping www.amazon.com to verify you can send outbound requests to the internet. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Reply from 18.225.8.244: bytes=32 time=51ms TTL=110 Reply from 18.225.8.244: bytes=32 time=61ms TTL=110 Note that the ping is successful and traffic is not blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~_ ####_ Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ / / Advanced example 508 Amazon Virtual Private Cloud /m/' User Guide Last login: Fri Sep 27 18:27:57 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING www-amazon-com.customer.fastly.net (18.65.233.187) 56(84) bytes of data. 64 bytes from 18.65.233.187 (18.65.233.187): icmp_seq=15 ttl=58 time=2.06 ms 64 bytes from 18.65.233.187 (18.65.233.187): icmp_seq=16 ttl=58 time=2.26 ms Note that the ping is successful and traffic is not blocked. 3. Ping Instance B using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Output: Pinging 3.18.106.198 with 32 bytes of data: Reply from 3.18.106.198: bytes=32 time=83ms TTL=110 Reply from 3.18.106.198: bytes=32 time=54ms TTL=110 Note that the ping is successful and traffic is not blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-08552a0774b5c8f72 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ / / /m/' Last login: Fri Sep 27 18:12:27 2024 from 3.16.146.5 [ec2-user@ip-10-0-2-98 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Advanced example 509 Amazon Virtual Private Cloud User Guide 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=249 time=1.55 ms 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=249 time=1.67 ms Note that the ping is successful and traffic is not blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ /
vpc-ug-182
vpc-ug.pdf
182
(18.65.233.187): icmp_seq=2 ttl=249 time=1.67 ms Note that the ping is successful and traffic is not blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ / / /m/' Last login: Thu Sep 19 20:31:26 2024 from 10.0.2.86 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=248 time=1.75 ms 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=248 time=1.97 ms 64 bytes from server-3-160-24-26.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=3 ttl=248 time=1.08 ms Note that the ping is successful and traffic is not blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: Advanced example 510 Amazon Virtual Private Cloud User Guide aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.3.59 can't be established. ECDSA key fingerprint is SHA256:c4naBCqbC61/cExDyccEproNU+1HHSpMSzl2J6cOtIZA8g. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.3.59' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ _/ _/ _/m/' [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:ee00:7:49a5:5fd4:b121 (2600:9000:25f3:ee00:7:49a5:5fd4:b121)) 56 data bytes 64 bytes from 2600:9000:25f3:ee00:7:49a5:5fd4:b121 (2600:9000:25f3:ee00:7:49a5:5fd4:b121): icmp_seq=1 ttl=58 time=1.19 ms 64 bytes from 2600:9000:25f3:ee00:7:49a5:5fd4:b121 (2600:9000:25f3:ee00:7:49a5:5fd4:b121): icmp_seq=2 ttl=58 time=1.38 ms Note that the ping is successful and traffic is not blocked. Scenario 2 - Turn on VPC BPA in Bidirectional mode In this section you'll turn on VPC BPA and block traffic to and from the internet gateways in your account. Diagram showing VPC BPA Bidirectional mode turned on: Advanced example 511 Amazon Virtual Private Cloud User Guide 2.1 Enable VPC BPA bidirectional mode Complete this section to enable VPC BPA. VPC BPA bidirectional mode blocks all traffic to and from internet gateways and egress-only internet gateways in this Region (except for excluded VPCs and subnets). AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. Choose Edit public access settings. Advanced example 512 Amazon Virtual Private Cloud User Guide 4. Choose Turn on block public access and Bidirectional, then choose Save changes. 5. Wait for the Status to change to On. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. VPC BPA is now on. AWS CLI 1. Use the modify-vpc-block-public-access-options command to turn on VPC BPA: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-bidirectional It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. View the status of VPC BPA: aws ec2 --region us-east-2 describe-vpc-block-public-access-options 2.2 Connect to instances Complete this section to connect to your instances. AWS Management Console 1. Ping the public IPv4 address of Instance A and Instance B as you did in Scenario 1. Note that traffic is blocked. 2. Connect to instance A using the EC2 Instance Connect > Connect using EC2 Instance Connect Endpoint option as you did in Scenario 1. Make sure you use the endpoint option. 3. Choose Connect. Once you successfully connect to the instance, ping www.amazon.com. Note that all outbound traffic is blocked. 4. Use the same method you used to connect to instance A to connect to instances B, C, and D, test outbound requests to the internet. Note that all outbound traffic is blocked. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: Advanced example 513 Amazon Virtual Private Cloud User Guide ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.1.85' can't be established. ECDSA key fingerprint is SHA256:3zo/gSss+HAZ+7eTyWlOB/Ke04IM+hadjsoLJeRTWBk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.1.85' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~_ ####_ Amazon Linux
vpc-ug-183
vpc-ug.pdf
183
with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.1.85' can't be established. ECDSA key fingerprint is SHA256:3zo/gSss+HAZ+7eTyWlOB/Ke04IM+hadjsoLJeRTWBk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.1.85' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~_ ####_ Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ / / /m/' Last login: Fri Sep 27 14:16:53 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 3. Ping Instance B using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Advanced example 514 Amazon Virtual Private Cloud Output: User Guide Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-08552a0774b5c8f72 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.2.98' can't be established. ECDSA key fingerprint is SHA256:0IjXKKyVlDthcCfI0IPIJMUiItAOLYKRNLGTYURnFXo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.2.98' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ / / /m/' Last login: Fri Sep 27 14:18:16 2024 from 3.16.146.5 [ec2-user@ip-10-0-2-98 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: Advanced example 515 Amazon Virtual Private Cloud User Guide A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ / / /m/' Last login: Tue Sep 24 15:17:56 2024 from 10.0.2.86 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ _/ _/ _/m/' Last login: Fri Sep 27 16:42:01 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:8200:7:49a5:5fd4:b121 (2600:9000:25f3:8200:7:49a5:5fd4:b121)) 56 data bytes Note that the ping fails and traffic is blocked. Advanced example 516 Amazon Virtual Private Cloud User Guide 2.3 Optional: Verify connectivity is blocked with Reachability Analyzer VPC Reachability Analyzer can be used to understand whether or not certain network paths can be reached given your network configuration, including VPC BPA settings. In this example you will analyze the same network path that was attempted earlier to confirm that VPC BPA is the reason why connectivity is failing. AWS Management Console 1. Go to the Network Insights console at https://console.aws.amazon.com/networkinsights/ home#ReachabilityAnalyzer. 2. Click Create and analyze path. 3. 4. For the Source Type, choose Internet Gateways and select the internet gateway tagged VPC BPA Internet Gateway from the Source dropdown. For the Destination Type, choose Instances and select the instance tagged with VPC BPA Instance A from the Destination dropdown. 5. Click Create and analyze path. 6. Wait for the analysis to complete. It could take a few minutes. 7. Once complete, you should see that the Reachability Statusis Not reachable and that the Path details shows that VPC_BLOCK_PUBLIC_ACCESS_ENABLED is the cause. AWS CLI 1. Create a network path using the ID of the internet gateway tagged VPC BPA Internet Gateway and the ID of the instance tagged VPC BPA Instance A: aws ec2 --region us-east-2 create-network-insights-path --source igw-id -- destination instance-id --protocol TCP 2. Start an analysis on the network path: aws ec2 --region us-east-2 start-network-insights-analysis --network-insights- path-id nip-id 3. Retrieve
vpc-ug-184
vpc-ug.pdf
184
Create and analyze path. 6. Wait for the analysis to complete. It could take a few minutes. 7. Once complete, you should see that the Reachability Statusis Not reachable and that the Path details shows that VPC_BLOCK_PUBLIC_ACCESS_ENABLED is the cause. AWS CLI 1. Create a network path using the ID of the internet gateway tagged VPC BPA Internet Gateway and the ID of the instance tagged VPC BPA Instance A: aws ec2 --region us-east-2 create-network-insights-path --source igw-id -- destination instance-id --protocol TCP 2. Start an analysis on the network path: aws ec2 --region us-east-2 start-network-insights-analysis --network-insights- path-id nip-id 3. Retrieve the results of the analysis: aws ec2 --region us-east-2 describe-network-insights-analyses --network- insights-analysis-ids nia-id Advanced example 517 Amazon Virtual Private Cloud User Guide 4. Verify that VPC_BLOCK_PUBLIC_ACCESS_ENABLED is the ExplanationCode for the lack of reachability. Note that you can also Monitor VPC BPA impact with flow logs. Scenario 3 - Change VPC BPA to Ingress-only mode In this section you'll change the VPC BPA traffic direction and allow only traffic that uses a NAT gateway or egress-only internet gateway. EC2 instances A and B in the public subnets will be unreachable from the internet because BPA blocks inbound traffic through the Internet Gateway. Instances C and D in the private subnet will remain able to initiate outbound traffic via the NAT gateway and Egress-Only Internet Gateway, and therefore can still reach the internet. Diagram of VPC BPA Ingress-only mode turned on: Advanced example 518 Amazon Virtual Private Cloud User Guide 3.1 Change mode to ingress-only Complete this section to change the mode. AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. In the Block public access tab, choose Edit public access settings. Advanced example 519 Amazon Virtual Private Cloud User Guide 4. Modify the public access settings in the VPC console and change the direction to Ingress- only. 5. Save the changes and wait for the status to be updated. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. AWS CLI 1. Modify the VPC BPA mode: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-ingress It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. View the status of VPC BPA: aws ec2 --region us-east-2 describe-vpc-block-public-access-options 3.2 Connect to instances Complete this section to connect to the instances. AWS Management Console 1. Ping the public IPv4 address of Instance A and Instance B as you did in Scenario 1. Note that traffic is blocked. 2. Connect to Instance A and B using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you cannot ping a public site on the internet from Instance A or B and traffic is blocked. 3. Connect to Instance C and D using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you can ping a public site on the internet from Instance C or D and traffic is allowed. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: Advanced example 520 Amazon Virtual Private Cloud User Guide ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.1.85' can't be established. ECDSA key fingerprint is SHA256:3zo/gSss+HAZ+7eTyWlOB/Ke04IM+hadjsoLJeRTWBk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.1.85' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~_ ####_ Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ / / /m/' Last login: Fri Sep 27 14:16:53 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 3. Ping Instance B using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Advanced example 521 Amazon Virtual Private Cloud Output: User Guide Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-08552a0774b5c8f72 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.2.98 ' can't be established. ECDSA key fingerprint is SHA256:0IjXKKyVlDthcCfI0IPIJMUiItAOLYKRNLGTYURnFXo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.2.98' (ECDSA) to the list of known hosts. A newer release
vpc-ug-185
vpc-ug.pdf
185
the public IPv4 address to check inbound traffic: ping 3.18.106.198 Advanced example 521 Amazon Virtual Private Cloud Output: User Guide Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-08552a0774b5c8f72 --region us- east-2 --connection-type eice Output: The authenticity of host '10.0.2.98 ' can't be established. ECDSA key fingerprint is SHA256:0IjXKKyVlDthcCfI0IPIJMUiItAOLYKRNLGTYURnFXo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.2.98' (ECDSA) to the list of known hosts. A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ _/ / /m/' Last login: Fri Sep 27 14:18:16 2024 from 3.16.146.5 [ec2-user@ip-10-0-2-98 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: Advanced example 522 Amazon Virtual Private Cloud User Guide A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Tue Sep 24 15:28:09 2024 from 10.0.2.86 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=248 time=1.84 ms 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=248 time=1.40 ms Note that the ping is successful and traffic is not blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ Advanced example 523 Amazon Virtual Private Cloud _/m/' User Guide Last login: Fri Sep 27 16:48:38 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:5800:7:49a5:5fd4:b121 (2600:9000:25f3:5800:7:49a5:5fd4:b121)) 56 data bytes 64 bytes from 2600:9000:25f3:5800:7:49a5:5fd4:b121 (2600:9000:25f3:5800:7:49a5:5fd4:b121): icmp_seq=14 ttl=58 time=1.47 ms 64 bytes from 2600:9000:25f3:5800:7:49a5:5fd4:b121 (2600:9000:25f3:5800:7:49a5:5fd4:b121): icmp_seq=16 ttl=58 time=1.59 ms Note that the ping is successful and traffic is not blocked. Scenario 4 - Create an exclusion In this section, you'll create an exclusion. VPC BPA will then only block traffic on the subnets without an exclusion. A VPC BPA exclusion is a mode that can be applied to a single VPC or subnet that exempts it from the account’s VPC BPA mode and will allow bidirectional or egress-only access. You can create VPC BPA exclusions for VPCs and subnets even when VPC BPA is not enabled on the account to ensure that there is no traffic disruption to the exclusions when VPC BPA is turned on. In this example, we'll create an exclusion for Subnet A to show how traffic to exclusions is impacted by VPC BPA. Diagram of VPC BPA Ingress-only mode turned on and Subnet A exclusion with Bidirectional mode turned on: Advanced example 524 Amazon Virtual Private Cloud User Guide 4.1 Create an exclusion for Subnet A Complete this section to create an exclusion. A VPC BPA exclusion is a mode that can be applied to a single VPC or subnet that exempts it from the account’s VPC BPA mode and will allow bidirectional or egress-only access. You can create VPC BPA exclusions for VPCs and subnets even when VPC BPA is not enabled on the account to ensure that there is no traffic disruption to the exclusions when VPC BPA is turned on. AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. Advanced example 525 Amazon Virtual Private Cloud User Guide 2. On the left navigation pane, choose Settings. 3. In the Block public access tab, under Exclusions, choose Create exclusions. 4. Choose VPC BPA Public Subnet A, ensure that allow direction Bidirectional is selected, and choose Create exclusions. 5. Wait for the Exclusion status to change to Active. You may need to refresh the exclusion table to see the change. The exclusion has been created. AWS CLI 1. Modify the exclusion allow direction: aws ec2 --region us-east-2 create-vpc-block-public-access-exclusion --subnet- id subnet-id --internet-gateway-exclusion-mode allow-bidirectional 2. It can take time for
vpc-ug-186
vpc-ug.pdf
186
at https://console.aws.amazon.com/vpc/. Advanced example 525 Amazon Virtual Private Cloud User Guide 2. On the left navigation pane, choose Settings. 3. In the Block public access tab, under Exclusions, choose Create exclusions. 4. Choose VPC BPA Public Subnet A, ensure that allow direction Bidirectional is selected, and choose Create exclusions. 5. Wait for the Exclusion status to change to Active. You may need to refresh the exclusion table to see the change. The exclusion has been created. AWS CLI 1. Modify the exclusion allow direction: aws ec2 --region us-east-2 create-vpc-block-public-access-exclusion --subnet- id subnet-id --internet-gateway-exclusion-mode allow-bidirectional 2. It can take time for the exclusion status to update. To view the status of the exclusion: aws ec2 --region us-east-2 describe-vpc-block-public-access-exclusions -- exclusion-ids exclusion-id 4.2 Connect to instances Complete this section to connect to the instances. AWS Management Console 1. Ping the public IPv4 address of Instance A. Note that traffic is allowed. 2. Ping the public IPv4 address of Instance B. Note that traffic is blocked. 3. Connect to Instance A using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com. Note that you can ping a public site on the internet from Instance A. Traffic is allowed. 4. Connect to Instance B using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from it. Note that you cannot ping a public site on the internet from Instance B. Traffic is blocked. Advanced example 526 Amazon Virtual Private Cloud User Guide 5. Connect to Instance C and D using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you can ping a public site on the internet from Instance C or D. Traffic is allowed. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Reply from 18.225.8.244: bytes=32 time=51ms TTL=110 Reply from 18.225.8.244: bytes=32 time=61ms TTL=110 Note that the ping is successful and traffic is not blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~_ ####_ Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ / / /m/' Last login: Fri Sep 27 17:58:12 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=249 time=1.03 ms Advanced example 527 Amazon Virtual Private Cloud User Guide 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=249 time=1.72 ms Note that the ping is successful and traffic is not blocked. 3. Ping Instance B using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Output: Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-08552a0774b5c8f72 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ _/ / /m/' Last login: Fri Sep 27 18:12:03 2024 from 3.16.146.5 [ec2-user@ip-10-0-2-98 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: Advanced example 528 Amazon Virtual Private Cloud User Guide aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , # ~_ #### Amazon Linux 2023 ~~ _#####\ ~~ ###| ~~ #/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~.. _/ _/ / /m/' Last login: Tue Sep 24 15:28:09 2024 from 10.0.2.86 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=248 time=1.84 ms 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=248 time=1.40 ms Note that the ping is successful and traffic is not blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version
vpc-ug-187
vpc-ug.pdf
187
ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=1 ttl=248 time=1.84 ms 64 bytes from server-3-160-24-126.cmh68.r.cloudfront.net (18.65.233.187): icmp_seq=2 ttl=248 time=1.40 ms Note that the ping is successful and traffic is not blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| Advanced example 529 Amazon Virtual Private Cloud User Guide ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:00:52 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(g2600-141f-4000-059a-0000-0000-0000-3bd4.deploy.static.akamaitechnologies.com (2600:141f:4000:59a::3bd4)) 56 data bytes 64 bytes from g2600-141f-4000-059a-0000-0000-0000-3bd4.deploy.static.akamaitechnologies.com (2600:141f:4000:59a::3bd4): icmp_seq=1 ttl=48 time=15.9 ms 64 bytes from g2600-141f-4000-059a-0000-0000-0000-3bd4.deploy.static.akamaitechnologies.com (2600:141f:4000:59a::3bd4): icmp_seq=2 ttl=48 time=15.8 ms Note that the ping is successful and traffic is not blocked. 4.3 Optional: Verify connectivity with Reachability Analyzer Using the same network path created in Reachability Analyzer in Scenario 2, you can now run a new analysis and confirm that the path is reachable now that an exclusion has been created for Public Subnet A. For information about the regional availability of Reachability Analyzer, see Considerations in the Reachability Analyzer Guide. AWS Management Console 1. From the Network Path you created earlier in the Network Insights console, click Re-run analysis. 2. Wait for the analysis to complete. It may take several minutes. 3. Confirm that the path is now Reachable. AWS CLI 1. Using the network path ID created earlier, start a new analysis: Advanced example 530 Amazon Virtual Private Cloud User Guide aws ec2 --region us-east-2 start-network-insights-analysis --network-insights- path-id nip-id 2. Retrieve the results of the analysis: aws ec2 --region us-east-2 describe-network-insights-analyses --network- insights-analysis-ids nia-id 3. Confirm that the VPC_BLOCK_PUBLIC_ACCESS_ENABLED explanation code is no longer present. Scenario 5 - Modify exclusion mode In this section you'll change the allow traffic direction on the exclusion to see how it impacts VPC BPA. Note In this scenario, you'll change the exclusion mode to Egress-only. Note that when you do this, the Egress-only exclusion on Subnet A doesn't allow outbound traffic, which is counterintuitive because you’d expect it to permit outbound traffic. However, since the account-level BPA is Ingress-only, Egress-only exclusions are ignored, and Subnet A’s routing to an internet gateway is restricted by VPC BPA, blocking outbound traffic. To enable outbound traffic on Subnet A, you'd have to switch VPC BPA to Bidirectional mode. Diagram of VPC BPA Ingress-only mode turned on and Subnet A exclusion with egress-only mode turned on: Advanced example 531 Amazon Virtual Private Cloud User Guide 5.1 Change exclusion allow direction to egress-only Complete this section to change the exclusion allow direction. AWS Management Console 1. Edit the exclusion you created in Scenario 4 and change the allow direction to Egress-only. 2. Choose Save changes. 3. Wait for the Exclusion status to change to Active. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. You may need to refresh the exclusion table to see the change. Advanced example 532 Amazon Virtual Private Cloud AWS CLI 1. Modify the exclusion allow direction: User Guide aws ec2 --region us-east-2 modify-vpc-block-public-access-exclusion --exclusion- id exclusion-id --internet-gateway-exclusion-mode allow-egress It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. It can take time for the exclusion status to update. To view the status of the exclusion: aws ec2 --region us-east-2 describe-vpc-block-public-access-exclusion 5.2 Connect to instances Complete this section to connect to the instances. AWS Management Console 1. Ping the public IPv4 address of Instance A and B. Note that traffic is blocked. 2. Connect to Instance A and B using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com. Note that you cannot ping a public site on the internet from Instance A or B. Traffic is blocked. 3. Connect to Instance C and D using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you can ping a public site on the internet from Instance C or D. Traffic is allowed. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Request timed out. Advanced example 533 Amazon Virtual Private Cloud User Guide Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice
vpc-ug-188
vpc-ug.pdf
188
instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you can ping a public site on the internet from Instance C or D. Traffic is allowed. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: ping 18.225.8.244 Output: Pinging 18.225.8.244 with 32 bytes of data: Request timed out. Advanced example 533 Amazon Virtual Private Cloud User Guide Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:09:55 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 3. Ping Instance B using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Output: Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Advanced example 534 Amazon Virtual Private Cloud Output: User Guide A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:09:55 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:00:31 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:a600:7:49a5:5fd4:b121 (2600:9000:25f3:a600:7:49a5:5fd4:b121)) 56 data bytes Advanced example 535 Amazon Virtual Private Cloud User Guide 64 bytes from 2600:9000:25f3:a600:7:49a5:5fd4:b121 (2600:9000:25f3:a600:7:49a5:5fd4:b121): icmp_seq=1 ttl=58 time=1.51 ms 64 bytes from 2600:9000:25f3:a600:7:49a5:5fd4:b121 (2600:9000:25f3:a600:7:49a5:5fd4:b121): icmp_seq=2 ttl=58 time=1.49 ms Note that the ping is successful and traffic is not blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:13:55 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2606:2cc0::374 (2606:2cc0::374)) 56 data bytes 64 bytes from 2606:2cc0::374 (2606:2cc0::374): icmp_seq=1 ttl=58 time=1.21 ms 64 bytes from 2606:2cc0::374 (2606:2cc0::374): icmp_seq=2 ttl=58 time=1.51 ms Note that the ping is successful and traffic is not blocked. Scenario 6 - Modify VPC BPA mode In this section you'll change the VPC BPA block direction to see how it impacts traffic. In this scenario, VPC BPA enabled in bidirectional mode blocks all traffic just like in Scenario 1. Unless an exclusion has access to a NAT gateway or egress-only internet gateway, traffic is blocked. Diagram of VPC BPA Bidirectional mode turned on and Subnet A exclusion with egress-only mode turned on: Advanced example 536 Amazon Virtual Private Cloud User Guide 6.1 Change VPC BPA to bidirectional mode Complete this section to change the VPC BPA mode. AWS Management Console 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. Choose Edit public access settings. 4. Change the block direction to Bidirectional then choose Save changes. Advanced example 537 Amazon Virtual Private Cloud User Guide 5. Wait for the Status to change to On. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. AWS CLI 1. Modify the VPC BPA block direction: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-bidirectional It may take a few minutes for VPC BPA settings to take effect
vpc-ug-189
vpc-ug.pdf
189
1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the left navigation pane, choose Settings. 3. Choose Edit public access settings. 4. Change the block direction to Bidirectional then choose Save changes. Advanced example 537 Amazon Virtual Private Cloud User Guide 5. Wait for the Status to change to On. It may take a few minutes for VPC BPA settings to take effect and the status to be updated. AWS CLI 1. Modify the VPC BPA block direction: aws ec2 --region us-east-2 modify-vpc-block-public-access-options --internet- gateway-block-mode block-bidirectional It may take a few minutes for VPC BPA settings to take effect and the status to be updated. 2. View the status of VPC BPA: aws ec2 --region us-east-2 describe-vpc-block-public-access-options 6.2 Connect to instances Complete this section to connect to the instances. AWS Management Console 1. Ping the public IPv4 address of Instance A and B. Note that traffic is blocked. 2. Connect to Instance A and B using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com. Note that you cannot ping a public site on the internet from Instance A or B. Traffic is blocked. 3. Connect to Instance C and D using EC2 instance connect as you did in Scenario 1 and ping www.amazon.com from them. Note that you cannot ping a public site on the internet from Instance C or D. Traffic is blocked. AWS CLI 1. Ping Instance A using the public IPv4 address to check inbound traffic: ping 18.225.8.244 Output: Advanced example 538 Amazon Virtual Private Cloud User Guide Pinging 18.225.8.244 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 2. Use the private IPv4 address to connect and check outbound traffic: aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:17:44 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 3. Ping Instance A using the public IPv4 address to check inbound traffic: ping 3.18.106.198 Output: Pinging 3.18.106.198 with 32 bytes of data: Request timed out. Note that the ping fails and traffic is blocked. 4. Use the private IPv4 address to connect and check outbound traffic: Advanced example 539 Amazon Virtual Private Cloud User Guide aws ec2-instance-connect ssh --instance-id i-058db34f9a0997895 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:09:55 2024 from 3.16.146.5 [ec2-user@ip-10-0-1-85 ~]$ ping www.amazon.com PING d3ag4hukkh62yn.cloudfront.net (18.65.233.187) 56(84) bytes of data. Note that the ping fails and traffic is blocked. 5. Connect to Instance C. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-04eca55f2a482b2c4 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:19:45 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-180 ~]$ ping www.amazon.com Advanced example 540 Amazon Virtual Private Cloud User Guide PING www.amazon.com(2600:9000:25f3:6200:7:49a5:5fd4:b121 (2600:9000:25f3:6200:7:49a5:5fd4:b121)) 56 data bytes Note that the ping fails and traffic is blocked. 6. Connect to Instance D. Since there is no public IP address to ping, use EC2 Instance Connect to connect and then ping a public IP from the instance to check outbound traffic: aws ec2-instance-connect ssh --instance-id i-05f9e6a9cfac1dba0 --region us- east-2 --connection-type eice Output: A newer release of "Amazon Linux" is available. Version 2023.5.20240916: Run "/usr/bin/dnf check-release-update" for full release and version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:20:58 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:b400:7:49a5:5fd4:b121 (2600:9000:25f3:b400:7:49a5:5fd4:b121)) 56 data bytes Note that the ping fails and traffic is blocked. Cleanup In this section you'll delete all of the resources you've created for this advanced example. It's important to cleanup the resources to avoid excess additional charges for resources created in your account. Delete the CloudFormation resources Complete this section to delete the resources
vpc-ug-190
vpc-ug.pdf
190
version update info , #_ ~\_ ####_ Amazon Linux 2023 ~~ \_#####\ ~~ \###| ~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023 ~~ V~' '-> ~~~ / ~~._. _/ _/ _/ _/m/' Last login: Fri Sep 27 18:20:58 2024 from 3.16.146.5 [ec2-user@ip-10-0-3-59 ~]$ ping www.amazon.com PING www.amazon.com(2600:9000:25f3:b400:7:49a5:5fd4:b121 (2600:9000:25f3:b400:7:49a5:5fd4:b121)) 56 data bytes Note that the ping fails and traffic is blocked. Cleanup In this section you'll delete all of the resources you've created for this advanced example. It's important to cleanup the resources to avoid excess additional charges for resources created in your account. Delete the CloudFormation resources Complete this section to delete the resources you created with the AWS CloudFormation template. Advanced example 541 Amazon Virtual Private Cloud AWS Management Console User Guide 1. Open the AWS CloudFormation console at https://console.aws.amazon.com/ cloudformation/. 2. Choose the VPC BPA stack. 3. Choose Delete. 4. Once you start deleting the stack, view the Events tab to view progress and ensure that the stack is deleted. You may have to force delete the stack for it to be fully deleted. AWS CLI 1. Delete the CloudFormation stack. You may have to force delete the stack for it to be fully deleted. aws cloudformation delete-stack --stack-name VPC-BPA-stack --region us-east-2 2. View the progress and ensure that the stack is deleted. aws cloudformation describe-stack-events --stack-name VPC-BPA-stack --region us- east-2 Track exclusion deletion with AWS CloudTrail Complete this section to track exclusion deletion with AWS CloudTrail. CloudTrail entries appear when you delete an exclusion. AWS Management Console You can view any deleted exclusions in the CloudTrail Event history by looking up Resource type > AWS::EC2::VPCBlockPublicAccessExclusion in the AWSCloudTrail console at https:// console.aws.amazon.com/cloudtrailv2/. AWS CLI You can use the lookup-events command to view the events related to deleting exclusions: aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceType,AttributeValue=AWS::EC2::VPCBlockPublicAccessExclusion Advanced example 542 Amazon Virtual Private Cloud User Guide The advanced example is complete. Security best practices for your VPC The following best practices are general guidelines and don’t represent a complete security solution. Because these best practices might not be appropriate or sufficient for your environment, treat them as helpful considerations rather than prescriptions. • When you add subnets to your VPC to host your application, create them in multiple Availability Zones. An Availability Zone is one or more discrete data centers with redundant power, networking, and connectivity in an AWS Region. Using multiple Availability Zones makes your production applications highly available, fault tolerant, and scalable. • Use security groups to control traffic to EC2 instances in your subnets. For more information, see Security groups. • Use network ACLs to control inbound and outbound traffic at the subnet level. For more information, see Control subnet traffic with network access control lists. • Manage access to AWS resources in your VPC using AWS Identity and Access Management (IAM) identity federation, users, and roles. For more information, see Identity and access management for Amazon VPC. • Use VPC Flow Logs to monitor the IP traffic going to and from a VPC, subnet, or network interface. For more information, see VPC Flow Logs. • Use Network Access Analyzer to identify unintended network access to resources in our VPCs. For more information, see the Network Access Analyzer Guide. • Use AWS Network Firewall to monitor and protect your VPC by filtering inbound and outbound traffic. For more information, see the AWS Network Firewall Guide. • Use Amazon GuardDuty to detect potential threats to your accounts, containers, workloads, and data within your AWS environment. The foundational threat detection includes monitoring the VPC flow logs associated with your Amazon EC2 instances. For more information, see VPC Flow Logs in the Amazon GuardDuty User Guide. For answers to frequently asked questions related to VPC security, see Security and Filtering in the Amazon VPC FAQs. Best practices 543 Amazon Virtual Private Cloud User Guide Use Amazon VPC with other AWS services Amazon Virtual Private Cloud (VPC) is a foundational AWS service that provides a secure, customizable networking environment for your cloud infrastructure. Beyond creating and managing your own VPC, you can leverage the integration between VPC and other AWS services to build comprehensive solutions tailored to your specific needs. You can connect your VPC to various AWS services using AWS PrivateLink. This enables private connectivity between your VPC and supported AWS services or on-premises applications, keeping network traffic within the AWS network and avoiding exposure to the public internet. This is particularly useful for maintaining strict security boundaries and compliance requirements. To further strengthen the security of your VPC, you can use AWS Network Firewall. This managed firewall service allows you to define and enforce network-level security policies, filtering both north-south and east-west traffic within your VPC. By pairing Network Firewall with your VPC, you can enhance your defense strategy and protect your cloud resources from unauthorized access or malicious activity. Additionally, you can filter
vpc-ug-191
vpc-ug.pdf
191
between your VPC and supported AWS services or on-premises applications, keeping network traffic within the AWS network and avoiding exposure to the public internet. This is particularly useful for maintaining strict security boundaries and compliance requirements. To further strengthen the security of your VPC, you can use AWS Network Firewall. This managed firewall service allows you to define and enforce network-level security policies, filtering both north-south and east-west traffic within your VPC. By pairing Network Firewall with your VPC, you can enhance your defense strategy and protect your cloud resources from unauthorized access or malicious activity. Additionally, you can filter DNS traffic within your VPC using the Route 53 Resolver DNS Firewall. This capability enables you to create custom DNS filtering rules to control which domains your VPC resources can resolve, providing an additional layer of security and compliance enforcement. If you encounter reachability issues between resources within your VPC or connected to your VPC, you can leverage Reachability Analyzer. Reachability Analyzer performs virtual connectivity tests, providing detailed hop-by-hop path information and identifying any blocking components. This troubleshooting tool can quickly help you identify and resolve network connectivity problems. By integrating these complementary AWS services with your VPC, you can build powerful, secure, and resilient cloud solutions that address your unique business and architectural requirements. Contents • Connect your VPC to services using AWS PrivateLink • Filter network traffic using AWS Network Firewall • Filter DNS traffic using Route 53 Resolver DNS Firewall • Troubleshoot reachability issues using Reachability Analyzer 544 Amazon Virtual Private Cloud User Guide Connect your VPC to services using AWS PrivateLink AWS PrivateLink establishes private connectivity between virtual private clouds (VPC) and supported AWS services, services hosted by other AWS accounts, supported AWS Marketplace services, and supported resources. You do not need to use an internet gateway, NAT device, AWS Direct Connect connection, or AWS Site-to-Site VPN connection to communicate with the service or resource. To use AWS PrivateLink, create a VPC endpoint in any subnets from which you need to access the service or resource. This creates elastic network interfaces in the specified subnets that serve as entry points for traffic destined to the service or resource. You can also create your own VPC endpoint service, powered by AWS PrivateLink and enable other AWS customers to access your service. PrivateLink enables the creation of private API endpoints, allowing organizations to expose their own services securely to other AWS customers. This empowers businesses to monetize their internal capabilities, foster collaborative ecosystems, and maintain control over how their services are accessed and consumed. One of the key benefits of using AWS PrivateLink is the ability to establish secure, private connectivity without the need for traditional networking constructs like internet gateways, NAT devices, or VPN connections. This helps simplify the network architecture, reduce the attack surface, and improve overall security by keeping the data traffic confined within the AWS network. The following diagram shows common use cases for AWS PrivateLink. The VPC has several EC2 instances in a private subnet that have access to resources through five VPC endpoints. There are three interface VPC endpoints, one resource VPC endpoint, and one service-network VPC endpoint. AWS PrivateLink 545 Amazon Virtual Private Cloud User Guide For more information, see AWS PrivateLink. Filter network traffic using AWS Network Firewall You can filter network traffic at the perimeter of your VPC using AWS Network Firewall. Network Firewall is a stateful, managed, network firewall and intrusion detection and prevention service. For more information, see the AWS Network Firewall Developer Guide. You implement Network Firewall with the following AWS resources. AWS Network Firewall 546 Amazon Virtual Private Cloud User Guide Network Firewall resource Description Firewall Firewall policy Rule group A firewall connects a firewall policy's network traffic filtering be havior to the VPC that you want to protect. The firewall configura tion includes specifications for the Availability Zones and subnets where the firewall endpoints are placed. It also defines high-level settings like the firewall logging configuration and tagging on the AWS firewall resource. For more information, see Firewalls in AWS Network Firewall. A firewall policy defines the monitoring and protection behavior for a f irewall. The details of the behavior are defined in the rule groups that you add to your policy, and in some policy default settings. To use a f irewall policy, you associate it with one or more firewalls. For more information, see Firewall policies in AWS Network Firewall. A rule group is a reusable set of criteria for inspecting and handling network traffic. You add one or more rule groups to a firewall policy as part of your policy configuration. You can define stateless rule groups to inspect each network packet in isolation. Stateless rule groups are similar in behavior and use to Amazon VPC network access control lists (ACLs).
vpc-ug-192
vpc-ug.pdf
192
rule groups that you add to your policy, and in some policy default settings. To use a f irewall policy, you associate it with one or more firewalls. For more information, see Firewall policies in AWS Network Firewall. A rule group is a reusable set of criteria for inspecting and handling network traffic. You add one or more rule groups to a firewall policy as part of your policy configuration. You can define stateless rule groups to inspect each network packet in isolation. Stateless rule groups are similar in behavior and use to Amazon VPC network access control lists (ACLs). You can also define stateful rule groups to inspect packets in the context of their traffic flow. Stateful rule groups are similar in behavior and use to Amazon VPC security groups. For more information, see Rule groups in AWS Network Firewall. You can also use AWS Firewall Manager to centrally configure and manage Network Firewall resources across your accounts and applications in AWS Organizations. You can manage firewalls for multiple accounts using a single account in Firewall Manager. For more information, see AWS Firewall Manager in the AWS WAF, AWS Firewall Manager, and AWS Shield Advanced Developer Guide. AWS Network Firewall 547 Amazon Virtual Private Cloud User Guide Filter DNS traffic using Route 53 Resolver DNS Firewall With DNS Firewall, you define domain name filtering rules in rule groups that you associate with your VPCs. You can specify lists of domain names to allow or block, and you can customize the responses for the DNS queries that you block. For more information, see the Route 53 Resolver DNS Firewall Documentation. You implement DNS Firewall with the following AWS resources. DNS Firewall resource Description DNS Firewall rule group A DNS Firewall rule group is a named, reusable collection of DNS Firewall rules for filtering DNS queries. You populate the rule group with the filtering rules, then associate the rule group with one or more VPCs from Amazon VPC. When you associate a rule group with a VPC, you enable DNS Firewall filtering for the VPC. Then, when Resolver receives a DNS query for a VPC that has a rule group associated with it, Resolver passes the query to DNS Firewall for filtering. Each rule within the rule group specifies one domain list and an action to take on DNS queries whose domains match the domain specifica tions in the list. You can allow, block, or alert on matching queries. You can also define custom responses for blocked queries. For more information, see Rule groups and rules in Route 53 Resolver DNS Firewall. Domain list A domain list is a reusable set of domain specifications that you use in a DNS Firewall rule, inside a rule group. For more information, see Domain lists in Route 53 Resolver DNS Firewall. You can also use AWS Firewall Manager to centrally configure and manage DNS Firewall resources across your accounts and organizations in AWS Organizations. You can manage firewalls for multiple accounts using a single account in Firewall Manager. For more information, see AWS Firewall Manager in the AWS WAF, AWS Firewall Manager, and AWS Shield Advanced Developer Guide. Route 53 Resolver DNS Firewall 548 Amazon Virtual Private Cloud User Guide Troubleshoot reachability issues using Reachability Analyzer Reachability Analyzer is a static configuration analysis tool. Use Reachability Analyzer to analyze and debug network reachability between two resources in your VPC. Reachability Analyzer produces hop-by-hop details of the virtual path between these resources when they are reachable, and identifies the blocking component otherwise. You can use Reachability Analyzer to analyze reachability between the following resources: • Instances • Internet gateways • Network interfaces • Transit gateways • Transit gateway attachments • VPC endpoint services • VPC endpoints • VPC peering connections • VPN gateways For more information, see the Reachability Analyzer Guide. Reachability Analyzer 549 Amazon Virtual Private Cloud User Guide VPC examples Amazon Virtual Private Cloud (VPC) is a fundamental building block within the AWS ecosystem, allowing you to provision isolated virtual networks tailored to your specific needs. By creating and managing your own VPCs, you gain full control over the networking environment, including the ability to define IP address ranges, subnets, routing tables, and connectivity options. This section contains three example configurations for your virtual private clouds (VPCs), each designed to address a different set of requirements: • VPC for a test environment: This configuration shows how to create a VPC that you can use as a development or test environment. • VPC for Web and database servers: This configuration shows how to create a VPC that you can use for a resilent architecture in a production environment. • VPC with servers in private subnets and NAT: In this more advanced configuration, all EC2 instances are provisioned within private subnets, with a NAT gateway
vpc-ug-193
vpc-ug.pdf
193
connectivity options. This section contains three example configurations for your virtual private clouds (VPCs), each designed to address a different set of requirements: • VPC for a test environment: This configuration shows how to create a VPC that you can use as a development or test environment. • VPC for Web and database servers: This configuration shows how to create a VPC that you can use for a resilent architecture in a production environment. • VPC with servers in private subnets and NAT: In this more advanced configuration, all EC2 instances are provisioned within private subnets, with a NAT gateway facilitating secure outbound internet access. This is an example where you need to limit direct internet connectivity to your resources while still enabling necessary outbound communication. By providing these example VPC configurations, we hope to illustrate the flexibility and customization options available when designing your cloud networking environment. The specific VPC setup you choose should be based on your application's architecture, security requirements, and overall business objectives. Carefully planning your VPC infrastructure can help you create a robust, scalable, and secure virtual network that supports the growth and evolution of your cloud- based workloads. Examples • Example: VPC for a test environment • Example: VPC for web and database servers • Example: VPC with servers in private subnets and NAT Related examples • To connect your VPCs to each other, see VPC peering configurations in the Amazon VPC Peering Guide. 550 Amazon Virtual Private Cloud User Guide • To connect your VPCs to your own network, see Site-to-Site VPN scenarios in the AWS Site-to- Site VPN User Guide. • To connect your VPCs to each other and to your own network, see Example transit gateway scenarios in the Amazon VPC Transit Gateways. Additional resources • Understand resiliency patterns and trade-offs (AWS Architecture Blog) • Plan your network topology (AWS Well-Architected Framework) • Amazon Virtual Private Cloud Connectivity Options (AWS Whitepapers) Example: VPC for a test environment This example demonstrates how to create a VPC that you can use as a development or test environment. Because this VPC is not intended to be used in production, it is not necessary to deploy your servers in multiple Availability Zones. To keep the cost and complexity low, you can deploy your servers in a single Availability Zone. Contents • Overview • 1. Create the VPC • 2. Deploy your application • 3. Test your configuration • 4. Clean up Overview The following diagram provides an overview of the resources included in this example. The VPC has a public subnet in a single Availability Zone and an internet gateway. The server is an EC2 instance that runs in the public subnet. The security group for the instance allows SSH traffic from your own computer, plus any other traffic specifically required for your development or testing activities. Test environment 551 Amazon Virtual Private Cloud User Guide Routing When you create this VPC by using the Amazon VPC console, we create a route table for the public subnet with local routes and routes to the internet gateway. The following is an example of the route table with routes for both IPv4 and IPv6. If you create an IPv4-only subnet instead of a dual stack subnet, your route table has only the IPv4 routes. Destination 10.0.0.0/16 2001:db8:1234:1a00::/56 0.0.0.0/0 ::/0 Security Target local local igw-id igw-id For this example configuration, you must create a security group for your instance that allows the traffic that your application needs. For example, you might need to add a rule that allows SSH traffic from your computer or HTTP traffic from your network. The following are example inbound rules for a security group, with rules for both IPv4 and IPv6. If you create IPv4-only subnets instead of dual stack subnets, you need only the rules for IPv4. Overview 552 Amazon Virtual Private Cloud User Guide Protocol Port range Description Source 0.0.0.0/0 ::/0 0.0.0.0/0 ::/0 Public IPv4 address range of your network TCP TCP TCP TCP TCP IPv6 address range TCP of your network 80 80 443 443 22 22 Public IPv4 TCP 3389 address range of your network IPv6 address range TCP 3389 of your network Allows inbound HTTP access from all IPv4 addresses Allows inbound HTTP access from all IPv6 addresses Allows inbound HTTPS access from all IPv4 addresses Allows inbound HTTPS access from all IPv6 addresses (Optional) Allows inbound SSH access from IPv4 IP addresses in your network (Optional) Allows inbound SSH access from IPv6 IP addresses in your network (Optional) Allows inbound RDP access from IPv4 IP addresses in your network (Optional) Allows inbound RDP access from IPv6 IP addresses in your network 1. Create the VPC Use the following procedure to create a VPC with a public subnet in one Availability Zone. This configuration is suitable for a
vpc-ug-194
vpc-ug.pdf
194
IPv4 addresses Allows inbound HTTP access from all IPv6 addresses Allows inbound HTTPS access from all IPv4 addresses Allows inbound HTTPS access from all IPv6 addresses (Optional) Allows inbound SSH access from IPv4 IP addresses in your network (Optional) Allows inbound SSH access from IPv6 IP addresses in your network (Optional) Allows inbound RDP access from IPv4 IP addresses in your network (Optional) Allows inbound RDP access from IPv6 IP addresses in your network 1. Create the VPC Use the following procedure to create a VPC with a public subnet in one Availability Zone. This configuration is suitable for a development or testing environment. To create the VPC 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 1. Create the VPC 553 Amazon Virtual Private Cloud User Guide 2. On the dashboard, choose Create VPC. 3. For Resources to create, choose VPC and more. 4. Configure the VPC a. b. c. For Name tag auto-generation, enter a name for the VPC. For IPv4 CIDR block, you can keep the default suggestion, or alternatively you can enter the CIDR block required by your application or network. For more information, see the section called “VPC CIDR blocks”. (Optional) If your application communicates by using IPv6 addresses, choose IPv6 CIDR block, Amazon-provided IPv6 CIDR block. 5. Configure the subnets a. b. c. For Number of Availability Zones, choose 1. You can keep the default Availability Zone, or alternatively you can expand Customize AZs and select an Availability Zone. For Number of public subnets, choose 1. For Number of private subnets, choose 0. d. You can keep the default CIDR block for the public subnet, or alternatively you can expand Customize subnet CIDR blocks and enter a CIDR block. For more information, see the section called “Subnet CIDR blocks”. 6. 7. 8. For NAT gateways, keep the default value, None. For VPC endpoints, choose None. A gateway VPC endpoint for S3 is used only to access Amazon S3 from private subnets. For DNS options, keep both options selected. As a result, your instance will receive a public DNS hostname that corresponds to its public IP address. 9. Choose Create VPC. 2. Deploy your application There are a variety of ways to deploy EC2 instances. For example: • Amazon EC2 launch instance wizard • Amazon EC2 Auto Scaling • AWS CloudFormation • Amazon Elastic Container Service (Amazon ECS) 2. Deploy your application 554 Amazon Virtual Private Cloud User Guide After you deploy an EC2 instance, you can connect to the instance, install the software that you need for your application, and then create an image for future use. For more information, see Create an AMI in the Amazon EC2 User Guide. Alternatively, you can use EC2 Image Builder to create and manage your Amazon Machine Image (AMI). 3. Test your configuration After you've finished deploying your application, you can test it. If you can't connect to your EC2 instance, or if your application can't send or receive the traffic that you expect, you can use Reachability Analyzer to help you troubleshoot. For example, Reachability Analyzer can identify configuration issues with your route tables or security groups. For more information, see the Reachability Analyzer Guide. 4. Clean up When you are finished with this configuration, you can delete it. Before you can delete the VPC, you must terminate your instance. For more information, see the section called “Delete your VPC”. Example: VPC for web and database servers This example demonstrates how to create a VPC that you can use for a two-tier architecture in a production environment. To improve resiliency, you deploy the servers in two Availability Zones. Contents • Overview • 1. Create the VPC • 2. Deploy your application • 3. Test your configuration • 4. Clean up Overview The following diagram provides an overview of the resources included in this example. The VPC has public subnets and private subnets in two Availability Zones. The web servers run in the public subnets and receive traffic from clients through a load balancer. The security group for the web 3. Test your configuration 555 Amazon Virtual Private Cloud User Guide servers allows traffic from the load balancer. The database servers run in the private subnets and receive traffic from the web servers. The security group for the database servers allows traffic from the web servers. The database servers can connect to Amazon S3 by using a gateway VPC endpoint. Routing When you create this VPC by using the Amazon VPC console, we create a route table for the public subnets with local routes and routes to the internet gateway, and a route table for each private subnet with local routes and a route to the gateway VPC endpoint. The following is an example of a route table for the public subnets, with routes for both IPv4 and
vpc-ug-195
vpc-ug.pdf
195
traffic from the web servers. The security group for the database servers allows traffic from the web servers. The database servers can connect to Amazon S3 by using a gateway VPC endpoint. Routing When you create this VPC by using the Amazon VPC console, we create a route table for the public subnets with local routes and routes to the internet gateway, and a route table for each private subnet with local routes and a route to the gateway VPC endpoint. The following is an example of a route table for the public subnets, with routes for both IPv4 and IPv6. If you create IPv4-only subnets instead of dual stack subnets, your route table has only the IPv4 routes. Destination 10.0.0.0/16 2001:db8:1234:1a00::/56 Target local local Overview 556 Amazon Virtual Private Cloud User Guide Destination 0.0.0.0/0 ::/0 Target igw-id igw-id The following is an example of a route table for the private subnets, with local routes for both IPv4 and IPv6. If you created IPv4-only subnets, your route table has only the IPv4 route. The last route sends traffic destined for Amazon S3 to the gateway VPC endpoint. Destination 10.0.0.0/16 2001:db8:1234:1a00::/56 Target local local s3-prefix-list-id s3-gateway-id Security For this example configuration, you create a security group for the load balancer, a security group for the web servers, and a security group for the database servers. Load balancer The security group for your Application Load Balancer or Network Load Balancer must allow inbound traffic from clients on the load balancer listener port. To accept traffic from anywhere on the internet, specify 0.0.0.0/0 as the source. The load balancer security group must also allow outbound traffic from the load balancer to the target instances on the instance listener port and the health check port. Web servers The following security group rules allow the web servers to receive HTTP and HTTPS traffic from the load balancer. You can optionally allow the web servers to receive SSH or RDP traffic from your network. The web servers can send SQL or MySQL traffic to your database servers. Overview 557 Amazon Virtual Private Cloud User Guide Source Protocol Port range Description ID of the security TCP 80 group for the load balancer ID of the security TCP 443 group for the load balancer Public IPv4 TCP address range of your network IPv6 address range TCP of your network 22 22 Public IPv4 TCP 3389 address range of your network IPv6 address range TCP 3389 of your network Allows inbound HTTP access from the load balancer Allows inbound HTTPS access from the load balancer (Optional) Allows inbound SSH access from IPv4 IP addresses in your network (Optional) Allows inbound SSH access from IPv6 IP addresses in your network (Optional) Allows inbound RDP access from IPv4 IP addresses in your network (Optional) Allows inbound RDP access from IPv6 IP addresses in your network Destination Protocol Port range Description ID of the security TCP 1433 group for instances running Microsoft SQL Server ID of the security TCP 3306 group for Overview Allows outbound Microsoft SQL Server access to the database servers Allows outbound MySQL access to the database servers 558 Amazon Virtual Private Cloud User Guide Destination Protocol Port range Description instances running MySQL Database servers The following security group rules allow the database servers to receive read and write requests from the web servers. Source Protocol Port range Comments ID of the web TCP 1433 server security group ID of the web TCP 3306 server security group Allows inbound Microsoft SQL Server access from the web servers Allows inbound MySQL Server access from the web servers Destination Protocol Port range Comments 0.0.0.0/0 0.0.0.0/0 TCP TCP 80 443 Allows outbound HTTP access to the internet over IPv4 Allows outbound HTTPS access to the internet over IPv4 For more information about security groups for Amazon RDS DB instances, see Controlling access with security groups in the Amazon RDS User Guide. 1. Create the VPC Use the following procedure to create a VPC with a public subnet and a private subnet in two Availability Zones. 1. Create the VPC 559 Amazon Virtual Private Cloud To create the VPC User Guide 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the dashboard, choose Create VPC. 3. For Resources to create, choose VPC and more. 4. Configure the VPC: a. Keep Name tag auto-generation selected to create Name tags for the VPC resources or clear it to provide your own Name tags for the VPC resources. b. c. For IPv4 CIDR block, you can keep the default suggestion, or alternatively you can enter the CIDR block required by your application or network. For more information, see the section called “VPC CIDR blocks”. (Optional) If your application communicates by using IPv6 addresses, choose IPv6 CIDR block, Amazon-provided IPv6 CIDR block. d. Choose a Tenancy
vpc-ug-196
vpc-ug.pdf
196
choose Create VPC. 3. For Resources to create, choose VPC and more. 4. Configure the VPC: a. Keep Name tag auto-generation selected to create Name tags for the VPC resources or clear it to provide your own Name tags for the VPC resources. b. c. For IPv4 CIDR block, you can keep the default suggestion, or alternatively you can enter the CIDR block required by your application or network. For more information, see the section called “VPC CIDR blocks”. (Optional) If your application communicates by using IPv6 addresses, choose IPv6 CIDR block, Amazon-provided IPv6 CIDR block. d. Choose a Tenancy option. This option defines if EC2 instances that you launch into the VPC will run on hardware that's shared with other AWS accounts or on hardware that's dedicated for your use only. If you choose the tenancy of the VPC to be Default, EC2 instances launched into this VPC will use the tenancy attribute specified when you launch the instance. For more information, see Launch an instance using defined parameters in the Amazon EC2 User Guide. If you choose the tenancy of the VPC to be Dedicated, the instances will always run as Dedicated Instances on hardware that's dedicated for your use. 5. Configure the subnets: a. b. c. For Number of Availability Zones, choose 2, so that you can launch instances in two Availability Zones to improve resiliency. For Number of public subnets, choose 2. For Number of private subnets, choose 2. d. You can keep the default CIDR blocks for the subnets, or alternatively you can expand Customize subnets CIDR blocks and enter a CIDR block. For more information, see the section called “Subnet CIDR blocks”. For NAT gateways, keep the default value, None. For VPC endpoints, keep the default value, S3 Gateway. While there is no effect unless you access an S3 bucket, there is no cost to enable this VPC endpoint. For DNS options, keep both options selected. As a result, your web servers will receive public DNS hostnames that correspond to their public IP addresses. 6. 7. 8. 1. Create the VPC 560 Amazon Virtual Private Cloud 9. Choose Create VPC. 2. Deploy your application User Guide Ideally, you've already tested your web servers and database servers in a development or test environment, and created the scripts or images that you'll use to deploy your application in production. You can use EC2 instances for your web servers. There are a variety of ways to deploy EC2 instances. For example: • Amazon EC2 launch instance wizard • AWS CloudFormation • Amazon Elastic Container Service (Amazon ECS) To improve availability, you can use Amazon EC2 Auto Scaling to deploy servers in multiple Availability Zones and maintain the minimum server capacity that is required by your application. You can use Elastic Load Balancing to distribute traffic evenly across your servers. You can attach your load balancer to an Auto Scaling group. You can use EC2 instances for your database servers, or one of our purpose-built database types. For more information, see Databases on AWS: How to choose. 3. Test your configuration After you've finished deploying your application, you can test it. If your application can't send or receive the traffic that you expect, you can use Reachability Analyzer to help you troubleshoot. For example, Reachability Analyzer can identify configuration issues with your route tables or security groups. For more information, see the Reachability Analyzer Guide. 4. Clean up When you are finished with this configuration, you can delete it. Before you can delete the VPC, you must terminate your instances and delete the load balancer. For more information, see the section called “Delete your VPC”. 2. Deploy your application 561 Amazon Virtual Private Cloud User Guide Example: VPC with servers in private subnets and NAT This example demonstrates how to create a VPC that you can use for servers in a production environment. To improve resiliency, you deploy the servers in two Availability Zones, by using an Auto Scaling group and an Application Load Balancer. For additional security, you deploy the servers in private subnets. The servers receive requests through the load balancer. The servers can connect to the internet by using a NAT gateway. To improve resiliency, you deploy the NAT gateway in both Availability Zones. Contents • Overview • 1. Create the VPC • 2. Deploy your application • 3. Test your configuration • 4. Clean up Overview The following diagram provides an overview of the resources included in this example. The VPC has public subnets and private subnets in two Availability Zones. Each public subnet contains a NAT gateway and a load balancer node. The servers run in the private subnets, are launched and terminated by using an Auto Scaling group, and receive traffic from the load balancer. The servers can connect to the internet
vpc-ug-197
vpc-ug.pdf
197
you deploy the NAT gateway in both Availability Zones. Contents • Overview • 1. Create the VPC • 2. Deploy your application • 3. Test your configuration • 4. Clean up Overview The following diagram provides an overview of the resources included in this example. The VPC has public subnets and private subnets in two Availability Zones. Each public subnet contains a NAT gateway and a load balancer node. The servers run in the private subnets, are launched and terminated by using an Auto Scaling group, and receive traffic from the load balancer. The servers can connect to the internet by using the NAT gateway. The servers can connect to Amazon S3 by using a gateway VPC endpoint. Private servers 562 Amazon Virtual Private Cloud User Guide Routing When you create this VPC by using the Amazon VPC console, we create a route table for the public subnets with local routes and routes to the internet gateway. We also create a route table for the private subnets with local routes, and routes to the NAT gateway, egress-only internet gateway, and gateway VPC endpoint. The following is an example of the route table for the public subnets, with routes for both IPv4 and IPv6. If you create IPv4-only subnets instead of dual stack subnets, your route table includes only the IPv4 routes. Destination 10.0.0.0/16 2001:db8:1234:1a00::/56 Target local local Overview 563 Amazon Virtual Private Cloud User Guide Destination 0.0.0.0/0 ::/0 Target igw-id igw-id The following is an example of a route table for one of the private subnets, with routes for both IPv4 and IPv6. If you created IPv4-only subnets, the route table includes only the IPv4 routes. The last route sends traffic destined for Amazon S3 to the gateway VPC endpoint. Destination 10.0.0.0/16 2001:db8:1234:1a00::/56 0.0.0.0/0 ::/0 Target local local nat-gateway-id eigw-id s3-prefix-list-id s3-gateway-id Security The following is an example of the rules that you might create for the security group that you associate with your servers. The security group must allow traffic from the load balancer over the listener port and protocol. It must also allow health check traffic. Source Protocol Port range Comments ID of the load listener listener balancer security protocol port group Allows inbound traffic from the load balancer on the listener port ID of the load health health balancer security check check port Allows inbound health check traffic from the load balancer group protocol Overview 564 Amazon Virtual Private Cloud 1. Create the VPC User Guide Use the following procedure to create a VPC with a public subnet and a private subnet in two Availability Zones, and a NAT gateway in each Availability Zone. To create the VPC 1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/. 2. On the dashboard, choose Create VPC. 3. For Resources to create, choose VPC and more. 4. Configure the VPC a. b. c. For Name tag auto-generation, enter a name for the VPC. For IPv4 CIDR block, you can keep the default suggestion, or alternatively you can enter the CIDR block required by your application or network. If your application communicates by using IPv6 addresses, choose IPv6 CIDR block, Amazon-provided IPv6 CIDR block. 5. Configure the subnets a. b. c. For Number of Availability Zones, choose 2, so that you can launch instances in multiple Availability Zones to improve resiliency. For Number of public subnets, choose 2. For Number of private subnets, choose 2. d. You can keep the default CIDR block for the public subnet, or alternatively you can expand Customize subnet CIDR blocks and enter a CIDR block. For more information, see the section called “Subnet CIDR blocks”. 6. 7. 8. For NAT gateways, choose 1 per AZ to improve resiliency. If your application communicates by using IPv6 addresses, for Egress only internet gateway, choose Yes. For VPC endpoints, if your instances must access an S3 bucket, keep the S3 Gateway default. Otherwise, instances in your private subnet can't access Amazon S3. There is no cost for this option, so you can keep the default if you might use an S3 bucket in the future. If you choose None, you can always add a gateway VPC endpoint later on. 9. For DNS options, clear Enable DNS hostnames. 10. Choose Create VPC. 1. Create the VPC 565 Amazon Virtual Private Cloud User Guide 2. Deploy your application Ideally, you've finished testing your servers in a development or test environment, and created the scripts or images that you'll use to deploy your application in production. You can use Amazon EC2 Auto Scaling to deploy servers in multiple Availability Zones and maintain the minimum server capacity required by your application. To launch instances by using an Auto Scaling group 1. Create a launch template to specify the configuration information needed to launch your EC2 instances by using Amazon EC2 Auto Scaling. For
vpc-ug-198
vpc-ug.pdf
198
Create VPC. 1. Create the VPC 565 Amazon Virtual Private Cloud User Guide 2. Deploy your application Ideally, you've finished testing your servers in a development or test environment, and created the scripts or images that you'll use to deploy your application in production. You can use Amazon EC2 Auto Scaling to deploy servers in multiple Availability Zones and maintain the minimum server capacity required by your application. To launch instances by using an Auto Scaling group 1. Create a launch template to specify the configuration information needed to launch your EC2 instances by using Amazon EC2 Auto Scaling. For step-by-step directions, see Create a launch template for your Auto Scaling group in the Amazon EC2 Auto Scaling User Guide. 2. Create an Auto Scaling group, which is a collection of EC2 instances with a minimum, maximum, and desired size. For step-by-step directions, see Create an Auto Scaling group using a launch template in the Amazon EC2 Auto Scaling User Guide. 3. Create a load balancer, which distributes traffic evenly across the instances in your Auto Scaling group, and attach the load balancer to your Auto Scaling group. For more information, see the Elastic Load Balancing User Guide and Use Elastic Load Balancing in the Amazon EC2 Auto Scaling User Guide. 3. Test your configuration After you've finished deploying your application, you can test it. If your application can't send or receive the traffic that you expect, you can use Reachability Analyzer to help you troubleshoot. For example, Reachability Analyzer can identify configuration issues with your route tables or security groups. For more information, see the Reachability Analyzer Guide. 4. Clean up When you are finished with this configuration, you can delete it. Before you can delete the VPC, you must delete the Auto Scaling group, terminate your instances, delete the NAT gateways, and delete the load balancer. For more information, see the section called “Delete your VPC”. 2. Deploy your application 566 Amazon Virtual Private Cloud User Guide Amazon VPC quotas The following tables list the quotas, formerly referred to as limits, for Amazon VPC resources for your AWS account. Unless indicated otherwise, these quotas are per Region. If you request a quota increase that applies per resource, we increase the quota for all resources in the Region. VPC and subnets Name Default Adjustable Comments VPCs per Region 5 Yes Subnets per VPC 200 IPv4 CIDR blocks per VPC 5 Yes Yes (up to 50) IPv6 CIDR blocks per VPC 5 Yes VPC Block Public Access exclusions per account per Region 50 (up to 50) Yes. To request an increase, open a service limit increase case using the AWS Support Center Console. Increasing this quota increases the quota on internet gateways per Region by the same amount. You can increase this limit so that you can have hundreds of VPCs per Region. This primary CIDR block and all secondary CIDR blocks count toward this quota. The number of CIDRs you can allocate to a single VPC. The number of VPC BPA exclusions you can create in an account. VPC and subnets 567 Amazon Virtual Private Cloud DNS User Guide Each EC2 instance can send 1024 packets per second per network interface to Route 53 Resolver (specifically the .2 address, such as 10.0.0.2 and 169.254.169.253). This quota cannot be increased. The number of DNS queries per second supported by Route 53 Resolver varies by the type of query, the size of the response, and the protocol in use. For more information and recommendations for a scalable DNS architecture, see the AWS Hybrid DNS with Active Directory Technical Guide. Elastic IP addresses Name Default Adjustabl e Comments Elastic IP addresses per Region Elastic IP addresses per public NAT gateway 5 2 Yes Yes This quota applies to individual AWS account VPCs and shared VPCs. You can request a quota increase up to 8. Gateways Name Egress-only internet gateways per Region Internet gateways per Region Default Adjustabl e Comments 5 5 Yes Yes To increase this quota, increase the quota for VPCs per Region. You can attach only one egress-only internet gateway to a VPC at a time. To increase this quota, increase the quota for VPCs per Region. You can attach only one internet gateway to a VPC at a time. DNS 568 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide NAT gateways per Availabil ity Zone Private IP address quota per NAT gateway Carrier gateways per VPC 5 8 1 Yes NAT gateways only count toward your quota in the pending, active, and deleting states. Yes No Customer-managed prefix lists While the default quotas for customer-managed prefix lists are adjustable, you cannot request an increase using the Service Quotas console. You must open a service limit increase case using the AWS Support Center Console. Name Default Adjustabl
vpc-ug-199
vpc-ug.pdf
199
only one internet gateway to a VPC at a time. DNS 568 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide NAT gateways per Availabil ity Zone Private IP address quota per NAT gateway Carrier gateways per VPC 5 8 1 Yes NAT gateways only count toward your quota in the pending, active, and deleting states. Yes No Customer-managed prefix lists While the default quotas for customer-managed prefix lists are adjustable, you cannot request an increase using the Service Quotas console. You must open a service limit increase case using the AWS Support Center Console. Name Default Adjustabl e Comments Prefix lists per Region 100 Versions per prefix list 1,000 Yes Yes Maximum number of entries per prefix list 1,000 Yes If a prefix list has 1,000 stored versions and you add a new version, the oldest version is removed so that the new version can be added. You can resize a customer-managed prefix list up to 1000. For more information, see Resize a prefix list. When you reference a prefix list in a resource, the maximum number of entries for the prefix lists counts against the quota for the number of entries for the resource. For example, if you create a prefix list with 20 maximum entries Customer-managed prefix lists 569 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide References to a prefix list per resource type 5,000 Yes and you reference that prefix list in a security group rule, this counts as 20 security group rules. This quota applies per resource type that can reference a prefix list. For example, you can have 5,000 references to a prefix list across all of your security groups plus 5,000 references to a prefix list across all of your subnet route tables. If you share a prefix list with other AWS accounts, the other accounts' references to your prefix list count toward this quota. Network ACLs Name Default Adjustabl e Comments Network ACLs per VPC 200 Yes Rules per network ACL 20 Yes You can associate one network ACL to one or more subnets in a VPC. This quota determines both the maximum number of inbound rules and the maximum number of outbound rules. This quota can be increased up to a maximum of 40 inbound rules and 40 outbound rules (for a total of 80 rules), but network performance might be impacted. Network ACLs 570 Amazon Virtual Private Cloud Network interfaces User Guide Name Default Adjustabl e Comments Network interfaces per instance Network interfaces per Region No Varies by instance type 5,000 Yes For more information, see Network interfaces per instance type. This quota applies to individual AWS account VPCs and shared VPCs. This limit is enforced per Availability Zone (AZ). If, for example, the network interfaces are in three AZs, each AZ will have a limit of 5,000 limit and the Region will have a limit of 15,000. Route tables Name Default Adjustabl e Comments Route tables per VPC 200 Yes Routes per route table (non-propagated routes) 50 Yes The main route table counts toward this quota. Note that if you request a quota increase for route tables, you may also want to request a quota increase for subnets. While route tables can be shared with multiple subnets, a subnet can only be associated with a single route table. You can increase this quota up to a maximum of 1,000; however, network performance might be impacted. This quota is enforced separately for IPv4 routes and IPv6 routes. Network interfaces 571 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide If you have more than 125 routes, we recommend that you paginate calls to describe your route tables for better performance. Propagated routes per route table 100 No If you require additional prefixes, advertise a default route. Route servers Name Default Adjustabl e Comments Route servers per VPC 5 Route server endpoints per route server 10 Yes. To request an increase, open a service limit increase case using the AWS Support Center Console. Yes. To request an increase, open a Route servers 572 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide service limit increase case using the AWS Support Center Console. Yes. To request an increase, open a service limit increase case using the AWS Support Center Console. No Peering sessions per network interface 20 Route server endpoints per route server and subnet 2 Routes per route server peer 100 No You can only have two endpoints in the same subnet for the same route server for redundancy. This is the number of routes that can be dynamically advertised over a route server peer Route servers 573 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide Routes per route server 100 No This is the number of routes
vpc-ug-200
vpc-ug.pdf
200
Console. Yes. To request an increase, open a service limit increase case using the AWS Support Center Console. No Peering sessions per network interface 20 Route server endpoints per route server and subnet 2 Routes per route server peer 100 No You can only have two endpoints in the same subnet for the same route server for redundancy. This is the number of routes that can be dynamically advertised over a route server peer Route servers 573 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide Routes per route server 100 No This is the number of routes that can be installed in the Forwarding Information Base (FIB) of a route server. Security groups Name Default Adjustabl e Comments VPC security groups per Region 2,500 Yes This quota applies to individual AWS account VPCs and shared VPCs. Inbound or outbound rules per security group 60 Yes If you increase this quota to more than 5,000 security groups in a Region, we recommend that you paginate calls to describe your security groups for better performance. This quota is enforced separately for inbound and outbound rules. For an account with the default quota of 60 rules, a security group can have 60 inbound rules and 60 outbound rules. In addition, this quota is enforced separately for IPv4 rules and IPv6 rules. For an account with the default quota of 60 rules, a security group can have 60 inbound rules for IPv4 traffic and 60 inbound rules for IPv6 traffic. For more information, see the section called “Security group size”. Security groups 574 Amazon Virtual Private Cloud Name Default Adjustabl e Comments User Guide A quota change applies to both inbound and outbound rules. This quota multiplied by the quota for security groups per network interface cannot exceed 1,000. Security groups per network interface 5 Yes This quota multiplied by the quota for rules per security group cannot exceed (up to 16) 1,000. VPC subnet sharing All standard VPC quotas apply to shared VPC subnets. Name Default Adjustabl e Comments Participant accounts per VPC 100 Yes Subnets that can be shared with an account 100 Yes The maximum number of distinct participant accounts that subnets in a VPC can be shared with. This is a per VPC quota and applies across all the subnets shared in a VPC. VPC owners can view the network interfaces and security groups that are attached to the participant resources. This is the maximum number of subnets that can be shared with an AWS account. VPC subnet sharing 575 Amazon Virtual Private Cloud User Guide Network Address Usage Network Address Usage (NAU) is comprised of IP addresses, network interfaces, and CIDRs in managed prefix lists. NAU is a metric applied to resources in a VPC to help you plan for and monitor the size of your VPC. For more information, see Network Address Usage. The resources that make up the NAU count have their own individual service quotas. Even if a VPC has NAU capacity available, you won't be able to launch resources into the VPC if the resources have exceeded their service quotas. Name Default Adjustabl e Comments Network Address Usage 64,000 Yes (up to to 256,000) The maximum number of NAU units per VPC. Peered Network Address Usage 128,000 Yes (up to The maximum number of NAU units for a VPC and all of its intra-Region peered 512,000) VPCs. VPCs that are peered across different Regions do not contribute to this number. Amazon EC2 API throttling For information about Amazon EC2 throttling, see Request throttling in the Amazon EC2 Developer Guide. Additional quota resources For more information, see the following: • AWS Client VPN quotas in the AWS Client VPN Administrator Guide • AWS Direct Connect quotas in the AWS Direct Connect User Guide • Peering quotas in the Amazon VPC Peering Guide • PrivateLink quotas in the AWS PrivateLink Guide Network Address Usage 576 Amazon Virtual Private Cloud User Guide • Site-to-Site VPN quotas in the AWS Site-to-Site VPN User Guide • Traffic Mirroring quotas in the Amazon VPC Traffic Mirroring Guide • Transit gateway quotas in the Amazon VPC Transit Gateways Guide Additional quota resources 577 Amazon Virtual Private Cloud User Guide Document history The following table describes the important changes in each release of the Amazon VPC User Guide. Change Description Date Dynamic routing in your VPC using Amazon VPC Route Amazon VPC Route Server simplifies routing for traffic March 31, 2025 Server AWS managed policy update Declarative policy support for VPC BPA between workloads that are deployed within a VPC and its internet gateways. With this feature, VPC Route Server dynamically updates VPC and gateway route tables with your preferred IPv4 or IPv6 routes to achieve routing fault tolerance for those workloads. This enables you to automatically reroute traffic within
vpc-ug-201
vpc-ug.pdf
201
Document history The following table describes the important changes in each release of the Amazon VPC User Guide. Change Description Date Dynamic routing in your VPC using Amazon VPC Route Amazon VPC Route Server simplifies routing for traffic March 31, 2025 Server AWS managed policy update Declarative policy support for VPC BPA between workloads that are deployed within a VPC and its internet gateways. With this feature, VPC Route Server dynamically updates VPC and gateway route tables with your preferred IPv4 or IPv6 routes to achieve routing fault tolerance for those workloads. This enables you to automatically reroute traffic within a VPC, which increases the manageability of VPC routing and interoper ability with third-party workloads. Amazon VPC updated the AmazonVPCFullAccess and AmazonVPCReadOnlyAccess managed policies. If you are using AWS Organizations to manage accounts in your organizat ion, you can use a declarative policy to enforce VPC BPA on December 9, 2024 December 1, 2024 578 Amazon Virtual Private Cloud User Guide VPC Block Public Access (BPA) Shared Security Groups the accounts in the organizat ion. VPC Block public Access (BPA) enables you to block resources in VPCs and subnets that you own in a Region from reaching or being reached from the internet through internet gateways and egress- only internet gateways. This feature enables you to share a security group with other AWS Organizations accounts. November 19, 2024 October 30, 2024 Security Group VPC Associati ons This feature enables you to associate a security group October 30, 2024 NAT gateway MTU support Private IPv6 addressing IPv6 preferred lease time with multiple VPCs in the same Region. NAT gateways support traffic with a maximum transmission unit (MTU) of 8500. Information about private IPv6 addressing was added. Private IPv6 addresses are only available in Amazon VPC IP Address Manager. You can now choose how frequently a running insta nce with an IPv6 assigned to it goes through DHCPv6 lease renewal. September 10, 2024 August 8, 2024 February 20, 2024 579 Amazon Virtual Private Cloud User Guide Guide structure review and improvements The structure of the guide was reviewed and improveme February 20, 2024 AWS managed policy update AWS managed policy update EC2-Classic is deprecated February 8, 2024 September 25, 2023 July 31, 2023 nts were made to improve the customer experience related to finding info for specific scenarios. Amazon VPC updated the AmazonVPCFullAccess and AmazonVPCReadOnlyAccess managed policies. Amazon VPC updated the AmazonVPCCrossAcco untNetworkInterfaceOperatio ns managed policy. With EC2-Classic, EC2 instances ran in a single, flat network shared with other customers. Amazon VPC replaces EC2-Classic. With Amazon VPC, your instances run in a virtual private cloud (VPC) that's logically isolated to your AWS account. 580 Amazon Virtual Private Cloud User Guide Add secondary IPv4 addresses to NAT gateways You can add secondary private IPv4 addresses to January 31, 2023 public and private NAT gateways. Secondary IPv 4 addresses increase the number of available ports, and therefore they increase the limit on the number of concurrent connections that your workloads can establish using a NAT gateway. Updated guide to align with the IAM best practices . For more information, see Security best practices in IAM. January 4, 2023 Aligning with IAM best practices Pick the private IP address of your NAT gateway When you create a NAT gateway, you can now November 17, 2022 choose to pick the private IP address that's assigned to the NAT gateway. Previousl y, the private IP address was automatically assigned from the IP address range of the subnet. Three IPv6 addresses are now reserved for use by the default VPC router. You can now transfer Elastic IP addresses from one AWS account to another. November 11, 2022 October 31, 2022 IPv6 default gateway router configuration Transfer Elastic IP addresses 581 Amazon Virtual Private Cloud User Guide Network Address Usage metrics You can enable Network Address Usage metrics for October 4, 2022 your VPC to help you plan for and monitor the size of your VPC. Publish Flow Logs to Amazon Data Firehose You can specify a Amazon Data Firehose delivery stream September 8, 2022 NAT gateway bandwidth as a destination for flow log data. NAT gateways now support bandwidth up to 100 Gbps (an increase from 45 Gbps) and can process up to ten million packets per second (up from four million packets). June 15, 2022 Multiple IPv6 CIDR blocks You can associate up to five IPv6 CIDR blocks to a VPC. May 12, 2022 Reorganization General reorganization of this Amazon Virtual Private Cloud January 2, 2022 NAT gateway IPv6 to IPv4 IPv6-only subnets in VPCs User Guide. NAT gateway supports network address translation from IPv6 to IPv4, popularly known as NAT64. You can create IPv6-only subnets into which you can launch IPv6-only EC2 instances. November 24, 2021 November 23, 2021 582 Amazon Virtual Private Cloud VPC Flow
vpc-ug-202
vpc-ug.pdf
202
and can process up to ten million packets per second (up from four million packets). June 15, 2022 Multiple IPv6 CIDR blocks You can associate up to five IPv6 CIDR blocks to a VPC. May 12, 2022 Reorganization General reorganization of this Amazon Virtual Private Cloud January 2, 2022 NAT gateway IPv6 to IPv4 IPv6-only subnets in VPCs User Guide. NAT gateway supports network address translation from IPv6 to IPv4, popularly known as NAT64. You can create IPv6-only subnets into which you can launch IPv6-only EC2 instances. November 24, 2021 November 23, 2021 582 Amazon Virtual Private Cloud VPC Flow Logs delivery options to Amazon S3 Amazon EC2 Global View More specific routes User Guide October 13, 2021 September 1, 2021 August 30, 2021 You can specify the Apache Parquet log file format, hourly partitions, and Hive- compatible S3 prefixes. Amazon EC2 Global View enables you to view VPCs, subnets, instances, security groups, and volumes across multiple AWS Regions in a single console. You can add a route to your route tables that is more specific than the local route. You can use more specific routes to redirect traffic between subnets within a VPC (East-West traffic) to a middlebox appliance. You can set the destination of a route to match an entire IPv4 or IPv6 CIDR block of a subnet in your VPC. Resource IDs and tagging support for security group You can refer to security group rules by resource ID. July 7, 2021 rules Private NAT gateways You can also add tags to your security group rules. You can use a private NAT gateway for outbound-only private communication between VPCs or between a VPC and your on-premises network. June 10, 2021 583 Amazon Virtual Private Cloud Tag on create User Guide June 30, 2020 You can add tags when you create a VPC, DHCP options, internet gateway, egress-only gateway, network ACL, and security group. Managed prefix lists You can create and manage a set of CIDR blocks in prefix June 29, 2020 Flow logs enhancements list. New flow log fields are available, and you can specify a custom format for flow logs that publish to CloudWatch Logs. May 4, 2020 Tagging support for flow logs You can add tags to your flow logs. March 16, 2020 Tag on NAT gateway creation You can add a tag when you create a NAT gateway. March 9, 2020 Maximum aggregation interval for flow logs Network border group configuration Gateway route tables February 4, 2020 January 22, 2020 December 3, 2019 You can specify the maximum period of time during which a flow is captured and aggregated into a flow log record. You can configure network border groups for your VPCs from the Amazon Virtual Private Cloud Console. You can associate a route table with a gateway and route inbound VPC traffic to a specific network interface in your VPC. 584 Amazon Virtual Private Cloud Flow logs enhancements VPC Sharing Create default subnet User Guide September 11, 2019 November 27, 2018 November 9, 2017 You can specify a custom format for your flow log and choose which fields to return in the flow log records. You can share subnets that are in the same VPC with multiple accounts in the same AWS organization. You can create a default subnet in an Availability Zone that does not have one. Tagging support for NAT gateways You can tag your NAT gateway. September 7, 2017 Amazon CloudWatch metrics for NAT gateways You can view CloudWatch metrics for your NAT gateway. September 7, 2017 Security group rule descripti ons You can add descriptions to your security group rules. August 31, 2017 Secondary IPv4 CIDR blocks for your VPC You can add multiple IPv4 CIDR blocks to your VPC. August 29, 2017 Recover Elastic IP addresses If you release an Elastic IP address, you might be able to August 11, 2017 Create default VPC IPv6 support recover it. You can create a new default VPC if you delete your existing default VPC. You can associate an IPv6 CIDR block with your VPC and assign IPv6 addresses to resources in your VPC. July 27, 2017 December 1, 2016 585 Amazon Virtual Private Cloud User Guide DNS resolution support for non-RFC 1918 IP address The Amazon DNS server can now resolve private October 24, 2016 ranges NAT gateways VPC flow logs ClassicLink Use private hosted zones DNS hostnames to private IP addresses for all address spaces. You can create a NAT gateway in a public subnet and enable instances in a private subnet to initiate outbound traffic to the internet or other AWS services. You can create a flow log to capture information about the IP traffic going to and from network interfaces in your VPC. You can use ClassicLink to link your EC2-Classic instance to a VPC in your
vpc-ug-203
vpc-ug.pdf
203
non-RFC 1918 IP address The Amazon DNS server can now resolve private October 24, 2016 ranges NAT gateways VPC flow logs ClassicLink Use private hosted zones DNS hostnames to private IP addresses for all address spaces. You can create a NAT gateway in a public subnet and enable instances in a private subnet to initiate outbound traffic to the internet or other AWS services. You can create a flow log to capture information about the IP traffic going to and from network interfaces in your VPC. You can use ClassicLink to link your EC2-Classic instance to a VPC in your account. You can associate VPC security groups with the EC2-Classic instance, enabling communica tion between your EC2-Class ic instance and instances in your VPC using private IP addresses. You can access resources in your VPC using custom DNS domain names that you define in a private hosted zone in Route 53. December 17, 2015 June 10, 2015 January 7, 2015 November 5, 2014 586 Amazon Virtual Private Cloud User Guide Modify a subnet's public IP addressing attribute You can modify the public IP addressing attribute of your June 21, 2014 subnet to indicate whether instances launched into that subnet should receive a public IP address. Assigning a public IP address You can assign a public IP address to an instance during August 20, 2013 launch. Enabling DNS hostnames and disabling DNS resolution You can modify VPC defaults and disable DNS resolution March 11, 2013 VPC Everywhere Dedicated Instances and enable DNS hostnames. Added support for VPC in five AWS Regions, VPCs in multiple Availability Zones, multiple VPCs per AWS account,and multiple VPN connections per VPC. Dedicated Instances are Amazon EC2 instances launched within your VPC that run hardware dedicated to a single customer. August 3, 2011 March 27, 2011 587