Aws VPC Guide
Aws VPC Guide
User Guide
Amazon Virtual Private Cloud User Guide
Table of Contents
What is Amazon VPC? ................................................................................................................... 1
Amazon VPC Concepts .......................................................................................................... 1
VPCs and Subnets ........................................................................................................ 1
Supported Platforms ...................................................................................................... 2
Default and Nondefault VPCs .......................................................................................... 2
Accessing the Internet .................................................................................................... 2
Accessing a Corporate or Home Network .......................................................................... 4
How to Get Started with Amazon VPC ....................................................................................... 5
Using Amazon VPC with Other AWS Services ............................................................................ 6
Accessing Amazon VPC ......................................................................................................... 6
Pricing for Amazon VPC ......................................................................................................... 7
Amazon VPC Limits ............................................................................................................... 7
PCI DSS Compliance ............................................................................................................. 7
Getting Started ............................................................................................................................. 8
Step 1: Create the VPC .......................................................................................................... 9
Viewing Information About Your VPC ............................................................................... 10
Step 2: Create a Security Group ............................................................................................. 11
Rules for the WebServerSG Security Group ..................................................................... 11
Creating Your WebServerSG Security Group .................................................................... 12
Step 3: Launch an Instance into Your VPC ................................................................................ 13
Step 4: Assign an Elastic IP Address to Your Instance ................................................................ 14
Step 5: Clean Up ................................................................................................................. 15
VPC Wizard Scenarios for Amazon VPC .......................................................................................... 17
Scenario 1: VPC with a Single Public Subnet ............................................................................ 17
Configuration for Scenario 1 .......................................................................................... 18
Basic Components for Scenario 1 ................................................................................... 18
Routing for Scenario 1 .................................................................................................. 19
Security for Scenario 1 ................................................................................................. 19
Implementing Scenario 1 .............................................................................................. 20
Scenario 2: VPC with Public and Private Subnets (NAT) ............................................................. 22
Configuration for Scenario 2 .......................................................................................... 23
Basic Components for Scenario 2 ................................................................................... 24
Routing for Scenario 2 .................................................................................................. 24
Security for Scenario 2 ................................................................................................. 25
Implementing Scenario 2 .............................................................................................. 27
Implementing Scenario 2 with a NAT Instance .................................................................. 30
Scenario 3: VPC with Public and Private Subnets and Hardware VPN Access ................................ 32
Configuration for Scenario 3 .......................................................................................... 32
Basic Configuration for Scenario 3 .................................................................................. 33
Routing for Scenario 3 .................................................................................................. 33
Security for Scenario 3 ................................................................................................. 35
Implementing Scenario 3 .............................................................................................. 37
Scenario 4: VPC with a Private Subnet Only and Hardware VPN Access ....................................... 41
Configuration for Scenario 4 .......................................................................................... 42
Basic Components for Scenario 4 ................................................................................... 42
Routing for Scenario 4 .................................................................................................. 43
Security for Scenario 4 ................................................................................................. 43
Implementing Scenario 4 .............................................................................................. 44
Your VPC and Subnets ................................................................................................................. 47
Your VPC ........................................................................................................................... 47
Your New VPC ............................................................................................................ 47
VPC Sizing ................................................................................................................. 48
Connections with Your Local Network and Other VPCs ....................................................... 49
Creating a VPC ........................................................................................................... 49
Deleting Your VPC ........................................................................................................ 50
iii
Amazon Virtual Private Cloud User Guide
iv
Amazon Virtual Private Cloud User Guide
v
Amazon Virtual Private Cloud User Guide
vi
Amazon Virtual Private Cloud User Guide
Amazon VPC Concepts
Amazon Virtual Private Cloud (Amazon VPC) enables you to launch Amazon Web Services (AWS)
resources into a virtual network that you've defined. This virtual network closely resembles a traditional
network that you'd operate in your own data center, with the benefits of using the scalable infrastructure
of AWS.
For more information, see Benefits of Using a VPC in the Amazon EC2 User Guide for Linux Instances.
Topics
• Amazon VPC Concepts (p. 1)
• How to Get Started with Amazon VPC (p. 5)
• Using Amazon VPC with Other AWS Services (p. 6)
• Accessing Amazon VPC (p. 6)
• Pricing for Amazon VPC (p. 7)
• Amazon VPC Limits (p. 7)
• PCI DSS Compliance (p. 7)
Amazon VPC is the networking layer for Amazon EC2. If you're new to Amazon EC2, see What is Amazon
EC2? in the Amazon EC2 User Guide for Linux Instances to get a brief overview.
A subnet is a range of IP addresses in your VPC. You can launch AWS resources into a subnet that you
select. Use a public subnet for resources that must be connected to the Internet, and a private subnet
1
Amazon Virtual Private Cloud User Guide
Supported Platforms
for resources that won't be connected to the Internet. For more information about public and private
subnets, see Your VPC with Subnets (p. 51).
To protect the AWS resources in each subnet, you can use multiple layers of security, including security
groups and network access control lists (ACL). For more information, see Security in Your VPC (p. 61).
Supported Platforms
The original release of Amazon EC2 supported a single, flat network that's shared with other customers
called the EC2-Classic platform. Older AWS accounts still support this platform, and can launch instances
into either EC2-Classic or a VPC. Accounts created after 2013-12-04 support EC2-VPC only. For more
information, see Detecting Your Supported Platforms and Whether You Have a Default VPC (p. 58).
Regardless of which platforms your account supports, you can create your own VPC, and configure it as
you need. This is known as a nondefault VPC. Subnets that you create in your nondefault VPC and
additional subnets that you create in your default VPC are called nondefault subnets.
Your default VPC includes an Internet gateway, and each default subnet is a public subnet. Each instance
that you launch into a default subnet has a private IP address and a public IP address. These instances
can communicate with the Internet through the Internet gateway. An Internet gateway enables your
instances to connect to the Internet through the Amazon EC2 network edge.
2
Amazon Virtual Private Cloud User Guide
Accessing the Internet
By default, each instance that you launch into a nondefault subnet has a private IP address, but no public
IP address, unless you specifically assign one at launch, or you modify the subnet's public IP address
attribute. These instances can communicate with each other, but can't access the Internet.
You can enable Internet access for an instance launched into a nondefault subnet by attaching an Internet
gateway to its VPC (if its VPC is not a default VPC) and associating an Elastic IP address with the instance.
3
Amazon Virtual Private Cloud User Guide
Accessing a Corporate or Home Network
Alternatively, to allow an instance in your VPC to initiate outbound connections to the Internet but prevent
unsolicited inbound connections from the Internet, you can use a network address translation (NAT)
device. NAT maps multiple private IP addresses to a single public IP address. A NAT device has an
Elastic IP address and is connected to the Internet through an Internet gateway. You can connect an
instance in a private subnet to the Internet through the NAT device, which routes traffic from the instance
to the Internet gateway, and routes any responses to the instance.
For more information about routing and NAT in your VPC, see Route Tables (p. 126) and NAT (p. 143).
A VPN connection consists of a virtual private gateway attached to your VPC and a customer gateway
located in your data center. A virtual private gateway is the VPN concentrator on the Amazon side of the
VPN connection. A customer gateway is a physical device or software appliance on your side of the VPN
connection.
4
Amazon Virtual Private Cloud User Guide
How to Get Started with Amazon VPC
For more information, see Adding a Hardware Virtual Private Gateway to Your VPC (p. 190).
If you have a default VPC, and you want to get started launching instances into your VPC without
performing any additional configuration on your VPC, see Launching an EC2 Instance into Your Default
VPC (p. 59).
To learn about the basic scenarios for Amazon VPC, see VPC Wizard Scenarios for Amazon VPC (p. 17).
You can configure your VPC and subnets in other ways to suit your needs. For more information about
other scenarios, see Amazon Virtual Private Cloud Connectivity Options.
The following table lists related resources that you'll find useful as you work with this service.
Resource Description
Amazon Virtual Private Cloud Connectiv- A whitepaper that provides an overview of the options for
ity Options network connectivity.
5
Amazon Virtual Private Cloud User Guide
Using Amazon VPC with Other AWS Services
Resource Description
AWS Developer Resources A central starting point to find documentation, code samples,
release notes, and other information to help you create innov-
ative applications with AWS.
AWS Data Pipeline Launching Resources for Your Pipeline into a VPC
To get a detailed view of the VPCs, subnets, and other VPC resources in your account and their relation
to each other, you can use the AWS Config service. For more information, see What is AWS Config? in
the AWS Config Developer Guide.
If you prefer to use a command line interface, you have several options:
6
Amazon Virtual Private Cloud User Guide
Pricing for Amazon VPC
Amazon VPC provides a Query API. These requests are HTTP or HTTPS requests that use the HTTP
verbs GET or POST and a Query parameter named Action. For more information about the API actions
for Amazon VPC, see Actions in the Amazon EC2 API Reference.
If you prefer to build applications using language-specific APIs instead of submitting a request over HTTP
or HTTPS, AWS provides libraries, sample code, tutorials, and other resources for software developers.
These libraries provide basic functions that automatically take care of tasks such as cryptographically
signing your requests, retrying requests, and handling error responses, so that it is easier for you to get
started. For more information about downloading the AWS SDKs, see AWS SDKs and Tools.
7
Amazon Virtual Private Cloud User Guide
In this exercise, you'll create a VPC and subnet, and launch a public-facing instance into your subnet.
Your instance will be able to communicate with the Internet, and you'll be able to access your instance
from your local computer using SSH (if it's a Linux instance) or Remote Desktop (if it's a Windows instance).
In your real world environment, you can use this scenario to create a public-facing web server; for example,
to host a blog.
Note
This exercise is intended to help you set up your own nondefault VPC quickly. If you already
have a default VPC and you want to get started launching instances into it (and not creating or
configuring a new VPC), see Launching an EC2 Instance into Your Default VPC.
• Create a nondefault VPC with a single public subnet. Subnets enable you to group instances based
on your security and operational needs. A public subnet is a subnet that has access to the Internet
through an Internet gateway.
• Create a security group for your instance that allows traffic only through specific ports.
• Launch an Amazon EC2 instance into your subnet.
• Associate an Elastic IP address with your instance. This allows your instance to access the Internet.
Before you can use Amazon VPC for the first time, you must sign up for Amazon Web Services (AWS).
When you sign up, your AWS account is automatically signed up for all services in AWS, including Amazon
VPC. If you haven't created an AWS account already, go to http://aws.amazon.com, and then choose
Create a Free Account.
Note
This exercise assumes that your account supports the EC2-VPC platform only. If your account
also supports the older EC2-Classic platform, you can still follow the steps in this exercise;
however, you will not have a default VPC in your account to compare against your nondefault
VPC. For more information, see Supported Platforms.
Contents
• Step 1: Create the VPC (p. 9)
• Step 2: Create a Security Group (p. 11)
• Step 3: Launch an Instance into Your VPC (p. 13)
• Step 4: Assign an Elastic IP Address to Your Instance (p. 14)
• Step 5: Clean Up (p. 15)
8
Amazon Virtual Private Cloud User Guide
Step 1: Create the VPC
• Creates a VPC with a /16 CIDR block (a network with 65,536 private IP addresses). For more information
about CIDR notation and the sizing of a VPC, see Your VPC.
• Attaches an Internet gateway to the VPC. For more information about Internet gateways, see Internet
Gateways.
• Creates a size /24 subnet (a range of 256 private IP addresses) in the VPC.
• Creates a custom route table, and associates it with your subnet, so that traffic can flow between the
subnet and the Internet gateway. For more information about route tables, see Route Tables.
The following diagram represents the architecture of your VPC after you've completed this step.
Note
This exercise covers the first scenario in the VPC wizard. For more information about the other
scenarios, see Scenarios for Amazon VPC.
9
Amazon Virtual Private Cloud User Guide
Viewing Information About Your VPC
Note
Do not choose Your VPCs in the navigation pane; you cannot access the VPC wizard from
this page.
4. Choose the first option, VPC with a Single Public Subnet, and then choose Select.
5. On the configuration page, enter a name for your VPC in the VPC name field; for example, my-vpc,
and enter a name for your subnet in the Subnet name field. This helps you to identify the VPC and
subnet in the Amazon VPC console after you've created them. For this exercise, you can leave the
rest of the configuration settings on the page, and choose Create VPC.
(Optional) If you prefer, you can modify the configuration settings as follows, and then choose Create
VPC.
• The IP CIDR block displays the IP address range that you'll use for your VPC (10.0.0.0/16),
and the Public subnet field displays the IP address range you'll use for the subnet (10.0.0.0/24).
If you don't want to use the default CIDR ranges, you can specify your own. For more information,
see VPC Sizing and Subnet Sizing.
• The Availability Zone list enables you to select the Availability Zone in which to create the subnet.
You can leave No Preference to let AWS choose an Availability Zone for you. For more information,
see Regions and Availability Zones.
• In the Add endpoints for S3 to your subnets section, you can select a subnet in which to create
a VPC endpoint to Amazon S3 in the same region. For more information, see VPC Endpoints.
• The Enable DNS hostnames option, when set to Yes, ensures that instances that are launched
into your VPC receive a DNS hostname. For more information, see Using DNS with Your VPC.
• The Hardware tenancy option enables you to select whether instances launched into your VPC
are run on shared or dedicated hardware. Selecting a dedicated tenancy incurs additional costs.
For more information about hardware tenancy, see Dedicated Instances.
6. A status window shows the work in progress. When the work completes, choose OK to close the
status window.
7. The Your VPCs page displays your default VPC and the VPC that you just created. The VPC that
you created is a nondefault VPC, therefore the Default VPC column displays No.
10
Amazon Virtual Private Cloud User Guide
Step 2: Create a Security Group
• The first row in the table is the local route, which enables instances within the VPC to communicate.
This route is present in every route table by default, and you can't remove it.
• The second row shows the route that the Amazon VPC wizard added to enable traffic destined for
an IP address outside the VPC (0.0.0.0/0) to flow from the subnet to the Internet gateway.
6. Select the main route table. The main route table has a local route, but no other routes.
Your VPC comes with a default security group. Any instance not associated with another security group
during launch is associated with the default security group. In this exercise, you'll create a new security
group, WebServerSG, and specify this security group when you launch an instance into your VPC.
Topics
• Rules for the WebServerSG Security Group (p. 11)
• Creating Your WebServerSG Security Group (p. 12)
Inbound
11
Amazon Virtual Private Cloud User Guide
Creating Your WebServerSG Security Group
Public IP address TCP 3389 Allows inbound RDP access from your
range of your home network to a Windows instance.
home network
Outbound
0.0.0.0/0 All All The default outbound rule that allows all
outbound communication.
a. Select HTTP from the Type list, and enter 0.0.0.0/0 in the Source field.
b. Choose Add another rule, then select HTTPS from the Type list, and enter 0.0.0.0/0 in the
Source field.
c. Choose Add another rule. If you're launching a Linux instance, select SSH from the Type list,
or if you're launching a Windows instance, select RDP from the Type list. Enter your network's
public IP address range in the Source field. If you don't know this address range, you can use
0.0.0.0/0 for this exercise.
Caution
If you use 0.0.0.0/0, you enable all IP addresses to access your instance using SSH
or RDP. This is acceptable for the short exercise, but it's unsafe for production
environments. In production, you'll authorize only a specific IP address or range of
addresses to access your instance.
12
Amazon Virtual Private Cloud User Guide
Step 3: Launch an Instance into Your VPC
The following diagram represents the architecture of your VPC after you've completed this step.
13
Amazon Virtual Private Cloud User Guide
Step 4: Assign an Elastic IP Address to Your Instance
you selected. You can leave the default selection, and then choose Next: Configure Instance
Details.
6. On the Configure Instance Details page, select the VPC that you created from the Network list,
and the subnet from the Subnet list. Leave the rest of the default settings, and go through the next
pages of the wizard until you get to the Tag Instance page.
7. On the Tag Instance page, you can tag your instance with a Name tag; for example
Name=MyWebServer. This helps you to identify your instance in the Amazon EC2 console after
you've launched it. Choose Next: Configure Security Group when you are done.
8. On the Configure Security Group page, the wizard automatically defines the launch-wizard-x
security group to allow you to connect to your instance. Instead, choose the Select an existing
security group option, select the WebServerSG group that you created previously, and then choose
Review and Launch.
9. On the Review Instance Launch page, check the details of your instance, and then choose Launch.
10. In the Select an existing key pair or create a new key pair dialog box, you can choose an existing
key pair, or create a new one. If you create a new key pair, ensure that you download the file and
store it in a secure location. You'll need the contents of the private key to connect to your instance
after it's launched.
To launch your instance, select the acknowledgment check box, and then choose Launch Instances.
11. On the confirmation page, choose View Instances to view your instance on the Instances page.
Select your instance, and view its details in the Description tab. The Private IPs field displays the
private IP address that's assigned to your instance from the range of IP addresses in your subnet.
For more information about the options available in the Amazon EC2 launch wizard, see Launching an
Instance in the Amazon EC2 User Guide for Linux Instances.
The following diagram represents the architecture of your VPC after you've completed this step.
14
Amazon Virtual Private Cloud User Guide
Step 5: Clean Up
Your instance is now accessible from the Internet. You can connect to your instance through its Elastic
IP address using SSH or Remote Desktop from your home network. For more information about how to
connect to a Linux instance, see Connecting to Your Linux Instance in the Amazon EC2 User Guide for
Linux Instances. For more information about how to connect to a Windows instance, see Connect to Your
Windows Instance Using RDP in the Amazon EC2 User Guide for Microsoft Windows Instances.
This completes the exercise; you can choose to continue using your instance in your VPC, or if you do
not need the instance, you can terminate it and release its Elastic IP address to avoid incurring charges
for them.You can also delete your VPC — note that you are not charged for the VPC and VPC components
created in this exercise (such as the subnets and route tables).
Step 5: Clean Up
Before you can delete a VPC, you must terminate any instances that are running in the VPC. If you delete
a VPC using the VPC console, it also deletes resources that are associated with the VPC, such as subnets,
security groups, network ACLs, DHCP options sets, route tables, and Internet gateways.
To terminate your instance, release your Elastic IP address, and delete your VPC
15
Amazon Virtual Private Cloud User Guide
Step 5: Clean Up
16
Amazon Virtual Private Cloud User Guide
Scenario 1: VPC with a Single Public Subnet
This section describes how to use the VPC wizard to create basic scenarios for Amazon VPC. Each
scenario includes the following information:
Scenario Usage
Scenario 1: VPC with a Single Run a single-tier, public-facing web application such as a blog or
Public Subnet (p. 17) simple web site.
Scenario 2: VPC with Public and Run a public-facing web application, while still maintaining non-pub-
Private Subnets (NAT) (p. 22) licly accessible back-end servers in a second subnet.
Scenario 3: VPC with Public and Extend your data center into the cloud, and also directly access the
Private Subnets and Hardware Internet from your VPC.
VPN Access (p. 32)
Scenario 4: VPC with a Private Extend your data center into the cloud, and leverage Amazon's infra-
Subnet Only and Hardware VPN structure without exposing your network to the Internet.
Access (p. 41)
17
Amazon Virtual Private Cloud User Guide
Configuration for Scenario 1
Topics
• Configuration for Scenario 1 (p. 18)
• Basic Components for Scenario 1 (p. 18)
• Routing for Scenario 1 (p. 19)
• Security for Scenario 1 (p. 19)
• Implementing Scenario 1 (p. 20)
Note
If you completed the exercise Getting Started with Amazon VPC (p. 8), then you've already
implemented this scenario using the VPC wizard in the Amazon VPC console.
• A virtual private cloud (VPC) of size /16 (example CIDR: 10.0.0.0/16). This provides 65,536 private IP
addresses.
• A subnet of size /24 (example CIDR: 10.0.0.0/24). This provides 256 private IP addresses.
• An Internet gateway. This connects the VPC to the Internet and to other AWS products.
• An instance with a private IP address in the subnet range (example: 10.0.0.6), which enables the
instance to communicate with other instances in the VPC, and an Elastic IP address (example:
198.51.100.2), which enables the instance to be reached from the Internet.
18
Amazon Virtual Private Cloud User Guide
Routing for Scenario 1
• A route table entry that enables instances in the subnet to communicate with other instances in the
VPC, and a route table entry that enables instances in the subnet to communicate directly over the
Internet.
For more information about subnets, see Your VPC and Subnets (p. 47) and IP Addressing in Your
VPC (p. 120). For more information about Internet gateways, see Internet Gateways (p. 138).
Tip
If you'd like instances in your VPC to communicate over the Internet without having to assign
each instance an Elastic IP address, you can use a NAT gateway. For more information about
configuring a VPC with a NAT gateway, see Scenario 2: VPC with Public and Private Subnets
(NAT) (p. 22).
The following table shows what the route table looks like for the example addresses used in the
configuration diagram for this scenario. The first row shows the entry for local routing in the VPC; this
entry enables the instances in this VPC to communicate with each other. The second row shows the entry
for routing all other subnet traffic to the Internet gateway, which is specified using its AWS-assigned
identifier.
Destination Target
10.0.0.0/16 local
0.0.0.0/0 igw-xxxxxxxx
For scenario 1, you'll use a security group but not network ACLs. If you'd like to use a network ACL, see
Recommended Rules for Scenario 1 (p. 81).
19
Amazon Virtual Private Cloud User Guide
Implementing Scenario 1
You'll create a security group named WebServerSG, modify the rules as needed, and then specify the
security group when you launch instances into the VPC. By default, new security groups start with only
an outbound rule that allows all traffic to leave the instances. You must add rules to enable any inbound
traffic or to restrict the outbound traffic.
The following table describes the inbound and outbound rules for the WebServerSG group. If you want
your web server to initiate outbound traffic, for example, to get software updates, you can leave the default
outbound rule. If you do not want your web server to initiate outbound traffic, you can remove the default
outbound rule.
Inbound
Public IP address range of your TCP 22 (Linux instances) Allow inbound SSH
network access from your network
Public IP address range of your TCP 3389 (Windows instances) Allow inbound
network RDP access from your network
Outbound (Optional)
Tip
You can also get the public IP address of your local computer using a service. To locate a service
that provides your IP address, use the search phrase "what is my IP address". If you are
connecting through an ISP or from behind a firewall without a static IP address, you need to find
the range of IP addresses used by client computers.
The default security group for a VPC has rules that automatically allow assigned instances to communicate
with each other. To allow that type of communication between the instances in your VPC, you must add
a rule like the following to your security groups.
Inbound
The security group ID All All Allow inbound traffic from other in-
(sg-xxxxxxxx) stances assigned to this security group
Implementing Scenario 1
Use the following process to implement the scenario using the VPC wizard.
20
Amazon Virtual Private Cloud User Guide
Implementing Scenario 1
• Select HTTP from the Type list, and enter 0.0.0.0/0 in the Source field.
• Choose Add another rule, then select HTTPS from the Type list, and enter 0.0.0.0/0 in
the Source field.
• Choose Add another rule, then select SSH from the Type list. Enter your network's public
IP address range in the Source field. (If you don't know this address range, you can use
0.0.0.0/0 for testing purposes; in production, you'll authorize only a specific IP address or
range of addresses to access your instance.)
Tip
If you use both Linux and Windows instances, you can add access for both SSH and
RDP.
• Choose Save.
g. (Optional) On the Outbound Rules tab, choose Edit. Locate the default rule that enables all
outbound traffic, choose Remove, and then choose Save.
21
Amazon Virtual Private Cloud User Guide
Scenario 2: VPC with Public and Private Subnets (NAT)
4. If you did not assign a public IP address to your instance as part of step 3, you will not be able to
connect to it. Assign an Elastic IP address to the instance:
You can now connect to your instances in the VPC. For information about how to connect to a Linux
instance, see Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances. For
information about how to connect to a Windows instance, see Connect to Your Windows Instance in the
Amazon EC2 User Guide for Microsoft Windows Instances.
22
Amazon Virtual Private Cloud User Guide
Configuration for Scenario 2
The instances in the public subnet can receive inbound traffic directly from the Internet, whereas the
instances in the private subnet can't. The instances in the public subnet can send outbound traffic directly
to the Internet, whereas the instances in the private subnet can't. Instead, the instances in the private
subnet can access the Internet by using a network address translation (NAT) gateway that resides in the
public subnet. The database servers can connect to the Internet for software updates using the NAT
gateway, but the Internet cannot initiate connections to the database servers.
Note
You can also use the VPC wizard to configure a VPC with a NAT instance; however, we
recommend that you use a NAT gateway. For more information, see NAT Gateways (p. 144).
Topics
• Configuration for Scenario 2 (p. 23)
• Basic Components for Scenario 2 (p. 24)
• Routing for Scenario 2 (p. 24)
• Security for Scenario 2 (p. 25)
• Implementing Scenario 2 (p. 27)
• Implementing Scenario 2 with a NAT Instance (p. 30)
23
Amazon Virtual Private Cloud User Guide
Basic Components for Scenario 2
• A virtual private cloud (VPC) of size /16 (example CIDR: 10.0.0.0/16). This provides 65,536 private IP
addresses.
• A public subnet of size /24 (example CIDR: 10.0.0.0/24). This provides 256 private IP addresses.
• A private subnet of size /24 (example CIDR: 10.0.1.0/24). This provides 256 private IP addresses.
• An Internet gateway. This connects the VPC to the Internet and to other AWS products.
• Instances with private IP addresses in the subnet range (examples: 10.0.0.5, 10.0.1.5), which enables
them to communicate with each other and other instances in the VPC. Instances in the public subnet
also have Elastic IP addresses (example: 198.51.100.1), which enable them to be reached from the
Internet.The instances can have public IP addresses assigned at launch instead of Elastic IP addresses.
Instances in the private subnet are back-end servers that don't need to accept incoming traffic from
the Internet; however, they can send requests to the Internet using the NAT gateway (see the next
bullet).
• A NAT gateway with its own Elastic IP address. This enables instances in the private subnet to send
requests to the Internet (for example, for software updates).
• A route table associated with the public subnet. This route table contains an entry that enables instances
in the subnet to communicate with other instances in the VPC, and an entry that enables instances in
the subnet to communicate directly with the Internet.
• The main route table associated with the private subnet. The route table contains an entry that enables
instances in the subnet to communicate with other instances in the VPC, and an entry that enables
instances in the subnet to communicate with the Internet through the NAT gateway.
For more information about subnets, see Your VPC and Subnets (p. 47) and IP Addressing in Your
VPC (p. 120). For more information about Internet gateways, see Internet Gateways (p. 138). For more
information about NAT gateways, see NAT Gateways (p. 144).
Tip
To help manage the instances in the private subnet, you can set up bastion servers in the public
subnet to act as proxies. For example, you can set up SSH port forwarders or RDP gateways
in the public subnet to proxy the traffic going to your database servers from your own network.
In this scenario, all traffic from each subnet that is bound for AWS (for example, to the Amazon EC2 or
Amazon S3 endpoints) goes over the Internet gateway. The database servers in the private subnet can't
receive traffic from the Internet directly because they don't have Elastic IP addresses. However, the
database servers can send and receive Internet traffic through the NAT device in the public subnet.
Any additional subnets that you create use the main route table by default, which means that they are
private subnets by default. If you'd like to make a subnet public, you can always change the route table
that it's associated with.
The following tables describe the route tables for this scenario.
24
Amazon Virtual Private Cloud User Guide
Security for Scenario 2
The first row describes the entry for local routing in the VPC; this entry enables the instances in the VPC
to communicate with each other. The second row describes the entry that sends all other subnet traffic
to the NAT gateway.
Destination Target
10.0.0.0/16 local
0.0.0.0/0 nat-gateway-id
The first row describes the entry for local routing in the VPC; this entry enables the instances in this VPC
to communicate with each other. The second row describes the entry for routing all other subnet traffic
to the Internet over the Internet gateway, which is specified using its AWS-assigned identifier (for example,
igw-1a2b3d4d).
Destination Target
10.0.0.0/16 local
0.0.0.0/0 igw-id
For scenario 2, you'll use security groups but not network ACLs. If you'd like to use a network ACL, see
Recommended Rules for Scenario 2 (p. 82).
For this scenario, we recommend that you create the following security groups instead of modifying the
default security group:
The instances assigned to a security group can be in different subnets. However, in this scenario, each
security group corresponds to the type of role an instance plays, and each role requires the instance to
be in a particular subnet. Therefore, in this scenario, all instances assigned to a security group are in the
same subnet.
25
Amazon Virtual Private Cloud User Guide
Security for Scenario 2
The WebServerSG security group is the security group that you specify when you launch your web servers
into your public subnet. The following table describes the recommended rules for this security group,
which allow the web servers to receive Internet traffic, as well as SSH and RDP traffic from your network.
The web servers can also initiate read and write requests to the database servers in the private subnet,
and send traffic to the Internet; for example, to get software updates. Because the web server doesn't
initiate any other outbound communication, the default outbound rule is removed.
Note
These recommendations include both SSH and RDP access, and both Microsoft SQL Server
and MySQL access. For your situation, you might only need rules for Linux (SSH and MySQL)
or Windows (RDP and Microsoft SQL Server).
Inbound
Your home network's public IP TCP 22 Allow inbound SSH access to Linux
address range instances from your home network
(over the Internet gateway)
Your home network's public IP TCP 3389 Allow inbound RDP access to Win-
address range dows instances from your home net-
work (over the Internet gateway)
Outbound
The ID of your DBServerSG se- TCP 1433 Allow outbound Microsoft SQL Server
curity group access to the database servers as-
signed to DBServerSG
The ID of your DBServerSG se- TCP 3306 Allow outbound MySQL access to the
curity group database servers assigned to DB-
ServerSG
The DBServerSG security group is the security group that you'll specify when you launch your database
servers into your private subnet. The following table describes the recommended rules for this security
group, which allow read or write database requests from the web servers. The database servers can also
initiate traffic bound for the Internet (your route table sends that traffic to the NAT gateway, which then
forwards it to the Internet over the Internet gateway).
Inbound
26
Amazon Virtual Private Cloud User Guide
Implementing Scenario 2
The ID of your WebServerSG TCP 1433 Allow web servers assigned to Web-
security group ServerSG Microsoft SQL Server ac-
cess to database servers assigned to
DBServerSG
The ID of your WebServerSG TCP 3306 Allow web servers assigned to Web-
security group ServerSG MySQL access to database
servers assigned to DBServerSG
Outbound
The default security group for a VPC has rules that automatically allow assigned instances to communicate
with each other. To allow that type of communication between instances in your VPC when you use a
different security group, you must add a rule like the following to your security groups.
Inbound
The ID of the security group All All Allow inbound traffic from other in-
stances assigned to this security group
Implementing Scenario 2
You can use the VPC wizard to create the VPC, subnets, and NAT gateway for scenario 2. If you want
to use an existing Elastic IP address for your NAT gateway, ensure that it's not currently associated with
another instance or network interface. The NAT gateway is automatically created in the public subnet of
your VPC.
Because the WebServerSG and DBServerSG security groups reference each other, create all the security
groups required for this scenario before you add rules to them.
27
Amazon Virtual Private Cloud User Guide
Implementing Scenario 2
1. Select the WebServerSG security group that you created. The details pane displays the details for
the security group, plus tabs for working with its inbound and outbound rules.
2. On the Inbound Rules tab, choose Edit and add rules for inbound traffic as follows:
3. On the Outbound Rules tab, choose Edit and add rules for outbound traffic as follows:
a. Locate the default rule that enables all outbound traffic and choose Remove.
b. Choose Type, MS SQL. For Destination, specify the ID of the DBServerSG security group.
c. Choose Add another rule, Type, MySQL. For Destination, specify the ID of the DBServerSG
security group.
d. Choose Add another rule, Type, HTTPS. For Destination, enter 0.0.0.0/0.
e. Choose Add another rule, Type, HTTP. For Destination, enter 0.0.0.0/0.
f. Choose Save.
28
Amazon Virtual Private Cloud User Guide
Implementing Scenario 2
1. Select the DBServerSG security group that you created. The details pane displays the details for the
security group, plus tabs for working with its inbound and outbound rules.
2. On the Inbound Rules tab, choose Edit and add rules for inbound traffic as follows:
a. Choose Type, MS SQL. For Source, specify the ID of your WebServerSG security group.
b. Choose Add another rule, Type, MYSQL. For Source, specify the ID of your WebServerSG
security group.
c. Choose Save.
3. On the Outbound Rules tab, choose Edit and add rules for outbound traffic as follows:
a. Locate the default rule that enables all outbound traffic and choose Remove.
b. Choose Type, HTTP. For Destination, enter 0.0.0.0/0.
c. Choose Add another rule, Type, HTTPS. For Destination, enter 0.0.0.0/0.
d. Choose Save.
If you did not assign a public IP address to your instance in the public subnet in step 5, you will not be
able to connect to it. Before you can access an instance in your public subnet, you must assign it an
Elastic IP address.
29
Amazon Virtual Private Cloud User Guide
Implementing Scenario 2 with a NAT Instance
You can now connect to your instances in the VPC. For information about how to connect to a Linux
instance, see Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances. For
information about how to connect to a Windows instance, see Connect to Your Windows Instance in the
Amazon EC2 User Guide for Microsoft Windows Instances.
You can follow the same procedures as above; however, in the NAT section of the VPC wizard, choose
Use a NAT instance instead and specify the details for your NAT instance.You will also require a security
group for your NAT instance (NATSG), which allows the 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, so that instances in the private subnet can get software updates.
After you've created the VPC with the NAT instance, you must change the security group associated with
the NAT instance to the new NATSG security group (by default, the NAT instance is launched using the
default security group).
Inbound
Your network's public IP address TCP 22 Allow inbound SSH access to the NAT
range instance from your network (over the
Internet gateway)
Outbound
30
Amazon Virtual Private Cloud User Guide
Implementing Scenario 2 with a NAT Instance
a. Choose Type, HTTP . For Source, enter the IP address range of your private subnet.
b. Choose Add another rule, Type, HTTPS. For Source, enter the IP address range of your
private subnet.
c. Choose Add another rule, Type, SSH. For Source, enter your network's public IP address
range.
d. Choose Save.
6. On the Outbound Rules tab, choose Edit and add rules for outbound traffic as follows:
a. Locate the default rule that enables all outbound traffic and choose Remove.
b. Choose Type, HTTP. For Destination, enter 0.0.0.0/0.
c. Choose Add another rule, Type, HTTPS. For Destination, enter 0.0.0.0/0.
d. Choose Save.
When the VPC wizard launched the NAT instance, it used the default security group for the VPC. You
need to associate the NAT instance with the NATSG security group instead.
31
Amazon Virtual Private Cloud User Guide
Scenario 3: VPC with Public and Private Subnets and
Hardware VPN Access
Topics
• Configuration for Scenario 3 (p. 32)
• Basic Configuration for Scenario 3 (p. 33)
• Routing for Scenario 3 (p. 33)
• Security for Scenario 3 (p. 35)
• Implementing Scenario 3 (p. 37)
32
Amazon Virtual Private Cloud User Guide
Basic Configuration for Scenario 3
Important
For this scenario, the Amazon VPC Network Administrator Guide describes what your network
administrator needs to do to configure the Amazon VPC customer gateway on your side of the
VPN connection.
• A virtual private cloud (VPC) of size /16 (example CIDR: 10.0.0.0/16). This provides 65,536 private IP
addresses.
• A public subnet of size /24 (example CIDR: 10.0.0.0/24). This provides 256 private IP addresses.
• A VPN-only subnet of size /24 (example CIDR: 10.0.1.0/24). This provides 256 private IP addresses.
• An Internet gateway. This connects the VPC to the Internet and to other AWS products.
• A VPN connection between your VPC and your network. The VPN connection consists of a virtual
private gateway located on the Amazon side of the VPN connection and a customer gateway located
on your side of the VPN connection.
• Instances with private IP addresses in the subnet range (examples: 10.0.0.5 and 10.0.1.5), which
enables the instances to communicate with each other and other instances in the VPC. Instances in
the public subnet also have Elastic IP addresses (example: 198.51.100.1), which enables them to be
reached from the Internet. The instances can have public IP addresses assigned at launch instead of
Elastic IP addresses. Instances in the VPN-only subnet are back-end servers that don't need to accept
incoming traffic from the Internet, but can send and receive traffic from your network.
• A custom route table associated with the public subnet. This route table contains an entry that enables
instances in the subnet to communicate with other instances in the VPC, and an entry that enables
instances in the subnet to communicate directly with the Internet.
• The main route table associated with the VPN-only subnet. The route table contains an entry that
enables instances in the subnet to communicate with other instances in the VPC, and an entry that
enables instances in the subnet to communicate directly with your network.
For more information about subnets, see Your VPC and Subnets (p. 47) and IP Addressing in Your
VPC (p. 120). For more information about Internet gateways, see Internet Gateways (p. 138). For more
information about your VPN connection, see Adding a Hardware Virtual Private Gateway to Your
VPC (p. 190). For more information about configuring a customer gateway, see the Amazon VPC Network
Administrator Guide.
The instances in the VPN-only subnet can't reach the Internet directly; any Internet-bound traffic must
first traverse the virtual private gateway to your network, where the traffic is then subject to your firewall
and corporate security policies. If the instances send any AWS-bound traffic (for example, requests to
the Amazon S3 or Amazon EC2 APIs), the requests must go over the virtual private gateway to your
network and then egress to the Internet before reaching AWS.
Tip
Any traffic from your network going to an Elastic IP address for an instance in the public subnet
goes over the Internet, and not over the virtual private gateway. You could instead set up a route
and security group rules that enable the traffic to come from your network over the virtual private
gateway to the public subnet.
33
Amazon Virtual Private Cloud User Guide
Routing for Scenario 3
The following tables describe the route tables for this scenario.
The first row describes the entry for local routing in the VPC; this entry enables the instances in the VPC
to communicate with each other. The second row describes the entry for routing all other subnet traffic
from the private subnet to your network over the virtual private gateway, which is specified using its
AWS-assigned identifier (for example, vgw-1a2b3c4d).
Destination Target
10.0.0.0/16 local
0.0.0.0/0 vgw-xxxxxxxx
The first row describes the entry for local routing in the VPC; this entry enables the instances in the VPC
to communicate with each other. The second row describes the entry for routing all other subnet traffic
from the public subnet to the Internet over the Internet gateway, which is specified using its AWS-assigned
identifier (for example, igw-1a2b3c4d).
Destination Target
10.0.0.0/16 local
0.0.0.0/0 igw-xxxxxxxx
Alternate Routing
Alternatively, if you want instances in the private subnet to access the Internet, you could set up the
routing so that the Internet-bound traffic for the subnet goes to a network address translation (NAT)
gateway or instance in the public subnet. The NAT device enables the instances in the VPN-only subnet
to send requests over the Internet gateway (for example, for software updates). To enable the private
subnet's Internet-bound traffic to go to the NAT device, you must update the main route table as follows.
The first row describes the entry for local routing in the VPC. The second row describes the entry for
routing the subnet traffic bound for your customer network (in this case, 172.16.0.0/12) to the virtual
private gateway, which is specified using its AWS-assigned identifier (for example, vgw-1a2b3c4d). The
third row sends all other subnet traffic to a NAT gateway, which is specified by its AWS-assigned identifier
(for example, nat-12345678901234567).
Destination Target
10.0.0.0/16 local
172.16.0.0/12 vgw-xxxxxxxx
0.0.0.0/0 nat-xxxxxxxxxxxxxxxxx
34
Amazon Virtual Private Cloud User Guide
Security for Scenario 3
For information about setting up a NAT device manually, see NAT (p. 143). For information about using
the VPC wizard to set up a NAT device, see Scenario 2: VPC with Public and Private Subnets
(NAT) (p. 22).
For scenario 3, you'll use security groups but not network ACLs. If you'd like to use a network ACL, see
Recommended Rules for Scenario 3 (p. 85).
Topics
• Recommended Security Groups (p. 35)
For this scenario, we recommend that you create the following security groups instead of modifying the
default security group:
The instances assigned to a security group can be in different subnets. However, in this scenario, each
security group corresponds to the type of role an instance plays, and each role requires the instance to
be in a particular subnet. Therefore, in this scenario, all instances assigned to a security group are in the
same subnet.
The WebServerSG security group is the security group that you'll specify when you launch your web
servers into your public subnet. The following table describes the recommended rules for this security
group, which allow the web servers to receive Internet traffic, as well as SSH and RDP traffic from your
network. The web servers can also initiate read and write requests to the database servers in the VPN-only
subnet, and send traffic to the Internet; for example, to get software updates. Because the web server
doesn't initiate any other outbound communication, the default outbound rule is removed.
Note
The group includes both SSH and RDP access, and both Microsoft SQL Server and MySQL
access. For your situation, you might only need rules for Linux (SSH and MySQL) or Windows
(RDP and Microsoft SQL Server).
Inbound
35
Amazon Virtual Private Cloud User Guide
Security for Scenario 3
Your network's public IP address TCP 22 Allow inbound SSH access to Linux
range instances from your network (over the
Internet gateway)
Your network's public IP address TCP 3389 Allow inbound RDP access to Win-
range dows instances from your network
(over the Internet gateway)
Outbound
The ID of your DBServerSG se- TCP 1433 Allow outbound Microsoft SQL Server
curity group access to the database servers as-
signed to DBServerSG
The ID of your DBServerSG se- TCP 3306 Allow outbound MySQL access to the
curity group database servers assigned to DB-
ServerSG
The DBServerSG security group is the security group that you'll specify when you launch your database
servers into your VPN-only subnet. The following table describes the recommended rules for this security
group, which allow Microsoft SQL Server and MySQL read and write requests from the web servers and
SSH and RDP traffic from your network. The database servers can also initiate traffic bound for the
Internet (your route table sends that traffic over the virtual private gateway).
Inbound
The ID of your WebServerSG TCP 1433 Allow web servers assigned to Web-
security group ServerSG Microsoft SQL Server ac-
cess to database servers assigned to
DBServerSG
The ID of your WebServerSG TCP 3306 Allow web servers assigned to Web-
security group ServerSG MySQL access to database
servers assigned to DBServerSG
Your network's IP address range TCP 22 Allow inbound SSH traffic to Linux in-
stances from your network (over the
virtual private gateway)
Your network's IP address range TCP 3389 Allow inbound RDP traffic to Windows
instances from your network (over the
virtual private gateway)
36
Amazon Virtual Private Cloud User Guide
Implementing Scenario 3
Outbound
The default security group for a VPC has rules that automatically allow assigned instances to communicate
with each other. To allow that type of communication between instances in your VPC when you use a
different security group, you must add a rule like the following to your security groups.
Inbound
The ID of the security group All All Allow inbound traffic from other in-
stances assigned to this security group
Implementing Scenario 3
Use the following process to implement scenario 3 using the VPC wizard.
1. Determine the appliance you'll use as your customer gateway. For more information about the devices
that we've tested, see Amazon Virtual Private Cloud FAQs. For more information about the
requirements for your customer gateway, see the Amazon VPC Network Administrator Guide.
2. Obtain the Internet-routable IP address for the customer gateway's external interface. The address
must be static and may be behind a device performing network address translation (NAT).
3. Gather the list of internal IP ranges (in CIDR notation) that should be advertised across the VPN
connection to the virtual private gateway (if you are using a statically routed VPN connection). For
more information, see VPN Routing Options (p. 192).
• In Customer Gateway IP, specify the public IP address of your VPN router.
• Optionally specify a name for your customer gateway and VPN connection.
• In Routing Type, select one of the routing options as follows:
• If your VPN router supports Border Gateway Protocol (BGP), select Dynamic (requires BGP).
37
Amazon Virtual Private Cloud User Guide
Implementing Scenario 3
• If your VPN router does not support BGP, choose Static. In IP Prefix, add each IP prefix for
your network.
For more information about which option to choose, see Amazon Virtual Private Cloud FAQs. For
more information about dynamic versus static routing, see VPN Routing Options (p. 192).
6. When the wizard is done, choose VPN Connections in the navigation pane. Select the VPN
connection that the wizard created, and choose Download Configuration. In the dialog box, select
the vendor for the customer gateway, the platform, and the software version, and then choose Yes,
Download.
7. Save the text file containing the VPN configuration and give it to the network administrator along with
this guide: Amazon VPC Network Administrator Guide. The VPN won't work until the network
administrator configures the customer gateway.
Because the WebServerSG and DBServerSG security groups reference each other, create all the security
groups required for this scenario before you add rules to them.
1. Select the WebServerSG security group that you created. The details pane displays the details for
the security group, plus tabs for working with its inbound and outbound rules.
2. On the Inbound Rules tab, choose Edit and add rules for inbound traffic as follows:
a. Select HTTP from the Type list, and enter 0.0.0.0/0 in the Source field.
b. Choose Add another rule, then select HTTPS from the Type list, and enter 0.0.0.0/0 in the
Source field.
c. Choose Add another rule, then select SSH from the Type list. Enter your network's public IP
address range in the Source field.
d. Choose Add another rule, then select RDP from the Type list. Enter your network's public IP
address range in the Source field.
e. Choose Save.
38
Amazon Virtual Private Cloud User Guide
Implementing Scenario 3
3. On the Outbound Rules tab, choose Edit and add rules for outbound traffic as follows:
a. Locate the default rule that enables all outbound traffic, and then choose Remove.
b. Select MS SQL from the Type list. In the Destination field, specify the ID of the DBServerSG
security group.
c. Choose Add another rule, then select MySQL from the Type list. In the Destination field,
specify the ID of the DBServerSG security group.
d. Choose Add another rule, then select HTTPS from the Type list. In the Destination field, enter
0.0.0.0/0.
e. Choose Add another rule, then select HTTP from the Type list. In the Destination field, enter
0.0.0.0/0.
f. Choose Save.
1. Select the DBServerSG security group that you created. The details pane displays the details for the
security group, plus tabs for working with its inbound and outbound rules.
2. On the Inbound Rules tab, choose Edit and add rules for inbound traffic as follows:
a. Select SSH from the Type list, and enter the IP address range of your network in the Source
field.
b. Choose Add another rule, then select RDP from the Type list, and enter the IP address range
of your network in the Source field.
c. Choose Add another rule, then select MS SQL from the Type list. Specify the ID of your
WebServerSG security group in the Source field.
d. Choose Add another rule, then select MYSQL from the Type list. Specify the ID of your
WebServerSG security group in the Source field.
e. Choose Save.
3. On the Outbound Rules tab, choose Edit and add rules for outbound traffic as follows:
a. Locate the default rule that enables all outbound traffic, and then choose Remove.
b. Select HTTP from the Type list. In the Destination field, enter 0.0.0.0/0.
c. Choose Add another rule, then select HTTPS from the Type list. In the Destination field, enter
0.0.0.0/0.
d. Choose Save.
39
Amazon Virtual Private Cloud User Guide
Implementing Scenario 3
After your network administrator configures your customer gateway, you can launch instances into your
VPC. If you're already familiar with launching instances outside a VPC, then you already know most of
what you need to know to launch an instance into a VPC.
1. Create the WebServerSG and DBServerSG security groups if you haven't done so already (see
Security for Scenario 3 (p. 35)). You'll specify one of these security groups when you launch the
instance.
2. Start the launch wizard:
3. Follow the directions in the wizard. Choose an AMI, choose an instance type, and then choose Next:
Configure Instance Details.
4. On the Configure Instance Details page, select the VPC that you created earlier from the Network
list, and then select a subnet. For example, launch a web server into the public subnet and the
database server into the private subnet.
5. (Optional) By default, instances launched into a nondefault VPC are not assigned a public IP address.
To be able to connect to your instance in the public subnet, you can assign a public IP address now,
or allocate an Elastic IP address and assign it to your instance after it's launched. To assign a public
IP address now, ensure that you select Enable from the Auto-assign Public IP list.You do not need
to assign a public IP address to an instance in the private subnet.
Note
You can only assign a public IP address to a single, new network interface with the device
index of eth0. For more information, see Assigning a Public IP Address During Launch (p. 122).
6. On the next two pages of the wizard, you can configure storage for your instance, and add tags. On
the Configure Security Group page, select the Select an existing security group option, and
select a security group for the instance (WebServerSG for a web server or DBServerSG for a
database server). Choose Review and Launch.
7. Review the settings that you've chosen. Make any changes that you need, and then choose Launch
to choose a key pair and launch your instance.
For the instances running in the VPN-only subnet, you can test their connectivity by pinging them from
your network. For more information, see Testing the End-to-End Connectivity of Your Instance (p. 198).
If you did not assign a public IP address to your instance in the public subnet in step 5, you will not be
able to connect to it. Before you can access an instance in your public subnet, you must assign it an
Elastic IP address.
40
Amazon Virtual Private Cloud User Guide
Scenario 4: VPC with a Private Subnet Only and
Hardware VPN Access
6. In the Associate Address dialog box, select the network interface or instance. Select the address
to associate the Elastic IP address with from the corresponding Private IP address list, and then
choose Yes, Associate.
In scenario 3, you need a DNS server that enables your public subnet to communicate with servers on
the Internet, and you need another DNS server that enables your VPN-only subnet to communicate with
servers in your network.
You can now connect to your instances in the VPC. For information about how to connect to a Linux
instance, see Connect to Your Linux Instance in the Amazon EC2 User Guide for Linux Instances. For
information about how to connect to a Windows instance, see Connect to Your Windows Instance in the
Amazon EC2 User Guide for Microsoft Windows Instances.
Topics
• Configuration for Scenario 4 (p. 42)
• Basic Components for Scenario 4 (p. 42)
• Routing for Scenario 4 (p. 43)
• Security for Scenario 4 (p. 43)
• Implementing Scenario 4 (p. 44)
41
Amazon Virtual Private Cloud User Guide
Configuration for Scenario 4
Important
For this scenario, the Amazon VPC Network Administrator Guide describes what your network
administrator needs to do to configure the Amazon VPC customer gateway on your side of the
VPN connection.
• A virtual private cloud (VPC) of size /16 (example CIDR: 10.0.0.0/16). This provides 65,536 private IP
addresses.
• A VPN-only subnet of size /24 (example CIDR: 10.0.0.0/24). This provides 256 private IP addresses.
• A VPN connection between your VPC and your network. The VPN connection consists of a virtual
private gateway located on the Amazon side of the VPN connection and a customer gateway located
on your side of the VPN connection.
• Instances with private IP addresses in the subnet range (examples: 10.0.0.5, 10.0.0.6, and 10.0.0.7),
which enables the instances to communicate with each other and other instances in the VPC.
• A route table entry that enables instances in the subnet to communicate with other instances in the
VPC, and a route table entry that enables instances in the subnet to communicate directly with your
network.
42
Amazon Virtual Private Cloud User Guide
Routing for Scenario 4
For more information about subnets, see Your VPC and Subnets (p. 47) and IP Addressing in Your
VPC (p. 120). For more information about your VPN connection, see Adding a Hardware Virtual Private
Gateway to Your VPC (p. 190). For more information about configuring a customer gateway, see the
Amazon VPC Network Administrator Guide.
The following table shows what the route table looks like for the example addresses used in the
configuration diagram for this scenario. The first row describes the entry for local routing in the VPC; this
entry enables the instances in this VPC to communicate with each other. The second row describes the
entry for routing all other subnet traffic to the virtual private gateway, which is specified using its
AWS-assigned identifier (for example, vgw-1a2b3c4d).
Destination Target
10.0.0.0/16 local
0.0.0.0/0 vgw-xxxxxxxx
The VPN connection is configured either as a statically-routed VPN connection or as a dynamically routed
VPN connection (using BGP). If you select static routing, you'll be prompted to manually enter the IP
prefix for your network when you create the VPN connection. If you select dynamic routing, the IP prefix
is advertised automatically to your VPC through BGP.
The instances in your VPC can't reach the Internet directly; any Internet-bound traffic must first traverse
the virtual private gateway to your network, where the traffic is then subject to your firewall and corporate
security policies. If the instances send any AWS-bound traffic (for example, requests to Amazon S3 or
Amazon EC2), the requests must go over the virtual private gateway to your network and then to the
Internet before reaching AWS.
For scenario 4, you'll use the default security group for your VPC but not network ACLs. If you'd like to
use a network ACL, see Recommended Rules for Scenario 4 (p. 89).
43
Amazon Virtual Private Cloud User Guide
Implementing Scenario 4
Important
The default security group automatically allows assigned instances to communicate with each
other, so you don't have to add a rule to allow this. If you use a different security group, you must
add a rule to allow this.
The following table describes the inbound rules that you should add to the default security group for your
VPC.
Inbound
Private IP address range of your TCP 22 (Linux instances) Allow inbound SSH
network traffic from your network
Private IP address range of your TCP 3389 (Windows instances) Allow inbound
network RDP traffic from your network
Implementing Scenario 4
Use the following process to implement scenario 4 using the VPC wizard.
1. Determine the appliance you'll use as your customer gateway. For information about the devices
that we've tested, see Amazon Virtual Private Cloud FAQs. For more information about the
requirements for your customer gateway, see the Amazon VPC Network Administrator Guide.
2. Obtain the Internet-routable IP address for the customer gateway's external interface. The address
must be static and may be behind a device performing network address translation (NAT).
3. Gather the list of internal IP ranges (in CIDR notation) that should be advertised across the VPN
connection to the virtual private gateway (if you are using a statically routed VPN connection). For
more information, see VPN Routing Options (p. 192).
Next, use the VPC wizard as described in the following procedure to create your VPC and a VPN
connection.
• In Customer Gateway IP, specify the public IP address of your VPN router.
• Optionally specify a name for your customer gateway and VPN connection.
• In Routing Type, select one of the routing options as follows:
• If your VPN router supports Border Gateway Protocol (BGP), select Dynamic (requires BGP).
44
Amazon Virtual Private Cloud User Guide
Implementing Scenario 4
• If your VPN router does not support BGP, choose Static. In IP Prefix, add each IP prefix for
your network.
For more information about which option to choose, see Amazon Virtual Private Cloud FAQs. For
more information about dynamic versus static routing, see VPN Routing Options (p. 192).
6. When the wizard is done, choose VPN Connections in the navigation pane. Select the VPN
connection that the wizard created, and choose Download Configuration. In the dialog box, select
the vendor for the customer gateway, the platform, and the software version, and then choose Yes,
Download.
7. Save the text file containing the VPN configuration and give it to the network administrator along with
this guide: Amazon VPC Network Administrator Guide. The VPN won't work until the network
administrator configures the customer gateway.
For this scenario, you need to update the default security group with new inbound rules that allow SSH
and Remote Desktop (RDP) access from your network. If the instances won't initiate outbound
communication, we can also remove the default outbound rule. Reminder: the initial settings of the default
security group block all inbound traffic, allow all outbound traffic, and allow instances assigned to the
group to communicate with each other.
a. Select SSH from the Type list, and enter your network's private IP address range in the Source
field.
b. Choose Add another rule, then select RDP from the Type list, and enter your network's private
IP address range in the Source field.
c. Choose Save.
4. On the Outbound Rules tab, choose Edit, locate the default rule that enables all outbound traffic,
choose Remove, and then choose Save.
After your network administrator configures your customer gateway, you can launch instances into your
VPC. If you're already familiar with launching instances outside a VPC, then you already know most of
what you need to know to launch an instance into a VPC.
45
Amazon Virtual Private Cloud User Guide
Implementing Scenario 4
To launch an instance
2. Follow the directions in the wizard. Choose an AMI, choose an instance type, and then choose Next:
Configure Instance Details.
3. On the Configure Instance Details page, select the VPC that you created earlier from the Network
list, and then select a subnet. Choose Next: Add Storage.
4. On the next two pages of the wizard, you can configure storage for your instance, and add tags. On
the Configure Security Group page, select the Select an existing security group option, and
select the default security group. Choose Review and Launch.
5. Review the settings that you've chosen. Make any changes that you need, and then choose Launch
to choose a keypair and launch your instance.
In scenario 4, you need a DNS server that enables your VPN-only subnet to communicate with servers
in your network. You must create a new set of DHCP options that includes your DNS server and then
configure the VPC to use that set of options.
Note
Your VPC automatically has a set of DHCP options with
domain-name-servers=AmazonProvidedDNS. This is a DNS server that Amazon provides to
enable any public subnets in your VPC to communicate with the Internet over an Internet gateway.
Scenario 4 doesn't have any public subnets, so you don't need this set of DHCP options.
You can now use SSH or RDP to connect to your instance in the VPC. For information about how to
connect to a Linux instance, see Connect to Your Linux Instance in the Amazon EC2 User Guide for
Linux Instances. For information about how to connect to a Windows instance, see Connect to Your
Windows Instance in the Amazon EC2 User Guide for Microsoft Windows Instances.
46
Amazon Virtual Private Cloud User Guide
Your VPC
To get started with Amazon Virtual Private Cloud (Amazon VPC), you'll create a VPC and subnets. For
a general overview of VPCs and subnets, see What is Amazon VPC? (p. 1).
Topics
• Your VPC (p. 47)
• Subnets in Your VPC (p. 50)
• CLI Overview (p. 54)
Your VPC
A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated
from other virtual networks in the AWS cloud. You can launch your AWS resources, such as Amazon
EC2 instances, into your VPC. When you create a VPC, you specify the set of IP addresses for the VPC
in the form of a Classless Inter-Domain Routing (CIDR) block (for example, 10.0.0.0/16). For more
information about CIDR notation and what "/16" means, see Classless Inter-Domain Routing on Wikipedia.
For information about the number of VPCs that you can create, see Amazon VPC Limits (p. 210).
Topics
• Your New VPC (p. 47)
• VPC Sizing (p. 48)
• Connections with Your Local Network and Other VPCs (p. 49)
• Creating a VPC (p. 49)
• Deleting Your VPC (p. 50)
47
Amazon Virtual Private Cloud User Guide
VPC Sizing
You need to add a subnet before you can launch an instance into your VPC.
VPC Sizing
You can assign a single CIDR block to a VPC. The allowed block size is between a /28 netmask and
/16 netmask. In other words, the VPC can contain from 16 to 65,536 IP addresses. You can't change
the size of a VPC after you create it. If your VPC is too small to meet your needs, create a new, larger
VPC, and then migrate your instances to the new VPC.To do this, create AMIs from your running instances,
and then launch replacement instances in your new, larger VPC.You can then terminate your old instances,
and delete your smaller VPC. For more information, see Deleting Your VPC (p. 50).
48
Amazon Virtual Private Cloud User Guide
Connections with Your Local Network and Other VPCs
When those instances in the VPC try to talk to hosts in the 10.0.37.0/24 address space, the traffic is
dropped because 10.0.37.0/24 is part of the larger prefix assigned to the VPC (10.0.0.0/16). The
instances can talk to hosts in the 10.1.38.0/24 space because that block isn't part of 10.0.0.0/16.
You can also create a VPC peering connection between your VPCs, or with a VPC in another AWS
account. A VPC peering connection enables you to route traffic between the VPCs using private IP
addresses; however, you cannot create a VPC peering connection between VPCs that have overlapping
CIDR blocks. For more information, see VPC Peering (p. 169).
We therefore recommend that you create a VPC with a CIDR range large enough for expected future
growth, but not one that overlaps with current or expected future subnets anywhere in your corporate or
home network, or that overlaps with current or future VPCs.
Creating a VPC
There are two ways to create a VPC using the Amazon VPC console: the Create VPC dialog box and
the VPC wizard. The following procedure uses the Create VPC dialog box, which creates only the VPC;
you'd need to subsequently add subnets, gateways, and routing tables. For information about using the
VPC wizard to create a VPC plus its subnets, gateways, and routing tables in one step, see VPC Wizard
Scenarios for Amazon VPC (p. 17).
Note
(EC2-Classic) If you use the launch wizard in the Amazon EC2 console to launch an instance
type that is available in a VPC only and you do not have any existing VPCs, the wizard creates
a nondefault VPC for you. For more information, see Instance Types Available Only in a VPC
in the Amazon EC2 User Guide for Linux Instances.
To create a VPC
• Optionally provide a name for your VPC. Doing so creates a tag with a key of Name and the value
that you specify.
• Specify a CIDR block for the VPC. We recommend that you specify a CIDR block from the private
(non-publicly routable) IP address ranges as specified in RFC 1918; for example, 10.0.0.0/16,
or 192.168.0.0/16. It's possible to specify a range of publicly routable IP addresses; however,
we currently do not support direct access to the Internet from publicly routable CIDR blocks in a
VPC. Windows instances cannot boot correctly if launched into a VPC with ranges from 224.0.0.0
49
Amazon Virtual Private Cloud User Guide
Deleting Your VPC
to 255.255.255.255 (Class D and Class E IP address ranges). For more information about IP
addresses, see IP Addressing in Your VPC (p. 120).
• Select a tenancy option, for example, a dedicated tenancy that ensures your instances run on
single-tenant hardware. For more information about dedicated instances, see Dedicated
Instances (p. 204).
After you've created a VPC, you can add subnets. For more information, see Adding a Subnet to Your
VPC (p. 53).
If you have a VPN connection, you don't have to delete it or the other components related to the VPN
(such as the customer gateway and virtual private gateway). If you plan to use the customer gateway
with another VPC, we recommend you keep the VPN connection and the gateways. Otherwise, your
network administrator must configure the customer gateway again after you create a new VPN connection.
For information about the number of subnets that you can create, see Amazon VPC Limits (p. 210).
Topics
• Your VPC with Subnets (p. 51)
• Subnet Sizing (p. 52)
• Subnet Routing (p. 52)
• Subnet Security (p. 53)
• Adding a Subnet to Your VPC (p. 53)
• Launching an Instance into Your Subnet (p. 53)
50
Amazon Virtual Private Cloud User Guide
Your VPC with Subnets
If a subnet's traffic is routed to an Internet gateway, the subnet is known as a public subnet. In this diagram,
subnet 1 is a public subnet. If you want your instance in a public subnet to communicate with the Internet,
it must have a public IP address or an Elastic IP address. For more information about public IP addresses,
see Public and Private IP Addresses (p. 120).
If a subnet doesn't have a route to the Internet gateway, the subnet is known as a private subnet. In this
diagram, subnet 2 is a private subnet.
If a subnet doesn't have a route to the Internet gateway, but has its traffic routed to a virtual private
gateway, the subnet is known as a VPN-only subnet. In this diagram, subnet 3 is a VPN-only subnet.
Note
Regardless of the type of subnet, the internal IP address range of the subnet is always private
— we do not announce the address block to the Internet. For more information, see IP Addressing
in Your VPC (p. 120).
For more information, see VPC Wizard Scenarios for Amazon VPC (p. 17), Internet Gateways (p. 138),
or Adding a Hardware Virtual Private Gateway to Your VPC (p. 190).
51
Amazon Virtual Private Cloud User Guide
Subnet Sizing
Subnet Sizing
When you create a subnet, you specify the CIDR block for the subnet. The CIDR block of a subnet can
be the same as the CIDR block for the VPC (for a single subnet in the VPC), or a subset (to enable
multiple subnets). The allowed block size is between a /28 netmask and /16 netmask. If you create
more than one subnet in a VPC, the CIDR blocks of the subnets must not overlap.
For example, if you create a VPC with CIDR block 10.0.0.0/24, it supports 256 IP addresses. You can
break this CIDR block into two subnets, each supporting 128 IP addresses. One subnet uses CIDR block
10.0.0.0/25 (for addresses 10.0.0.0 - 10.0.0.127) and the other uses CIDR block 10.0.0.128/25
(for addresses 10.0.0.128 - 10.0.0.255).
There are many tools available to help you calculate subnet CIDR blocks. For information about a commonly
used tool, see http://www.subnet-calculator.com/cidr.php. Also, your network engineering group can help
you determine the CIDR blocks to specify for your subnets.
The first four IP addresses and the last IP address in each subnet CIDR block are not available for you
to use, and cannot be assigned to an instance. For example, in a subnet with CIDR block 10.0.0.0/24,
the following five IP addresses are reserved:
Subnet Routing
By design, each subnet must be associated with a route table, which specifies the allowed routes for
outbound traffic leaving the subnet. Every subnet that you create is automatically associated with the
main route table for the VPC. You can change the association, and you can change the contents of the
main route table. For more information, see Route Tables (p. 126).
In the previous diagram, the route table associated with subnet 1 routes all traffic (0.0.0.0/0) to an
Internet gateway (for example, igw-1a2b3c4d). Because instance V1 has an Elastic IP address, it can
be reached from the Internet.
Note
The Elastic IP address or public IP address that's associated with your instance is accessed
through the Internet gateway of your VPC. Traffic that goes through a VPN connection between
your instance and another network traverses a virtual private gateway, not the Internet gateway,
and therefore does not access the Elastic IP address or public IP address.
The instance V2 can't reach the Internet, but can reach other instances in the VPC. You can allow an
instance in your VPC to initiate outbound connections to the Internet but prevent unsolicited inbound
connections from the Internet using a network address translation (NAT) gateway or instance. Because
you can allocate a limited number of Elastic IP addresses, we recommend that you use a NAT device if
you have more instances that require a static public IP address. For more information, see NAT (p. 143).
The route table associated with subnet 3 routes all traffic (0.0.0.0/0) to a virtual private gateway (for
example, vgw-1a2b3c4d). Instance V3 can reach computers in the corporate network over the VPN
connection.
52
Amazon Virtual Private Cloud User Guide
Subnet Security
Subnet Security
AWS provides two features that you can use to increase security in your VPC: security groups and network
ACLs. Both features enable you to control the inbound and outbound traffic for your instances, but security
groups work at the instance level, while network ACLs work at the subnet level. Security groups alone
can meet the needs of many VPC users. However, some VPC users decide to use both security groups
and network ACLs to take advantage of the additional layer of security that network ACLs provide. For
more information about security groups and network ACLs and how they differ, see Security in Your
VPC (p. 61).
By design, each subnet must be associated with a network ACL. Every subnet that you create is
automatically associated with the VPC's default network ACL. You can change the association, and you
can change the contents of the default network ACL. For more information, see Network ACLs (p. 70).
You can create a flow log on your VPC or subnet to capture the traffic that flows to and from the network
interfaces in your VPC or subnet. You can also create a flow log on an individual network interface. Flow
logs are published to CloudWatch Logs. For more information, see VPC Flow Logs (p. 110).
• Configure your routing. To make your subnet a public subnet, you must add a route to an Internet
gateway. For more information, see Internet Gateways (p. 138). For more information about route tables,
see Route Tables (p. 126).
• Modify the subnet settings to specify that all instances launched in that subnet receive public IP
addresses. For more information, see Modifying Your Subnet's Public IP Addressing Behavior (p. 121).
• Create or modify your security groups as needed. For more information, see Security Groups for Your
VPC (p. 63).
• Create or modify your network ACLs as needed. For more information about network ACLs, see Network
ACLs (p. 70).
53
Amazon Virtual Private Cloud User Guide
Deleting Your Subnet
2. Follow the directions in the wizard. Select an AMI, choose an instance type, and then choose Next:
Configure Instance Details.
3. On the Configure Instance Details page, ensure you have selected the required VPC in the Network
list, then select the subnet to launch the instance into. Keep the other default settings on this page
and choose Next: Add Storage.
4. On the next pages of the wizard, you can configure storage for your instance, and add tags. On the
Configure Security Group page, choose from any existing security group that you own, or follow
the wizard directions to create a new security group. Choose Review and Launch when you're done.
5. Review your settings and choose Launch.
6. Choose an existing key pair that you own, or create a new one, then choose Launch Instances
when you're done.
CLI Overview
You can perform the tasks described on this page using a command line interface (CLI). For more
information, including a list of available API actions, see Accessing Amazon VPC (p. 6).
Create a VPC
Create a Subnet
Describe a VPC
54
Amazon Virtual Private Cloud User Guide
CLI Overview
Describe a Subnet
Delete a VPC
Delete a Subnet
55
Amazon Virtual Private Cloud User Guide
Default VPC Basics
If you created your AWS account after 2013-12-04, it supports only EC2-VPC. In this case, you'll have a
default VPC in each AWS region. A default VPC is ready for you to use — you can immediately start
launching instances into your default VPC without having to perform any additional configuration steps.
A default VPC combines the benefits of the advanced networking features provided by the EC2-VPC
platform with the ease of use of the EC2-Classic platform.
For more information about the EC2-Classic and EC2-VPC platforms, see Supported Platforms.
Topics
• Default VPC Basics (p. 56)
• Detecting Your Supported Platforms and Whether You Have a Default VPC (p. 58)
• Launching an EC2 Instance into Your Default VPC (p. 59)
• Deleting Your Default Subnets and Default VPC (p. 60)
Availability
If you created your AWS account after 2013-12-04, it supports only EC2-VPC. In this case, we create a
default VPC for you in each AWS region. Therefore, unless you create a nondefault VPC and specify it
when you launch an instance, we launch your instances into your default VPC.
If you created your AWS account before 2013-03-18, it supports both EC2-Classic and EC2-VPC in
regions that you've used before, and only EC2-VPC in regions that you haven't used. In this case, we
create a default VPC in each region in which you haven't created any AWS resources. Therefore, unless
you create a nondefault VPC and specify it when you launch an instance in a region that you haven't
used before, we launch the instance into your default VPC for that region. However, if you launch an
instance in a region that you've used before, we launch the instance into EC2-Classic.
If you created your AWS account between 2013-03-18 and 2013-12-04, it may support only EC2-VPC,
or it may support both EC2-Classic and EC2-VPC in some of the regions that you've used. For information
about detecting the platform support in each region for your AWS account, see Detecting Your Supported
Platforms and Whether You Have a Default VPC (p. 58). For information about when each region was
56
Amazon Virtual Private Cloud User Guide
Components
enabled for default VPCs, see Announcement: Enabling regions for the default VPC feature set in the
AWS forum for Amazon VPC.
If an AWS account supports only EC2-VPC, any IAM accounts associated with this AWS account also
support only EC2-VPC, and use the same default VPC as the AWS account.
If your AWS account supports both EC2-Classic and EC2-VPC and you want the benefits of using
EC2-VPC with the simplicity of launching instances into EC2-Classic, you can either create a new AWS
account or launch your instances into a region that you haven't used before. If you'd prefer to add a default
VPC to a region that doesn't have one, see "I really want a default VPC for my existing EC2 account. Is
that possible?" in the Default VPCs FAQ.
Components
When we create a default VPC, we do the following to set it up for you:
The following figure illustrates the key components that we set up for a default VPC.
Instances that you launch into a default subnet receive both a public IP address and a private IP address.
Instances in a default subnet also receive both public and private DNS hostnames. Instances that you
launch into a nondefault subnet in a default VPC don't receive a public IP address or a DNS hostname.
You can change your subnet's default public IP addressing behavior. For more information, see Modifying
Your Subnet's Public IP Addressing Behavior (p. 121).
You can use a default VPC as you would use any other VPC; you can add subnets, modify the main route
table, add additional route tables, associate additional security groups, update the rules of the default
security group, and add VPN connections. You can also create additional VPCs.
57
Amazon Virtual Private Cloud User Guide
Default Subnets
You can use a default subnet as you would use any other subnet; you can add custom route tables and
set network ACLs. You can also specify a default subnet when you launch an EC2 instance.
Default Subnets
The CIDR block for a default VPC is always a /16 netmask, for example, 172.31.0.0/16. This provides up
to 65,536 private IP addresses. The netmask for a default subnet is always /20, which provides up to
4,096 addresses per subnet, a few of which are reserved for our use.
By default, a default subnet is a public subnet, because the main route table sends the subnet's traffic
that is destined for the Internet to the Internet gateway. You can make a default subnet a private subnet
by removing the route from the destination 0.0.0.0/0 to the Internet gateway. However, if you do this, any
EC2 instance running in that subnet can't access the Internet.
From time to time, AWS may add a new Availability Zone to a region. In most cases, we’ll automatically
create a new default subnet in this Availability Zone for your default VPC. However, if you’ve made any
modifications to your default VPC, we do not add a new default subnet. If you want a default subnet for
the new Availability Zone, contact AWS Support to create a default subnet for you.
Verify that the region you'll use is selected in the navigation bar. On the Amazon EC2 console dashboard,
look for Supported Platforms under Account Attributes. If there are two values, EC2 and VPC, you can
launch instances into either platform. If there is one value, VPC, you can launch instances only into
EC2-VPC.
For example, the following indicates that the account supports the EC2-VPC platform only, and has a
default VPC with the identifier vpc-1a2b3c4d.
If you delete your default VPC, the Default VPC value displayed is None. For more information, see
Deleting Your Default Subnets and Default VPC (p. 60).
58
Amazon Virtual Private Cloud User Guide
Detecting Platform Support Using the Command Line
Also, when you list your VPCs using the following commands, we indicate any default VPCs in the output:
59
Amazon Virtual Private Cloud User Guide
Deleting Your Default Subnets and Default VPC
To launch an EC2 instance into your default VPC, use these commands without specifying a subnet or
an Availability Zone.
To launch an EC2 instance into a specific default subnet in your default VPC, specify its subnet ID or
Availability Zone.
If you delete a default subnet, you can't launch instances into that Availability Zone in your default VPC,
unless you create a nondefault subnet in that Availability Zone. If you delete a default subnet and want
to restore it, you can create a nondefault subnet and contact AWS Support to mark the subnet as a default
subnet. You must provide the following details: your AWS account ID, the region, and the subnet ID. To
ensure that your new default subnet behaves as expected, modify the subnet attribute to assign public
IP addresses to instances that are launched in that subnet. For more information, see Modifying Your
Subnet's Public IP Addressing Behavior (p. 121). You can only have one default subnet per Availability
Zone. You cannot create a default subnet in a nondefault VPC.
If you delete your default VPC and need a new one, you can contact AWS Support to create a new default
VPC in that region for you. You cannot mark an existing VPC as a default VPC.
If you try to delete your default subnet or default VPC in the Amazon VPC console, a dialog box displays
a warning and requires you to acknowledge that you are aware that you are deleting a default subnet or
default VPC.
60
Amazon Virtual Private Cloud User Guide
Amazon VPC provides three features that you can use to increase and monitor the security for your VPC:
• Security groups — Act as a firewall for associated Amazon EC2 instances, controlling both inbound
and outbound traffic at the instance level
• Network access control lists (ACLs) — Act as a firewall for associated subnets, controlling both inbound
and outbound traffic at the subnet level
• Flow logs — Capture information about the IP traffic going to and from network interfaces in your VPC
When you launch an instance in a VPC, you can associate one or more security groups that you've
created. 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 automatically belongs to the default security
group for the VPC. For more information about security groups, see Security Groups for Your VPC (p. 63)
You can secure your VPC instances using only security groups; however, you can add network ACLs as
a second layer of defense. For more information about network ACLs, see Network ACLs (p. 70).
You can monitor the accepted and rejected IP traffic going to and from your instances by creating a flow
log for a VPC, subnet, or individual network interface. Flow log data is published to CloudWatch Logs,
and can help you diagnose overly restrictive or overly permissive security group and network ACL rules.
For more information, see VPC Flow Logs (p. 110).
You can use AWS Identity and Access Management to control who in your organization has permission
to create and manage security groups, network ACLs and flow logs. For example, you can give only your
network administrators that permission, but not personnel who only need to launch instances. For more
information, see Controlling Access to Amazon VPC Resources (p. 90).
Amazon security groups and network ACLs don't filter traffic to or from link-local addresses
(169.254.0.0/16) or AWS-reserved addresses (the first four IP addresses and the last one in each
subnet). Similarly, flow logs do not capture IP traffic to or from these addresses. These addresses support
the services: Domain Name Services (DNS), Dynamic Host Configuration Protocol (DHCP), Amazon EC2
instance metadata, Key Management Server (KMS—license management for Windows instances), and
routing in the subnet. You can implement additional firewall solutions in your instances to block network
communication with link-local addresses.
61
Amazon Virtual Private Cloud User Guide
Comparison of Security Groups and Network ACLs
Operates at the instance level (first layer of de- Operates at the subnet level (second layer of de-
fense) fense)
Supports allow rules only Supports allow rules and deny rules
Is stateful: Return traffic is automatically allowed, Is stateless: Return traffic must be explicitly allowed
regardless of any rules by rules
We evaluate all rules before deciding whether to We process rules in number order when deciding
allow traffic whether to allow traffic
Applies to an instance only if someone specifies Automatically applies to all instances in the subnets
the security group when launching the instance, or it's associated with (backup layer of defense, so
associates the security group with the instance later you don't have to rely on someone specifying the
on security group)
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 associated with the subnet control which traffic is allowed to
the subnet. The rules of the security group associated with an instance control which traffic is allowed to
the instance.
62
Amazon Virtual Private Cloud User Guide
Security Groups
For each security group, you add rules that control the inbound traffic to instances, and a separate set
of rules that control the outbound traffic. This section describes the basics things you need to know about
security groups for your VPC and their rules.
You might set up network ACLs with rules similar to your security groups in order to add an additional
layer of security to your VPC. For more information about the differences between security groups and
network ACLs, see Comparison of Security Groups and Network ACLs (p. 62).
Topics
• Security Group Basics (p. 64)
• Default Security Group for Your VPC (p. 64)
• Security Group Rules (p. 65)
• Differences Between Security Groups for EC2-Classic and EC2-VPC (p. 66)
• Working with Security Groups (p. 67)
• API and CLI Overview (p. 69)
63
Amazon Virtual Private Cloud User Guide
Security Group Basics
• You can create up to 500 security groups per VPC. You can add up to 50 rules to each security group,
and associate up to 5 security groups per network interface. For more information about security group
limits, see Amazon VPC Limits (p. 210).
• You can specify allow rules, but not deny rules.
• You can specify separate rules for inbound and outbound traffic.
• By default, no inbound traffic is allowed until you add inbound rules to the security group.
• By default, an outbound rule allows all outbound traffic. You can remove the rule and add outbound
rules that allow specific outbound traffic only.
• Security groups are stateful — responses to allowed inbound traffic are allowed to flow outbound
regardless of outbound rules, and vice versa. For more information, see Connection Tracking in the
Amazon EC2 User Guide.
• Instances associated with a security group can't talk to each other unless you add rules allowing it
(exception: the default security group has these rules by default).
• Security groups are associated with network interfaces. After you launch an instance, you can change
the security groups associated with the instance, which changes the security groups associated with
the primary network interface (eth0). You can also change the security groups associated with any
other network interface. For more information about network interfaces, see Elastic Network Interfaces
(ENI).
The following table describes the default rules for a default security group.
Inbound
The security group ID All All Allow inbound traffic from instances
(sg-xxxxxxxx) assigned to the same security group
Outbound
You can change the rules for the default security group.
You can't delete a default security group. If you try to delete the default security group, you'll get the
following error: Client.CannotDelete: the specified group: "sg-51530134" name:
"default" cannot be deleted by a user.
64
Amazon Virtual Private Cloud User Guide
Security Group Rules
• (Inbound rules only) The source of the traffic (CIDR range or security group) and the destination port
or port range.
• (Outbound rules only) The destination for the traffic (CIDR range or security group) and the destination
port or port range.
• Any protocol that has a standard protocol number (for a list, see Protocol Numbers). If you specify
ICMP as the protocol, you can specify any or all of the ICMP types and codes.
Note
If your instance (host A) initiates traffic to host B and uses a protocol other than TCP, UDP,
or ICMP, your instance’s firewall only tracks the IP address and protocol number for the purpose
of allowing response traffic from host B. If host B initiates traffic to your instance in a separate
request within 600 seconds of the original request or response, your instance accepts it
regardless of inbound security group rules, because it’s regarded as response traffic. You can
control this by modifying your security group’s outbound rules to permit only certain types of
outbound traffic. Alternatively, you can use a network ACL for your subnet — network ACLs
are stateless and therefore do not automatically allow response traffic. For more information,
see Network ACLs (p. 70).
When you specify a security group as the source for a rule, this allows instances associated with the
source security group to access instances in the security group. (Note that this does not add rules from
the source security group to this security group.)
Some systems for setting up firewalls let you filter on source ports. Security groups let you filter only on
destination ports.
When you add or remove rules, they are automatically applied to all instances associated with the security
group.
The kind of rules you add may depend on the purpose of the instance. The following table describes
example rules for a security group for web servers. The web servers can receive HTTP and HTTPS traffic,
and send SQL or MySQL traffic to a database server.
Inbound
Your network's public IP address TCP 22 Allow inbound SSH access to Linux
range instances from your network (over the
Internet gateway)
Your network's public IP address TCP 3389 Allow inbound RDP access to Win-
range dows instances from your network
(over the Internet gateway)
65
Amazon Virtual Private Cloud User Guide
Differences Between Security Groups for EC2-Classic
and EC2-VPC
Outbound
The ID of the security group for TCP 1433 Allow outbound Microsoft SQL Server
your database servers access to instances in the specified
security group
The ID of the security group for TCP 3306 Allow outbound MySQL access to in-
your MySQL database servers stances in the specified security group
A database server would need a different set of rules; for example, instead of inbound HTTP and HTTPS
traffic, you can add a rule that allows inbound MySQL or Microsoft SQL Server access. For an example
of security group rules for web servers and database servers, see Recommended Security Groups (p. 35).
For more information about creating security group rules to ensure that Path MTU Discovery can function
correctly, see Path MTU Discovery in the Amazon EC2 User Guide.
The following table summarizes the differences between security groups for use with EC2-Classic and
those for use with EC2-VPC.
EC2-Classic EC2-VPC
You can create up to 500 security groups per re- You can create up to 500 security groups per VPC.
gion.
You can add up to 100 rules to a security group. You can add up to 50 rules to a security group.
You can add rules for inbound traffic only. You can add rules for inbound and outbound traffic.
You can assign up to 500 security groups to an in- You can assign up to 5 security groups to a network
stance. interface.
You can reference security groups from other AWS You can reference security groups for your VPC
accounts. only.
After you launch an instance, you can't change the You can change the security groups assigned to
security groups assigned to it. an instance after it's launched.
When you add a rule to a security group, you don't When you add a rule to a security group, you must
have to specify a protocol, and only TCP, UDP, or specify a protocol, and it can be any protocol with
ICMP are available. a standard protocol number, or all protocols (see
Protocol Numbers).
When you add a rule to a security group, you must When you add a rule to a security group, you can
specify port numbers (for TCP or UDP). specify port numbers only if the rule is for TCP or
UDP, and you can specify all port numbers.
66
Amazon Virtual Private Cloud User Guide
Working with Security Groups
Topics
• Modifying the Default Security Group (p. 67)
• Creating a Security Group (p. 67)
• Adding and Removing Rules (p. 67)
• Changing an Instance's Security Groups (p. 68)
• Deleting a Security Group (p. 68)
• Deleting the 2009-07-15-default Security Group (p. 69)
By default, new security groups start with only an outbound rule that allows all traffic to leave the instances.
You must add rules to enable any inbound traffic or to restrict the outbound traffic.
Several of the scenarios presented in this guide include instructions for adding rules to security groups.
For an example, see Recommended Security Groups (p. 35).
To add a rule
67
Amazon Virtual Private Cloud User Guide
Working with Security Groups
4. On the Inbound Rules tab, click Edit. Select an option for a rule for inbound traffic from the Type
list, and then fill in the required information. For example, select HTTP or HTTPS and specify the
Source as 0.0.0.0/0. Click Save when you are done.
5. You can also allow communication between all instances associated with this security group. On the
Inbound Rules tab, select All Traffic from the Type list. Start typing the ID of the security group in
the Source field; this provides you with a list of security groups. Select the security group from the
list, and then click Save.
6. If you need to, you can use the Outbound Rules tab to add rules for outbound traffic.
To delete a rule
68
Amazon Virtual Private Cloud User Guide
API and CLI Overview
69
Amazon Virtual Private Cloud User Guide
Network ACLs
Network ACLs
A network access control list (ACL) is an optional layer of security that acts as a firewall for controlling
traffic in and out of a subnet. You might set up network ACLs with rules similar to your security groups in
order to add an additional layer of security to your VPC. For more information about the differences
between security groups and network ACLs, see Comparison of Security Groups and Network ACLs (p. 62).
Topics
• Network ACL Basics (p. 70)
• Network ACL Rules (p. 71)
• Default Network ACL (p. 71)
• Custom Network ACL (p. 72)
• Ephemeral Ports (p. 74)
• Working with Network ACLs (p. 74)
• Example: Controlling Access to Instances in a Subnet (p. 77)
• API and Command Overview (p. 137)
• A network ACL is a numbered list of rules that we evaluate in order, starting with the lowest numbered
rule, to determine whether traffic is allowed in or out of any subnet associated with the network ACL.
The highest number that you can use for a rule is 32766. We recommend that you start by creating
70
Amazon Virtual Private Cloud User Guide
Network ACL Rules
rules with rule numbers that are multiples of 100, so that you can insert new rules where you need to
later on.
• A network ACL has separate inbound and outbound rules, and each rule can either allow or deny traffic.
• Your VPC automatically comes with a modifiable default network ACL; by default, it allows all inbound
and outbound traffic.
• You can create custom network ACL. Each custom network ACL starts out closed (permits no traffic)
until you add rules.
• Each subnet 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.
• Network ACLs are stateless; responses to allowed inbound traffic are subject to the rules for outbound
traffic (and vice versa).
For information about the number of network ACLs you can create, see Amazon VPC Limits (p. 210).
• 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 may contradict it.
• 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.
• [Inbound rules only] The source of the traffic (CIDR range) and the destination (listening) port or port
range.
• [Outbound rules only] The destination for the traffic (CIDR range) and the destination port or port range.
• Choice of ALLOW or DENY for the specified traffic.
Inbound
Outbound
71
Amazon Virtual Private Cloud User Guide
Custom Network ACL
The network ACL also includes inbound rules that allow SSH and RDP traffic into the subnet.The outbound
rule 120 enables responses to egress the subnet.
The network ACL has outbound rules (100 and 110) that allow outbound HTTP and HTTPS traffic out of
the subnet.There's a corresponding inbound rule that enables responses to that outbound traffic (inbound
rule 140, which covers ephemeral ports 49152-65535).
Note
Each network ACL includes a default rule whose rule number is an asterisk. This rule ensures
that if a packet doesn't match any of the other rules, it's denied. You can't modify or remove this
rule.
Inbound
72
Amazon Virtual Private Cloud User Guide
Custom Network ACL
* All traffic All All 0.0.0.0/0 DENY Denies all inbound traffic
not already handled by a
preceding rule (not modi-
fiable).
Outbound
As a packet comes to the subnet, we evaluate it against the ingress rules of the ACL the subnet is
associated with (starting at the top of the list of rules, and moving to the bottom). Here's how the evaluation
goes if the packet is destined for the SSL port (443). The packet doesn't match the first rule evaluated
(rule 100). It does match the second rule (110), which allows the packet into the subnet. If the packet had
been destined for port 139 (NetBIOS), the first two rules would not have matched, but the * rule ultimately
would have denied the packet.
You might want to add a DENY rule in a situation where you legitimately need to open a wide range of
ports, but there are certain ports within that range you want to deny. Just make sure to place the DENY
rule earlier in the table than the rule that allows the wide range of port traffic.
Important
With Elastic Load Balancing, if the subnet for your back-end instances has a network ACL in
which you've added a DENY rule for all traffic with a source of 0.0.0.0/0 or the subnet's CIDR,
then 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 back-end instances,
see Network ACLs for Load Balancers in a VPC in the Elastic Load Balancing Developer Guide.
73
Amazon Virtual Private Cloud User Guide
Ephemeral Ports
Ephemeral Ports
The example network ACL in the preceding section uses an ephemeral port range of 49152-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. For example, if a request comes into a
web server in your VPC from a Windows XP client on the Internet, your network ACL must have an
outbound rule to enable traffic destined for ports 1025-5000.
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 type of instance (Amazon Linux, Windows
Server 2008, and so on).
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.
Topics
• Determining Network ACL Associations (p. 74)
• Creating a Network ACL (p. 75)
• Adding and Deleting Rules (p. 75)
• Associating a Subnet with a Network ACL (p. 76)
• Disassociating a Network ACL from a Subnet (p. 76)
• Changing a Subnet's Network ACL (p. 76)
• Deleting a Network ACL (p. 77)
The network ACL associated with the subnet is included in the Network ACL tab, along with the
network ACL's rules.
74
Amazon Virtual Private Cloud User Guide
Working with Network ACLs
2. In the navigation pane, choose Network ACLs. The Associated With column indicates the number
of associated subnets for each network ACL.
3. Select a network ACL.
4. In the details pane, choose Subnet Associations to display the subnets associated with the network
ACL.
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 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.
75
Amazon Virtual Private Cloud User Guide
Working with Network ACLs
9. From the Allow/Deny list, select ALLOW to allow the specified traffic or DENY to deny the specified
traffic.
10. (Optional) To add another rule, choose Add another rule, and repeat steps 4 to 9 as required.
11. When you are done, choose Save.
After changing a subnet's network ACL, you don't have to terminate and relaunch the instances in the
subnet; the changes take effect after a short period.
76
Amazon Virtual Private Cloud User Guide
Example: Controlling Access to Instances in a Subnet
4. Select the network ACL to associate the subnet with from the Network ACL list, and then choose
Save.
All instances use the same security group (sg-1a2b3c4d), with the following rules.
77
Amazon Virtual Private Cloud User Guide
Example: Controlling Access to Instances in a Subnet
Inbound Rules
Outbound Rules
The subnet is associated with a network ACL that has the following rules.
Inbound Rules
78
Amazon Virtual Private Cloud User Guide
Example: Controlling Access to Instances in a Subnet
Outbound Rules
This scenario gives you the flexibility to change the security groups or security group rules for your
instances, and have the network ACL as the backup layer of defense. The network ACL rules apply to
all instances in the subnet, so if you accidentally make your security group rules too permissive, the
network ACL rules continue to permit access only from the single IP address. For example, the following
rules are more permissive than the earlier rules — they allow inbound SSH access from any IP address.
Inbound Rules
Outbound Rules
79
Amazon Virtual Private Cloud User Guide
API and Command Overview
However, only other instances within the subnet and your remote computer are able to access this
instance. The network ACL rules still prevent all inbound traffic to the subnet except from your remote
computer.
80
Amazon Virtual Private Cloud User Guide
Recommended Network ACL Rules for Your VPC
Topics
• Recommended Rules for Scenario 1 (p. 81)
• Recommended Rules for Scenario 2 (p. 82)
• Recommended Rules for Scenario 3 (p. 85)
• Recommended Rules for Scenario 4 (p. 89)
For more information about network ACLs and how to use them, see Network ACLs (p. 70).
Important
We use the ephemeral port range 49152-65535 as an example, or 1024-65535 for a NAT
gateway.You must select a range that is appropriate for your configuration. For more information,
see Ephemeral Ports (p. 74).
The following table shows the rules we recommended. They block all traffic except that which is explicitly
required.
Inbound
81
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 2
130 Public IP ad- TCP 3389 ALLOW Allows inbound RDP traffic
dress range from your home network
of your (over the Internet gateway)
home net-
work
Outbound
82
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 2
For this scenario you have a network ACL for the public subnet, and a separate one for the private subnet.
The following table shows the rules we recommend for each ACL. They block all traffic except that which
is explicitly required. They mostly mimic the security group rules for the scenario.
Inbound
130 Public IP ad- TCP 3389 ALLOW Allows inbound RDP traffic
dress range from your home network
of your (over the Internet gateway)
home net-
work
Outbound
83
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 2
Inbound
84
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 3
Outbound
For this scenario you have a network ACL for the public subnet, and a separate one for the VPN-only
subnet. The following table shows the rules we recommend for each ACL. They block all traffic except
that which is explicitly required.
85
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 3
Inbound
130 Public IP ad- TCP 3389 ALLOW Allows inbound RDP traffic
dress range to the web servers from your
of your home network (over the Inter-
home net- net gateway)
work
Outbound
86
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 3
Inbound
87
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 3
Outbound
88
Amazon Virtual Private Cloud User Guide
Recommended Rules for Scenario 4
The following table shows the rules we recommended. They block all traffic except that which is explicitly
required.
Inbound
Outbound
89
Amazon Virtual Private Cloud User Guide
Controlling Access
For more information about creating IAM policies for Amazon EC2, supported resources for EC2 API
actions, as well as example policies for Amazon EC2, see IAM Policies for Amazon EC2 in the Amazon
EC2 User Guide for Linux Instances.
Topics
• Example Policies for a CLI or SDK (p. 90)
• Example Policies for the Console (p. 100)
90
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
For example policies for working with ClassicLink, see Example Policies for CLI or SDK in the Amazon
EC2 User Guide for Linux Instances.
91
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following policy grants users permission to create and manage your VPC.You might attach this policy
to a group of network administrators. The Action element specifies the API actions related to VPCs,
subnets, Internet gateways, customer gateways, virtual private gateways, VPN connections, route tables,
Elastic IP addresses, security groups, network ACLs, and DHCP options sets. The policy also allows the
group to run, stop, start, and terminate instances. It also allows the group to list Amazon EC2 resources.
The policy uses wildcards to specify all actions for each type of object (for example, *SecurityGroup*).
Alternatively, you could list each action explicitly. If you use the wildcards, be aware that if we add new
actions whose names include any of the wildcarded strings in the policy, the policy would automatically
grant the group access to those new actions.
The Resource element uses a wildcard to indicate that users can specify all resources with these API
actions. The * wildcard is also necessary in cases where the API action does not support resource-level
permissions.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":["ec2:*Vpc*",
"ec2:*Subnet*",
"ec2:*Gateway*",
"ec2:*Vpn*",
"ec2:*Route*",
"ec2:*Address*",
"ec2:*SecurityGroup*",
"ec2:*NetworkAcl*",
"ec2:*DhcpOptions*",
"ec2:RunInstances",
"ec2:StopInstances",
"ec2:StartInstances",
"ec2:TerminateInstances",
"ec2:Describe*"],
"Resource":"*"
}
]
}
92
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following policy grants users permission to list your VPCs and their components. They can't create,
update, or delete them.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":["ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeInternetGateways",
"ec2:DescribeCustomerGateways",
"ec2:DescribeVpnGateways",
"ec2:DescribeVpnConnections",
"ec2:DescribeRouteTables",
"ec2:DescribeAddresses",
"ec2:DescribeSecurityGroups",
"ec2:DescribeNetworkAcls",
"ec2:DescribeDhcpOptions",
"ec2:DescribeTags",
"ec2:DescribeInstances"],
"Resource":"*"
}
]
}
The following policy grants users permission to launch instances, stop instances, start instances, terminate
instances, and describe the available resources for Amazon EC2 and Amazon VPC.
The second statement in the policy protects against any other policy that might grant the user access to
a wider range of API actions by explicitly denying permissions.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":["ec2:RunInstances",
"ec2:StopInstances",
"ec2:StartInstances",
"ec2:TerminateInstances",
"ec2:Describe*"],
"Resource":"*"
},
{
"Effect":"Deny",
"NotAction":["ec2:RunInstances",
"ec2:StopInstances",
"ec2:StartInstances",
"ec2:TerminateInstances",
"ec2:Describe*"],
"Resource":"*"
}
]
}
93
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following policy grants users 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 subnet-1a2b3c4d,
and the ARN for sg-123abc123. If users 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 users 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 user 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-1a2b3c4d",
"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-123abc123"
]
}
]
}
94
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following policy grants users 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 users 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:subnet/*",
"Condition": {
"StringEquals": {
"ec2:Vpc": "arn:aws:ec2:region:account:vpc/vpc-1a2b3c4d"
}
}
},
{
"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/*"
]
}
]
}
95
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following policy grants users permission to create and delete inbound and outbound rules for any
security group within a specific VPC. The policy does this by applying a condition key (ec2:Vpc) to the
security group resource for the Authorize and Revoke actions.
The second statement grants users permission to describe all security groups. This is necessary in order
for users to be able to modify security group rules using the CLI.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action": [
"ec2:AuthorizeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress",
"ec2:RevokeSecurityGroupEgress"],
"Resource": "arn:aws:ec2:region:account:security-group/*",
"Condition": {
"StringEquals": {
"ec2:Vpc": "arn:aws:ec2:region:account:vpc/vpc-1a2b3c4d"
}
}
},
{
"Effect": "Allow",
"Action": "ec2:DescribeSecurityGroups",
"Resource": "*"
}
]
}
96
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
The following are examples of policies you can use to manage the creation and modification of VPC
peering connections.
The following policy allows users to create VPC peering connection requests using only VPCs that are
tagged with Purpose=Peering. The first statement applies a condition key (ec2:ResourceTag) to the
VPC resource. Note that the VPC resource for the CreateVpcPeeringConnection action is always
the requester VPC.
The second statement grants users permissions to create the VPC peering connection resource, and
therefore uses the * wildcard in place of a specific resource ID.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action": "ec2:CreateVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:account:vpc/*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Purpose": "Peering"
}
}
},
{
"Effect": "Allow",
"Action": "ec2:CreateVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:account:vpc-peering-connection/*"
}
]
}
The following policy allows users in AWS account 333333333333 to create VPC peering connections
using any VPC in the us-east-1 region, but only if the VPC that will be accepting the peering connection
is a specific VPC (vpc-aaa111bb) in a specific account (777788889999).
{
"Version": "2012-10-17",
"Statement": [{
"Effect":"Allow",
"Action": "ec2:CreateVpcPeeringConnection",
"Resource": "arn:aws:ec2:us-east-1:333333333333:vpc/*"
},
{
"Effect": "Allow",
"Action": "ec2:CreateVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:333333333333:vpc-peering-connection/*",
"Condition": {
"ArnEquals": {
"ec2:AccepterVpc": "arn:aws:ec2:region:777788889999:vpc/vpc-aaa111bb"
}
}
}
97
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
]
}
The following policy allows users to accept VPC peering connection requests from AWS account
444455556666 only. This helps to prevent users from accepting VPC peering connection requests from
unknown accounts. The first statement uses the ec2:RequesterVpc condition key to enforce this.
The policy also grants users permissions to accept VPC peering requests only when your VPC has the
tag Purpose=Peering.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action": "ec2:AcceptVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:account:vpc-peering-connection/*",
"Condition": {
"ArnEquals": {
"ec2:RequesterVpc": "arn:aws:ec2:region:444455556666:vpc/*"
}
}
},
{
"Effect": "Allow",
"Action": "ec2:AcceptVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:account:vpc/*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Purpose": "Peering"
}
}
}
]
}
The following policy allows users in account 444455556666 to delete any VPC peering connection, except
those that use the specified VPC vpc-1a2b3c4d, which is in the same account. The policy specifies
both the ec2:AccepterVpc and ec2:RequesterVpc condition keys, as the VPC may have been the
requester VPC or the peer VPC in the original VPC peering connection request.
98
Amazon Virtual Private Cloud User Guide
Example Policies for a CLI or SDK
{
"Version": "2012-10-17",
"Statement": [{
"Effect":"Allow",
"Action": "ec2:DeleteVpcPeeringConnection",
"Resource": "arn:aws:ec2:region:444455556666:vpc-peering-connection/*",
"Condition": {
"ArnNotEquals": {
"ec2:AccepterVpc": "arn:aws:ec2:region:444455556666:vpc/vpc-1a2b3c4d",
"ec2:RequesterVpc": "arn:aws:ec2:region:444455556666:vpc/vpc-1a2b3c4d"
}
}
}
]
}
The following policy allows users to work with VPC peering connections entirely within a specific account.
Users can view, create, accept, reject, and delete VPC peering connections, provided they are all within
AWS account 333333333333.
The first statement allows users to view all VPC peering connections. The Resource element requires
a * wildcard in this case, as this API action (DescribeVpcPeeringConnections) currently does not
support resource-level permissions.
The second statement allows users to create VPC peering connections, and allows access to all VPCs
in account 333333333333 in order to do so.
The third statement uses a * wildcard as part of the Action element to allow all VPC peering connection
actions. The condition keys ensure that the actions can only be performed on VPC peering connections
with VPCs that are part of account 333333333333. For example, a user is not allowed to delete a VPC
peering connection if either the accepter or requester VPC is in a different account. A user cannot create
a VPC peering connection with a VPC in a different account.
99
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "ec2:DescribeVpcPeeringConnections",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": ["ec2:CreateVpcPeeringConnection","ec2:AcceptVpcPeeringConnection"],
"Resource": "arn:aws:ec2:*:333333333333:vpc/*"
},
{
"Effect": "Allow",
"Action": "ec2:*VpcPeeringConnection",
"Resource": "arn:aws:ec2:*:333333333333:vpc-peering-connection/*",
"Condition": {
"ArnEquals": {
"ec2:AccepterVpc": "arn:aws:ec2:*:333333333333:vpc/*",
"ec2:RequesterVpc": "arn:aws:ec2:*:333333333333:vpc/*"
}
}
}
]
}
The following policy grants users permission to create, modify, view, and delete VPC endpoints. None
of the ec2:*VpcEndpoint* actions support resource-level permissions, so you have to use the * wildcard
for the Resource element to allow users to work with all resources.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":"ec2:*VpcEndpoint*",
"Resource":"*"
}
]
}
This section demonstrates policies that enable users to work with specific parts of the VPC console.
100
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
101
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
You can use the VPC wizard in the Amazon VPC console to create and set up and configure a VPC for
you, so that it's ready for you to use. The wizard provides different configuration options, depending on
your requirements. For more information about using the VPC wizard to create a VPC, see VPC Wizard
Scenarios for Amazon VPC (p. 17).
To enable users to use the VPC wizard, you must grant them permission to create and modify the resources
that form part of the selected configuration. The following example policies show the actions that are
required for each of the wizard configuration options.
Note
If the VPC wizard fails at any point, it attempts to detach and delete the resources that it's created.
If you do not grant users permissions to use these actions, then those resources remain in your
account.
The first VPC wizard configuration option creates a VPC with a single subnet. In your IAM policy, you
must grant users permission to use the following actions so they can successfully use this wizard option:
None of the API actions in this policy support resource-level permissions, so you cannot control which
specific resources users can use.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcEndpointServices",
"ec2:CreateRouteTable", "ec2:CreateRoute", "ec2:CreateInternetGateway",
102
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
The second VPC wizard configuration option creates a VPC with a public and private subnet, and provides
the option to launch a NAT gateway or a NAT instance. The following policy has the same actions as the
previous example (option 1), plus actions that allow users to run and configure either a NAT gateway or
a NAT instance.
The following actions are required regardless if you're launching a NAT instance or a NAT gateway:
• ec2:DescribeKeyPairs: To display a list of existing key pairs and load the NAT section of the wizard.
The following actions are required to create a NAT gateway (these actions are not required for launching
a NAT instance):
The following actions are required to launch a NAT instance (these actions are not required for creating
a NAT gateway):
The following policy allows users to create either a NAT instance or a NAT gateway.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcEndpointServices",
"ec2:CreateRouteTable", "ec2:CreateRoute", "ec2:CreateInternetGateway",
"ec2:CreateNatGateway",
"ec2:AttachInternetGateway", "ec2:AssociateRouteTable", "ec2:ModifyVp
cAttribute", "ec2:DescribeKeyPairs",
"ec2:DescribeImages", "ec2:RunInstances", "ec2:AllocateAddress",
"ec2:AssociateAddress",
"ec2:DescribeAddresses", "ec2:DescribeInstances", "ec2:ModifyInstanceAt
tribute", "ec2:DescribeRouteTables",
"ec2:DescribeVpnGateways", "ec2:DescribeVpcs", "ec2:DescribeSubnets",
"ec2:DescribeNatGateways"
],
"Resource": "*"
}
]
}
103
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
You can use resource-level permissions on the ec2:RunInstances action to control users' ability to
launch instances. For example, you can specify the ID of a NAT-enabled AMI so that users can only
launch instances from this AMI. To find out which AMI the wizard uses to launch a NAT instance, log in
to the Amazon VPC console as a user with full permissions, then carry out the second option of the VPC
wizard. Switch to the Amazon EC2 console, select the Instances page, select the NAT instance, and
note the AMI ID that was used to launch it.
The following policy allows users to launch instances using only ami-1a2b3c4d. If users try to launch
an instance using any other AMI, the launch fails.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcEndpointServices",
"ec2:CreateRouteTable", "ec2:CreateRoute", "ec2:CreateInternetGateway",
Option 3: VPC with public and private subnets and hardware VPN access
The third VPC wizard configuration option creates a VPC with a public and private subnet, and creates
a VPN connection between your VPC and your own network. In your IAM policy, you must grant users
permission to use the same actions as option 1. This allows them to create a VPC and two subnets, and
to configure the routing for the public subnet.To create a VPN connection, users must also have permission
to use the following actions:
104
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
None of the API actions in this policy support resource-level permissions, so you cannot control which
specific resources users can use.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcEndpointServices",
"ec2:CreateRouteTable", "ec2:CreateRoute", "ec2:CreateInternetGateway",
Option 4: VPC with a private subnet only and hardware VPN access
The fourth VPC configuration option creates a VPC with a private subnet, and creates a VPN connection
between the VPC and your own network. Unlike the other three options, users do not need permission
to create or attach an Internet gateway to the VPC, and they do not need permission to create a route
table and associate it with the subnet. They will require the same permissions as listed in the previous
example (option 3) to establish the VPN connection.
None of the API actions in this policy support resource-level permissions, so you cannot control which
specific resources users can use.
105
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:CreateVpc", "ec2:CreateSubnet", "ec2:DescribeAvailabilityZones",
"ec2:DescribeVpcEndpointServices",
"ec2:ModifyVpcAttribute", "ec2:CreateCustomerGateway", "ec2:CreateVpnGate
way",
"ec2:AttachVpnGateway", "ec2:EnableVgwRoutePropagation", "ec2:CreateVpn
Connection",
"ec2:DescribeVpnGateways", "ec2:DescribeCustomerGateways", "ec2:DescribeVpn
Connections",
"ec2:DescribeRouteTables", "ec2:DescribeNetworkAcls", "ec2:DescribeInter
netGateways", "ec2:DescribeVpcs"
],
"Resource": "*"
}
]
}
106
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
On the Your VPCs page in the VPC console, you can create or delete a VPC. To view VPCs, users must
have permission to use the ec2:DescribeVPCs action. To create a VPC using the Create VPC dialog
box, users must have permission to use the ec2:CreateVpc action.
Note
By default, the VPC console creates a tag with a key of Name and a value that the user specifies.
If users do not have permission to the use the ec2:CreateTags action, then they will see an
error in the Create VPC dialog box when they try to create a VPC. However, the VPC may have
been successfully created.
When you set up a VPC, you typically create a number of dependent objects, such as subnets and an
Internet gateway. You cannot delete a VPC until you've disassociated and deleted these dependent
objects. When you delete a VPC using the console, it performs these actions for you (except terminating
your instances; you have to do this yourself).
The following example allows users to view and create VPCs on the Your VPCs page, and to delete
VPCs that have been created with the first option in the VPC wizard - a VPC with a single public subnet.
This VPC has one subnet that's associated with a custom route table, and an Internet gateway that's
attached to it. To delete the VPC and its components using the console, you must grant users permission
to use a number of ec2:Describe* actions, so that the console can check if there are any other resources
that are dependent on this VPC. You must also grant users permission to disassociate the route table
from the subnet, detach the Internet gateway from the VPC, and permission to delete both these resources.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:DescribeVpcs", "ec2:DescribeRouteTables", "ec2:DescribeVpnGateways",
"ec2:DescribeInternetGateways",
"ec2:DescribeSubnets", "ec2:DescribeDhcpOptions", "ec2:DescribeIn
stances", "ec2:DescribeVpcAttribute",
"ec2:DescribeNetworkAcls", "ec2:DescribeNetworkInterfaces", "ec2:De
scribeAddresses",
"ec2:DescribeVpcPeeringConnections", "ec2:DescribeSecurityGroups",
"ec2:CreateVpc", "ec2:DeleteVpc", "ec2:DetachInternetGateway",
"ec2:DeleteInternetGateway",
"ec2:DisassociateRouteTable", "ec2:DeleteSubnet", "ec2:DeleteRouteTable"
],
"Resource": "*"
}
]
}
You can't apply resource-level permissions to any of the ec2:Describe* API actions, but you can apply
resource-level permissions to some of the ec2:Delete* actions to control which resources users can
delete.
For example, the following policy allows users to delete only route tables and Internet gateways that have
the tag Purpose=Test. Users cannot delete individual route tables or Internet gateways that do not have
this tag, and similarly, users cannot use the VPC console to delete a VPC that's associated with a different
route table or Internet gateway.
107
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:DescribeVpcs", "ec2:DescribeRouteTables", "ec2:DescribeVpnGateways",
"ec2:DescribeInternetGateways",
"ec2:DescribeSubnets", "ec2:DescribeDhcpOptions", "ec2:DescribeIn
stances", "ec2:DescribeVpcAttribute",
"ec2:DescribeNetworkAcls", "ec2:DescribeNetworkInterfaces", "ec2:De
scribeAddresses",
"ec2:DescribeVpcPeeringConnections", "ec2:DescribeSecurityGroups",
"ec2:CreateVpc", "ec2:DeleteVpc", "ec2:DetachInternetGateway",
"ec2:DisassociateRouteTable", "ec2:DeleteSubnet"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ec2:DeleteInternetGateway",
"Resource": "arn:aws:ec2:region:account:internet-gateway/*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Purpose": "Test"
}
}
},
{
"Effect": "Allow",
"Action": "ec2:DeleteRouteTable",
"Resource": "arn:aws:ec2:region:account:route-table/*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Purpose": "Test"
}
}
}
]
}
108
Amazon Virtual Private Cloud User Guide
Example Policies for the Console
To view security groups on the Security Groups page in the Amazon VPC console, users must have
permission to use the ec2:DescribeSecurityGroups action. To use the Create Security Group
dialog box to create a security group, users must have permission to use the ec2:DescribeVpcs and
ec2:CreateSecurityGroup actions. If users do not have permission to use the
ec2:DescribeSecurityGroups action, they can still create a security group using the dialog box, but
they may encounter an error that indicates that the group was not created.
In the Create Security Group dialog box, users must add the security group name and description, but
they will not be able to enter a value for the Name tag field unless they've been granted permission to
use the ec2:CreateTags action. However, they do not need this action to successfully create a security
group.
The following policy allows users to view and create security groups, and add and remove inbound and
outbound rules to any security group that's associated with vpc-1a2b3c4d.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:DescribeSecurityGroups", "ec2:DescribeVpcs", "ec2:CreateSecurity
Group"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteSecurityGroup", "ec2:AuthorizeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress", "ec2:RevokeSecurityGroupEgress"
],
"Resource": "arn:aws:ec2:*:*:security-group/*",
"Condition":{
"ArnEquals": {
"ec2:Vpc": "arn:aws:ec2:*:*:vpc/vpc-1a2b3c4d"
}
}
}
]
}
109
Amazon Virtual Private Cloud User Guide
VPC Flow Logs
To view VPC peering connections in the Amazon VPC console, users must have permission to use the
ec2:DescribePeeringConnections action. To use the Create VPC Peering Connection dialog box,
users must have permission to use the ec2:DescribeVpcs action. This allows them to view and select
a VPC; without this action, the dialog box cannot load. You can apply resource-level permissions to all
the ec2:*PeeringConnection actions, except ec2:DescribeVpcPeeringConnections.
The following policy allows users to view VPC peering connections, and to use the Create VPC Peering
Connection dialog box to create a VPC peering connection using a specific requester VPC
(vpc-1a2b3c4d) only. If users try to create a VPC peering connection with a different requester VPC,
the request fails.
{
"Version": "2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action": [
"ec2:DescribeVpcPeeringConnections", "ec2:DescribeVpcs"
],
"Resource": "*"
},
{
"Effect":"Allow",
"Action": "ec2:CreateVpcPeeringConnection",
"Resource": [
"arn:aws:ec2:*:*:vpc/vpc-1a2b3c4d",
"arn:aws:ec2:*:*:vpc-peering-connection/*"
]
}
]
}
For more examples of writing IAM policies for working with VPC peering connections, see 7. Creating
and managing VPC peering connections (p. 97).
Flow logs can help you with a number of tasks; for example, to troubleshoot why specific traffic is not
reaching an instance, which in turn can help you diagnose overly restrictive security group rules. You can
also use flow logs as a security tool to monitor the traffic that is reaching your instance.
There is no additional charge for using flow logs; however, standard CloudWatch Logs charges apply.
For more information, see Amazon CloudWatch Pricing.
Topics
• Flow Logs Basics (p. 111)
• Flow Log Limitations (p. 111)
• Flow Log Records (p. 112)
• IAM Roles for Flow Logs (p. 113)
• Working With Flow Logs (p. 114)
110
Amazon Virtual Private Cloud User Guide
Flow Logs Basics
To create a flow log, you specify the resource for which you want to create the flow log, the type of traffic
to capture (accepted traffic, rejected traffic, or all traffic), the name of a log group in CloudWatch Logs to
which the flow log will be published, and the ARN of an IAM role that has sufficient permission to publish
the flow log to the CloudWatch Logs log group. If you specify the name of a log group that does not exist,
we'll attempt to create the log group for you. After you've created a flow log, it can take several minutes
to begin collecting data and publishing to CloudWatch Logs. Flow logs do not capture real-time log streams
for your network interfaces.
You can create multiple flow logs that publish data to the same log group in CloudWatch Logs. 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.
If you launch more instances into your subnet after you've created a flow log for your subnet or VPC, then
a new log stream is created for each new network interface as soon as any network traffic is recorded
for that network interface.
You can create flow logs for network interfaces that are created by other AWS services; for example,
Elastic Load Balancing, Amazon RDS, Amazon ElastiCache, Amazon Redshift, and Amazon WorkSpaces.
However, you cannot use these services' consoles or APIs to create the flow logs; you must use the
Amazon EC2 console or the Amazon EC2 API. Similarly, you cannot use the CloudWatch Logs console
or API to create log streams for your network interfaces.
If you no longer require a flow log, you can delete it. Deleting a flow log disables the flow log service for
the resource, and no new flow log records or log streams are created. It does not delete any existing flow
log records or log streams for a network interface. To delete an existing log stream, you can use the
CloudWatch Logs console. After you've deleted a flow log, it can take several minutes to stop collecting
data.
• You cannot enable flow logs for network interfaces that are in the EC2-Classic platform. This includes
EC2-Classic instances that have been linked to a VPC through ClassicLink.
• You cannot enable flow logs for VPCs that are peered with your VPC unless the peer VPC is in your
account.
• You cannot tag a flow log.
• After you've created a flow log, you cannot change its configuration; for example, you can't associate
a different IAM role with the flow log. Instead, you can delete the flow log and create a new one with
the required configuration.
111
Amazon Virtual Private Cloud User Guide
Flow Log Records
• None of the flow log API actions (ec2:*FlowLogs) support resource-level permissions. If you want to
create an IAM policy to control the use of the flow log API actions, you must grant users permission to
use all resources for the action by using the * wildcard for the resource element in your statement. For
more information, see Controlling Access to Amazon VPC Resources (p. 90).
• If your network interface has multiple IP addresses and traffic is sent to a secondary private IP address,
the flow log displays the primary private IP address in the destination IP address field.
Flow logs do not capture all types of 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.
• DHCP traffic.
version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes start end action
log-status
Field Description
interface-id The ID of the network interface for which the log stream applies.
srcaddr The source IP address. The IP address of the network interface is always its
private IP address.
dstaddr The destination IP address. The IP address of the network interface is always
its private IP address.
protocol The IANA protocol number of the traffic. For more information, go to Assigned
Internet Protocol Numbers.
start The time, in Unix seconds, of the start of the capture window.
end The time, in Unix seconds, of the end of the capture window.
112
Amazon Virtual Private Cloud User Guide
IAM Roles for Flow Logs
Field Description
• ACCEPT: The recorded traffic was permitted by the security groups or network
ACLs.
• REJECT: The recorded traffic was not permitted by the security groups or
network ACLs.
If a field is not applicable for a specific record, the record displays a '-' symbol for that entry.
For examples of flow log records, see Examples: Flow Log Records (p. 118)
You can work with 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 Monitoring Log Data and Filter and
Pattern Syntax in the Amazon CloudWatch Developer Guide. For an example of setting up a metric filter
and alarm for a flow log, see Example: Creating a CloudWatch Metric Filter and Alarm for a Flow
Log (p. 119).
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
113
Amazon Virtual Private Cloud User Guide
Working With Flow Logs
You must also ensure that your role has a trust relationship that allows the flow logs service to assume
the role (in the IAM console, choose your role, and then choose Edit Trust Relationship to view the trust
relationship):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "vpc-flow-logs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Alternatively, you can follow the procedures below to create a new role for use with flow logs.
Topics
• Creating a Flow Log (p. 115)
• Viewing Flow Logs (p. 115)
• Deleting a Flow Log (p. 116)
114
Amazon Virtual Private Cloud User Guide
Working With Flow Logs
• Filter: Select whether the flow log should capture rejected traffic, accepted traffic, or all traffic.
• Role: Specify the name of an IAM role that has permission to publish logs to CloudWatch Logs.
• Destination Log Group: Enter the name of a log group in CloudWatch Logs to which the flow
logs will be published. You can use an existing log group, or you can enter a name for a new log
group, which we'll create for you.
• Filter: Select whether the flow log should capture rejected traffic, accepted traffic, or all traffic.
• Role: Specify the name of an IAM role that has permission to publish logs to CloudWatch Logs.
• Destination Log Group: Enter the name of a log group in CloudWatch Logs to which the flow
logs will be published. You can use an existing log group, or you can enter a name for a new log
group, which we'll create for you.
To view information about your flow logs for your network interfaces
115
Amazon Virtual Private Cloud User Guide
Troubleshooting
To view information about your flow logs for your VPCs or subnets
You can view your flow log records using the CloudWatch Logs console. It may take a few minutes after
you've created your flow log for it to be visible in the console.
Troubleshooting
Incomplete Flow Log Records
If your flow log records are incomplete, or are no longer being published, there may be a problem delivering
the flow logs to the CloudWatch Logs log group. In either the Amazon EC2 console or the Amazon VPC
console, go to the Flow Logs tab for the relevant resource. For more information, see Viewing Flow
Logs (p. 115). 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 may be displayed:
116
Amazon Virtual Private Cloud User Guide
API and CLI Overview
• 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 limit on
the number of CloudWatch Logs log groups that you can create. For more information, see CloudWatch
Limits in the Amazon CloudWatch Developer Guide.
• Access error: The IAM role for your flow log does not have sufficient permissions to publish flow log
records to the CloudWatch log group. For more information, see IAM Roles for Flow Logs (p. 113).
• Unknown error: An internal error has occurred in the flow logs service.
• The flow log is still in the process of being created. In some cases, it can take tens of minutes after
you've created 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.
117
Amazon Virtual Private Cloud User Guide
Examples: Flow Log Records
The following is an example of a flow log record in which SSH traffic (destination port 22, TCP protocol)
to network interface eni-abc123de in account 123456789010 was allowed.
The following is an example of a flow log record in which RDP traffic (destination port 3389, TCP protocol)
to network interface eni-abc123de in account 123456789010 was rejected.
The following is an example of a flow log record in which no data was recorded during the capture window.
The following is an example of a flow log record in which records were skipped during the capture window.
If you're using flow logs to diagnose overly restrictive or permissive security group rules or network ACL
rules, then 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 55.123.456.78) to
your instance (the network interface's private IP address is 172.11.22.333). Your security group's
inbound rules allow ICMP traffic and the outbound rules do not allow ICMP traffic; however, 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 will not reach your home computer. In a flow log, this is displayed as
3 flow log entries: there are 2 ACCEPT entries for the originating ping and the response ping that the
security group permitted, and one REJECT entry for response ping that the network ACL denied:
118
Amazon Virtual Private Cloud User Guide
Example: Creating a CloudWatch Metric Filter and Alarm
for a Flow Log
To create a metric filter for rejected SSH traffic and create an alarm for the filter
4. In the Select Log Data to Test list, select the log stream for your network interface.You can optionally
choose Test Pattern to view the lines of log data that match the filter pattern. When you're ready,
choose Assign Metric.
5. Provide a metric namespace, a metric name, and ensure that the metric value is set to 1. When
you're done, choose Create Filter.
6. In the navigation pane, choose Alarms, and then choose Create Alarm.
7. In the Custom Metrics section, choose the namespace for the metric filter that you created.
Note
It can take a few minutes for a new metric to display in the console.
8. Select the metric name that you created, and then choose Next.
9. Enter a name and description for the alarm. In the is fields, choose >= and enter 10. In the for field,
leave the default 1 for the consecutive periods.
10. Choose 1 Hour from the Period list, and Sum from the Statistic list. The Sum statistic ensures that
you are capturing the total number of data points for the specified time period.
11. In the Actions section, you can choose to send a notification to an existing list, or you can create a
new list and enter the email addresses that should receive a notification when the alarm is triggered.
When you are done, choose Create Alarm.
119
Amazon Virtual Private Cloud User Guide
IP Addressing
You can use the following components to configure networking in your VPC:
Topics
• Public and Private IP Addresses (p. 120)
• Modifying Your Subnet's Public IP Addressing Behavior (p. 121)
• Assigning a Public IP Address During Launch (p. 122)
• Elastic IP Addresses (p. 123)
120
Amazon Virtual Private Cloud User Guide
Modifying Your Subnet's Public IP Addressing Behavior
Private IP addresses
When you launch an instance into a VPC, a primary private IP address from the address range of the
subnet is assigned to the default network interface (eth0) of the instance. If you don't specify a primary
private IP address, we select an available IP address in the subnet range for you. For more information
about network interfaces, see Elastic Network Interfaces in the Amazon EC2 User Guide for Linux
Instances.
You can assign additional private IP addresses, known as secondary private IP addresses, to instances
that are running in a VPC. Unlike a primary private IP address, you can reassign a secondary private IP
address from one network interface to another. A private IP address remains associated with the network
interface when the instance is stopped and restarted, and is released when the instance is terminated.
For more information about primary and secondary IP addresses, see Multiple IP Addresses in the Amazon
EC2 User Guide for Linux Instances.
Note
We refer to private IP addresses as the IP addresses that are within the CIDR range of the VPC.
Most VPC IP address ranges fall within the private (non-publicly routable) IP address ranges
specified in RFC 1918; however, it is possible to use publicly routable CIDR blocks for your VPC.
We currently do not support direct access to the Internet from publicly routable VPC CIDR blocks
— if your VPC uses a publicly routable IP address range, you must set up Internet access through
a virtual private gateway, a VPN connection, or AWS Direct Connect.
Public IP addresses
All subnets have an attribute that determines whether instances launched into that subnet receive a public
IP address. The public IP address is assigned to the default network interface (eth0). By default, instances
launched into a default subnet are assigned a public IP address. A public IP address is mapped to the
primary private IP address through network address translation (NAT).
You can control whether your instance receives a public IP address by doing the following:
• Modifying the public IP addressing attribute of your subnet. For more information, see Modifying Your
Subnet's Public IP Addressing Behavior (p. 121).
• Enabling or disabling the public IP addressing feature during instance launch, which overrides the
subnet's public IP addressing attribute. For more information, see Assigning a Public IP Address During
Launch (p. 122).
A public IP address is assigned to your instance from Amazon's pool of public IP addresses; it's not
associated with your account. When a public IP address is disassociated from your instance, it's released
back into the pool, and is no longer available for you to use.You cannot manually associate or disassociate
a public IP address. Instead, in certain cases, we release the public IP address from your instance, or
assign it a new one. For more information, see Public IP Addresses in the Amazon EC2 User Guide for
Linux Instances.
If you require a persistent public IP address that can be assigned to and removed from instances as you
require, use an Elastic IP address instead. To do this, you must allocate an Elastic IP address for use
with the VPC, and then associate that Elastic IP address with a private IP address specified by the network
interface attached to the instance. For more information, see Elastic IP Addresses (p. 123).
121
Amazon Virtual Private Cloud User Guide
Assigning a Public IP Address During Launch
You can modify the subnet's public IP addressing attribute. If you change this attribute, you can still
override this setting for a specific instance during launch. For more information, see Assigning a Public
IP Address During Launch (p. 122).
This feature is only available during launch. However, whether you assign a public IP address to your
instance during launch or not, you can associate an Elastic IP address with your instance after it's launched.
For more information, see Elastic IP Addresses (p. 123).
122
Amazon Virtual Private Cloud User Guide
Elastic IP Addresses
Elastic IP Addresses
An Elastic IP address is a static, public IP address designed for dynamic cloud computing. You can
associate an Elastic IP address with any instance or network interface for your VPC. With an Elastic IP
address, you can mask the failure of an instance by rapidly remapping the address to another instance
in your VPC. Note that 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.
Topics
• Elastic IP Address Basics (p. 123)
• Working with Elastic IP Addresses (p. 123)
• API and Command Overview (p. 125)
• You first allocate an Elastic IP address for use in a VPC, and then associate it with an instance in your
VPC (it can be assigned to only one instance at a time).
• An Elastic IP address is a property of network interfaces. You can associate an Elastic IP address with
an instance by updating the network interface attached to the instance.
• If you associate an Elastic IP address with the eth0 network interface of your instance, its current public
IP address (if it had one) is released to the EC2-VPC public IP address pool. If you disassociate the
Elastic IP address, the eth0 network interface is automatically assigned a new public IP address within
a few minutes. This doesn't apply if you've attached a second network interface to your instance.
• There are differences between an Elastic IP address that you use in a VPC and one that you use in
EC2-Classic. For more information, see Elastic IP Address Differences Between EC2-Classic and
Amazon EC2-VPC in the Amazon EC2 User Guide for Linux Instances).
• You can move an Elastic IP address from one instance to another. The instance can be in the same
VPC or another VPC, but not in EC2-Classic.
• Your Elastic IP addresses remain associated with your AWS account until you explicitly release them.
• To ensure efficient use of Elastic IP addresses, we impose a small hourly charge when they aren't
associated with a running instance, or when they are associated with a stopped instance or an unattached
network interface. While your instance is running, you aren't charged for one Elastic IP address
associated with the instance, but you are charged for any additional Elastic IP addresses associated
with the instance. For more information, see Amazon EC2 Pricing.
• You're limited to five Elastic IP addresses; to help conserve them, you can use a NAT device (see
NAT (p. 143)).
• An Elastic IP address is accessed through the Internet gateway of a VPC. If you have set up a VPN
connection between your VPC and your network, the VPN traffic traverses a virtual private gateway,
not an Internet gateway, and therefore cannot access the Elastic IP address.
• You can migrate an Elastic IP address that you've allocated for use in the EC2-Classic platform to the
VPC platform. For more information, see Migrating an Elastic IP Address from EC2-Classic to EC2-VPC
in the Amazon EC2 User Guide.
123
Amazon Virtual Private Cloud User Guide
Elastic IP Addresses
To change which instance an Elastic IP address is associated with, disassociate it from the currently
associated instance, and then associate it with the new instance in the VPC.
If you no longer need an Elastic IP address, we recommend that you release it (the address must not be
associated with an instance). You incur charges for any Elastic IP address that's allocated for use with
a VPC but not associated with an instance.
124
Amazon Virtual Private Cloud User Guide
Elastic IP Addresses
125
Amazon Virtual Private Cloud User Guide
Network Interfaces
You can create an ENI, attach it to an instance, detach it from an instance, and attach it to another
instance. An ENI's attributes follow the ENI as it is attached or detached from an instance and reattached
to another instance. When you move an ENI from one instance to another, network traffic is redirected
to the new instance.
Each instance in your VPC has a default elastic network interface (the primary network interface) that is
assigned a private IP address from the IP address range of your VPC. You cannot detach a primary
network interface from an instance. You can create and attach an additional elastic network interface to
any instance in your VPC. The number of ENIs you can attach varies by instance type. For more
information, see Private IP Addresses Per ENI Per Instance Type in the Amazon EC2 User Guide for
Linux Instances.
For more information about ENIs, and step-by-step instructions for working with them using the Amazon
EC2 console, see Elastic Network Interfaces in the Amazon EC2 User Guide for Linux Instances.
Route Tables
A route table contains a set of rules, called routes, that are used to determine where network traffic is
directed.
126
Amazon Virtual Private Cloud User Guide
Route Table Basics
Each subnet in your VPC must be associated with a route table; the table controls the routing for the
subnet. A subnet can only be associated with one route table at a time, but you can associate multiple
subnets with the same route table.
Topics
• Route Table Basics (p. 127)
• Route Priority (p. 130)
• Routing Options (p. 131)
• Working with Route Tables (p. 133)
• API and Command Overview (p. 137)
You can explicitly associate a subnet with the main route table, even if it's already implicitly associated.
You might do that if you change which table is the main route table, which changes the default for additional
new subnets, or any subnets that are not explicitly associated with any other route table. For more
information, see Replacing the Main Route Table (p. 136).
127
Amazon Virtual Private Cloud User Guide
Route Table Basics
The following diagram shows the routing for a VPC with both an Internet gateway and a virtual private
gateway, plus a public subnet and a VPN-only subnet. The main route table came with the VPC, and it
also has a route for the VPN-only subnet. A custom route table is associated with the public subnet. The
custom route table has a route over the Internet gateway (the destination is 0.0.0.0/0, and the target is
the Internet gateway).
If you create a new subnet in this VPC, it's automatically associated with the main route table, which
routes its traffic to the virtual private gateway. If you were to set up the reverse configuration (the main
route table with the route to the Internet gateway, and the custom route table with the route to the virtual
private gateway), then a new subnet automatically has a route to the Internet gateway.
Subnets can be implicitly or explicitly associated with the main route table. Subnets typically won't have
an explicit association to the main route table, although it might happen temporarily if you're replacing
the main route table.
You might want to make changes to the main route table, but to avoid any disruption to your traffic, you
can first test the route changes using a custom route table. After you're satisfied with the testing, you then
replace the main route table with the new custom table.
The following diagram shows a VPC with two subnets that are implicitly associated with the main route
table (Route Table A), and a custom route table (Route Table B) that isn't associated with any subnets.
128
Amazon Virtual Private Cloud User Guide
Route Table Basics
You can create an explicit association between Subnet 2 and Route Table B.
After you've tested Route Table B, you can make it the main route table. Note that Subnet 2 still has an
explicit association with Route Table B, and Subnet 1 has an implicit association with Route Table B
because it is the new main route table. Route Table A is no longer in use.
If you disassociate Subnet 2 from Route Table B, there's still an implicit association between Subnet 2
and Route Table B. If you no longer need Route Table A, you can delete it.
129
Amazon Virtual Private Cloud User Guide
Route Priority
Route Priority
We use the most specific route in your route table that matches the traffic to determine how to route the
traffic (longest prefix match). For example, the following route table has a route for Internet traffic
(0.0.0.0/0) that points to an Internet gateway, and a route for 172.31.0.0/16 traffic that points to a
peering connection (pcx-1a2b3c4d). Any traffic from the subnet that's destined for the 172.31.0.0/16
IP address range uses the peering connection, because this route is more specific than the route for
Internet gateway. Any traffic destined for within the VPC (10.0.0.0/16) is covered by the Local route,
and therefore routed within the VPC. All other traffic from the subnet uses the Internet gateway.
Destination Target
10.0.0.0/16 Local
172.31.0.0/16 pcx-1a2b1a2b
0.0.0.0/0 igw-11aa22bb
If you've attached a virtual private gateway to your VPC and enabled route propagation on your route
table, routes representing your VPN connection automatically appear as propagated routes in your route
table’s list of routes. If these routes overlap with existing static routes and longest prefix match cannot
be applied, then we prioritize the routes as follows in your VPC, from most preferred to least preferred:
If you have overlapping routes within a VPN connection and longest prefix match cannot be applied, then
we prioritize the routes as follows in the VPN connection, from most preferred to least preferred:
In this example, your route table has a static route to an Internet gateway (that you added manually), and
a propagated route to a virtual private gateway. Both routes have a destination of 172.31.0.0/24. In
this case, all traffic destined for 172.31.0.0/24 is routed to the Internet gateway — it is a static route
and therefore takes priority over the propagated route.
130
Amazon Virtual Private Cloud User Guide
Routing Options
Destination Target
10.0.0.0/16 Local
172.31.0.0/24 igw-11aa22bb
Routing Options
The following topics explain routing for specific gateways or connections in your VPC.
Topics
• Route Tables for an Internet Gateway (p. 131)
• Route Tables for a NAT Device (p. 131)
• Route Tables for a Virtual Private Gateway (p. 131)
• Route Tables for a VPC Peering Connection (p. 131)
• Route Tables for ClassicLink (p. 132)
• Route Tables for a VPC Endpoint (p. 132)
To enable the routing of traffic between VPCs in a VPC peering connection, you must add a route to one
or more of your VPC route tables that points to the VPC peering connection to access all or part of the
CIDR block of the other VPC in the peering connection. Similarly, the owner of the other VPC must add
a route to their VPC route table to route traffic back to your VPC.
131
Amazon Virtual Private Cloud User Guide
Routing Options
For example, you have a VPC peering connection (pcx-1a2b1a2b) between two VPCs, with the following
information:
To enable traffic between the VPCs and allow access to the entire CIDR block of either VPC, the VPC A
route table is configured as follows.
Destination Target
10.0.0.0/16 Local
172.31.0.0/16 pcx-1a2b1a2b
Destination Target
172.31.0.0/16 Local
10.0.0.0/16 pcx-1a2b1a2b
For more information about VPC peering connections, see the following topics:
• Working with VPC peering connections in the VPC console: VPC Peering (p. 169)
• Adding routes for VPC peering connections: Updating Route Tables for Your VPC Peering
Connection (p. 174)
• Supported VPC peering connection scenarios and routing configurations: Amazon VPC Peering Guide
When you enable a VPC for ClassicLink, a route is added to all of the VPC route tables with a destination
of 10.0.0.0/8 and a target of local. This allows communication between instances in the VPC and
any EC2-Classic instances that are then linked to the VPC. If you add another route table to a
ClassicLink-enabled VPC, it automatically receives a route with a destination of 10.0.0.0/8 and a target
of local. If you disable ClassicLink for a VPC, this route is automatically deleted in all the VPC route
tables.
If any of your VPC route tables have existing routes for address ranges within the 10.0.0.0/8 CIDR,
then you cannot enable your VPC for ClassicLink. This does not include local routes for VPCs with
10.0.0.0/16 and 10.1.0.0/16 IP address ranges.
If you've already enabled a VPC for ClassicLink, you may not be able to add any more specific routes to
your route tables for the 10.0.0.0/8 IP address range.
132
Amazon Virtual Private Cloud User Guide
Working with Route Tables
route is automatically added to each of the route tables with a destination that specifies the prefix list ID
of the service (pl-xxxxxxxx), and a target with the endpoint ID (vpce-xxxxxxxx).You cannot explicitly
delete or modify the endpoint route, but you can change the route tables that are used by the endpoint.
For more information about routing for endpoints, and the implications for routes to AWS services, see
Routing for Endpoints (p. 178).
Topics
• Determining Which Route Table a Subnet Is Associated With (p. 133)
• Determining Which Subnets Are Explicitly Associated with a Table (p. 133)
• Creating a Custom Route Table (p. 134)
• Adding and Removing Routes from a Route Table (p. 134)
• Enabling and Disabling Route Propagation (p. 135)
• Associating a Subnet with a Route Table (p. 135)
• Changing a Subnet Route Table (p. 135)
• Disassociating a Subnet from a Route Table (p. 136)
• Replacing the Main Route Table (p. 136)
• Deleting a Route Table (p. 136)
The main route table can have explicit and implicit associations. Custom route tables have only explicit
associations.
133
Amazon Virtual Private Cloud User Guide
Working with Route Tables
Subnets that aren't explicitly associated with any route table have an implicit association with the main
route table. You can explicitly associate a subnet with the main route table (for an example of why you
might do that, see Replacing the Main Route Table (p. 136)).
134
Amazon Virtual Private Cloud User Guide
Working with Route Tables
For more information about VPN routing options, see VPN Routing Options (p. 192).
135
Amazon Virtual Private Cloud User Guide
Working with Route Tables
The following procedure describes how to remove an explicit association between a subnet and the main
route table. The result is an implicit association between the subnet and the main route table. The process
is the same as disassociating any subnet from any route table.
136
Amazon Virtual Private Cloud User Guide
API and Command Overview
137
Amazon Virtual Private Cloud User Guide
Internet Gateways
Enable a virtual private gateway (VGW) to propagate routes to the routing tables of a VPC
Internet Gateways
An Internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows
communication between instances in your VPC and the Internet. It therefore imposes no availability risks
or bandwidth constraints on your network traffic. An Internet gateway serves two purposes: to provide a
target in your VPC route tables for Internet-routable traffic, and to perform network address translation
(NAT) for instances that have been assigned public IP addresses.
To enable access to or from the Internet for instances in a VPC subnet, you must do the following:
138
Amazon Virtual Private Cloud User Guide
Creating a VPC with an Internet Gateway
• Ensure that instances in your subnet have public IP addresses or Elastic IP addresses.
• Ensure that your network access control and security group rules allow the relevant traffic to flow to
and from your instance.
To use an Internet gateway, your subnet's route table must contain a route that directs Internet-bound
traffic to the Internet gateway. You can scope the route to all destinations not explicitly known to the route
table (0.0.0.0/0), or you can scope the route to a narrower range of IP addresses; for example, the
public IP addresses of your company’s public endpoints outside of AWS, or the Elastic IP addresses of
other Amazon EC2 instances outside your VPC. If your subnet is associated with a route table that has
a route to an Internet gateway, it's known as a public subnet. However, the Internet gateway route is not
sufficient to provide Internet access to instances in the subnet. For more information about public and
private subnets, see Your VPC with Subnets (p. 51).
To enable an instance in your public subnet to communicate with the Internet, it must have a public IP
address or an Elastic IP address that's associated with a private IP address on your instance. Your
instance is only aware of the private (internal) IP address space defined within the VPC and subnet. The
Internet gateway logically provides the one-to-one NAT on behalf of your instance, so that when traffic
leaves your VPC subnet and goes to the Internet, the reply address field is set to the public IP address
or Elastic IP address of your instance, and not its private IP address. Conversely, traffic that's destined
for public IP address or Elastic IP address of your instance has its destination address translated into the
instance's private IP address before the traffic is delivered to the VPC.
Your default VPC comes with an Internet gateway, and instances launched into a default subnet receive
a public IP address by default, unless you specify otherwise during launch, or you modify the subnet's
public IP address attribute. Therefore, instances that you launch into a default subnet can automatically
communicate with the Internet. For more information, see Your Default VPC and Subnets (p. 56).
Instances that you launch into a nondefault subnet may or may not be able to communicate with the
Internet, depending on how you create and configure your VPC. For example, if you use the VPC wizard
to create your VPC, depending on the option that you select, the VPC wizard adds an Internet gateway
to your VPC and updates the route table so that your instances can communicate with the Internet. For
more information about using the VPC wizard to create a subnet with an Internet gateway, see Scenario
1: VPC with a Single Public Subnet (p. 17) or Scenario 2: VPC with Public and Private Subnets
(NAT) (p. 22). Instances that you launch into a nondefault subnet do not receive a public IP address by
default and therefore can't communicate with the Internet, unless you specifically assign one during
launch, or you modify the subnet's public IP address attribute. For more information about assigning a
public IP address at launch, see Assigning a Public IP Address During Launch (p. 122). For more information
about modifying your subnet's public IP addressing attribute, see Modifying Your Subnet's Public IP
Addressing Behavior (p. 121).
When you add a new subnet to your VPC, you must set up the routing and security that you want for the
subnet.
Topics
• Creating a Subnet (p. 140)
• Attaching an Internet Gateway (p. 140)
• Creating a Custom Route Table (p. 141)
• Updating the Security Group Rules (p. 141)
• Adding Elastic IP Addresses (p. 142)
139
Amazon Virtual Private Cloud User Guide
Creating a VPC with an Internet Gateway
When you are finished setting up the subnet, your VPC is configured as shown in the following diagram.
Creating a Subnet
To add a subnet to your VPC
For more information about subnets, see Your VPC and Subnets (p. 47).
140
Amazon Virtual Private Cloud User Guide
Creating a VPC with an Internet Gateway
For more information about route tables, see Route Tables (p. 126).
For more information about security groups, see Security Groups for Your VPC (p. 63).
141
Amazon Virtual Private Cloud User Guide
Creating a VPC with an Internet Gateway
For more information about Elastic IP addresses, see Elastic IP Addresses (p. 123).
142
Amazon Virtual Private Cloud User Guide
NAT
NAT
You can use a NAT device to enable instances in a private subnet to connect to the Internet (for example,
for software updates) or other AWS services, but prevent the Internet from initiating connections with the
instances. A NAT device forwards traffic from the instances in the private subnet to the Internet or other
AWS services, and then sends the response back to the instances. When traffic goes to the Internet, the
source IP address is replaced with the NAT device’s address and similarly, when the response traffic
goes to those instances, the NAT device translates the address back to those instances’ private IP
addresses.
Note
We use the term NAT in this documentation to follow common IT practice, though the actual role
of a NAT device is both address translation and port address translation (PAT).
143
Amazon Virtual Private Cloud User Guide
NAT Gateways
AWS offers two kinds of NAT devices — a NAT gateway or a NAT instance. We recommend NAT
gateways, as they provide better availability and bandwidth over NAT instances. The NAT Gateway
service is also a managed service that does not require your administration efforts. A NAT instance is
launched from a NAT AMI. You can choose to use a NAT instance for special purposes.
NAT Gateways
You can use a network address translation (NAT) gateway to enable instances in a private subnet to
connect to the Internet or other AWS services, but prevent the Internet from initiating a connection with
those instances. For more information about NAT, see NAT (p. 143).
You are charged for creating and using a NAT gateway in your account. NAT gateway hourly usage and
data processing rates apply. Amazon EC2 charges for data transfer also apply. For more information,
see Amazon VPC Pricing.
Topics
• NAT Gateway Basics (p. 144)
• Working with NAT Gateways (p. 146)
• Troubleshooting NAT Gateways (p. 149)
• Controlling the Use of NAT Gateways (p. 153)
• API and CLI Overview (p. 153)
Each NAT gateway is created in a specific Availability Zone and implemented with redundancy in that
zone. You have a limit on the number of NAT gateways you can create in an Availability Zone. For more
information, see Amazon VPC Limits (p. 210).
Note
If you have resources in multiple Availability Zones and they share one NAT gateway, in the
event that the NAT gateway’s Availability Zone is down, resources in the other Availability Zones
lose Internet access. To create an Availability Zone-independent architecture, create a NAT
gateway in each Availability Zone and configure your routing to ensure that resources use the
NAT gateway in the same Availability Zone.
If you no longer need a NAT gateway, you can delete it. Deleting a NAT gateway disassociates its Elastic
IP address, but does not release the address from your account.
• A NAT gateway supports bursts of up to 10 Gbps of bandwidth. If you require more than 10 Gbps
bursts, you can distribute the workload by splitting your resources into multiple subnets, and creating
a NAT gateway in each subnet.
144
Amazon Virtual Private Cloud User Guide
NAT Gateways
• You can associate exactly one Elastic IP address with a NAT gateway. You cannot disassociate an
Elastic IP address from a NAT gateway after it's created. If you need to use a different Elastic IP address
for your NAT gateway, you must create a new NAT gateway with the required address, update your
route tables, and then delete the existing NAT gateway if it's no longer required.
• A NAT gateway supports the following protocols: TCP, UDP, and ICMP.
• You cannot associate a security group with a NAT gateway. You can use security groups for your
instances in the private subnets to control the traffic to and from those instances.
• You can use a network ACL to control the traffic to and from the subnet in which the NAT gateway is
located. The network ACL applies to the NAT gateway's traffic. A NAT gateway uses ports 1024 -
65535. For more information, see Network ACLs (p. 70).
• When a NAT gateway is created, it receives an elastic network interface that's automatically assigned
a private IP address from the IP address range of your subnet.You can view the NAT gateway's network
interface in the Amazon EC2 console. For more information, see Viewing Details about an Elastic
Network Interface. You cannot modify the attributes of this network interface.
• A NAT gateway cannot be accessed by a ClassicLink connection associated with your VPC.
The following diagram illustrates the architecture of a VPC with a NAT gateway. The main route table
sends Internet traffic from the instances in the private subnet to the NAT gateway. The NAT gateway
sends the traffic to the Internet gateway using the NAT gateway’s Elastic IP address as the source IP
address.
Topics
• Migrating From a NAT Instance (p. 146)
• Using a NAT Gateway with VPC Endpoints, VPN, AWS Direct Connect, or VPC Peering (p. 146)
145
Amazon Virtual Private Cloud User Guide
NAT Gateways
Using a NAT Gateway with VPC Endpoints, VPN, AWS Direct Connect, or
VPC Peering
A NAT gateway cannot send traffic over VPC endpoints, VPN connections, AWS Direct Connect, or VPC
peering connections. If your instances in the private subnet need to access resources over a VPC endpoint,
a VPN connection, or AWS Direct Connect, use the private subnet’s route table to route the traffic directly
to these devices.
For example, your private subnet’s route table has the following routes: Internet-bound traffic (0.0.0.0/0)
is routed to a NAT gateway, Amazon S3 traffic (pl-xxxxxxxx; a specific IP address range for Amazon S3)
is routed to a VPC endpoint, and 10.25.0.0/16 traffic is routed to a VPC peering connection.The pl-xxxxxxxx
and 10.25.0.0/16 IP address ranges are more specific than 0.0.0.0/0; when your instances send traffic
to Amazon S3 or the peered VPC, the traffic is sent to the VPC endpoint or the VPC peering connection.
When your instances send traffic to the Internet (other than the Amazon S3 IP addresses), the traffic is
sent to the NAT gateway.
You cannot route traffic to a NAT gateway through a VPC peering connection, a VPN connection, or AWS
Direct Connect. A NAT gateway cannot be used by resources on the other side of these connections.
Topics
• Creating a NAT Gateway (p. 146)
• Updating Your Route Table (p. 147)
• Deleting a NAT Gateway (p. 147)
• Testing a NAT Gateway (p. 147)
146
Amazon Virtual Private Cloud User Guide
NAT Gateways
If the NAT gateway goes to a status of Failed, there was an error during creation. For more information,
see NAT Gateway Goes to a Status of Failed (p. 150).
To ensure that your NAT gateway can access the Internet, the route table associated with the subnet in
which your NAT gateway resides must include a route that points Internet traffic to an Internet gateway.
For more information, see Creating a Custom Route Table (p. 141). If you delete a NAT gateway, the NAT
gateway routes remain in a blackhole status until you delete or update the routes. For more information,
see Adding and Removing Routes from a Route Table (p. 134).
147
Amazon Virtual Private Cloud User Guide
NAT Gateways
If you're able to connect to the Internet, you can also perform the following tests to determine if the Internet
traffic is being routed through the NAT gateway:
• You can trace the route of traffic from an instance in your private subnet. To do this, run the traceroute
command from a Linux instance in your private subnet. In the output, you should see the private IP
address of the NAT gateway in one of the hops (it's usually the first hop).
• Use a third-party website or tool that displays the source IP address when you connect to it from an
instance in your private subnet. The source IP address should be the Elastic IP address of your NAT
gateway. You can get the Elastic IP address and private IP address of your NAT gateway by viewing
its information on the NAT Gateways page in the Amazon VPC console.
If the above tests fail, see Troubleshooting NAT Gateways (p. 149).
The following example demonstrates how to test if your instance in a private subnet can connect to the
Internet.
1. Launch an instance in your public subnet (you'll use this as a bastion server). For more information,
see Launching an Instance into Your Subnet (p. 53). In the launch wizard, ensure that you select an
Amazon Linux AMI, and assign a public IP address to your instance. Ensure that your security group
rules allow inbound SSH traffic from the range of IP addresses for your local network (you can also
use 0.0.0.0/0 for this test), and outbound SSH traffic to the IP address range of your private subnet.
2. Launch an instance in your private subnet. In the launch wizard, ensure that you select an Amazon
Linux AMI. Do not assign a public IP address to your instance. Ensure that your security group rules
allow inbound SSH traffic from the private IP address of your instance that you launched in the public
subnet, and all outbound ICMP traffic. You must choose the same key pair that you used to launch
your instance in the public subnet.
3. Configure SSH agent forwarding on your local computer, and connect to your bastion server in the
public subnet. For more information, see To configure SSH agent forwarding for Linux or OS X (p. 148)
or To configure SSH agent forwarding for Windows (PuTTY) (p. 149).
4. From your bastion server, connect to your instance in the private subnet, and then test the Internet
connection from your instance in the private subnet. For more information, see To test the Internet
connection (p. 149).
1. From your local machine, add your private key to the authentication agent.
ssh-add -c mykeypair.pem
ssh-add -K mykeypair.pem
2. Connect to your instance in the public subnet using the -A option to enable SSH agent forwarding,
and use the instance's public address; for example:
ssh -A [email protected]
148
Amazon Virtual Private Cloud User Guide
NAT Gateways
1. Download and install Pageant from the PuTTY download page, if not already installed.
2. Convert your private key to .ppk format. For more information, see Converting Your Private Key
Using PuTTYgen in the Amazon EC2 User Guide for Linux Instances.
3. Start Pageant, and then choose Add Key. Select the .ppk file you created, enter the passphrase if
required, choose OK, and then close the Pageant Key List window.
4. Start a PuTTY session and connect to your instance in the public subnet using its public IP address.
For more information, see Starting a PuTTY Session. In the Auth category, ensure that you select
the Allow agent forwarding option, and leave the Private key file for authentication field blank.
1. From your instance in the public subnet, connect to your instance in your private subnet by using its
private IP address, for example:
2. From your private instance, test that you can connect to the Internet by running the ping command
for a website that has ICMP enabled, for example:
ping ietf.org
Press Ctrl+C on your keyboard to cancel the ping command. If the ping command fails, see
Instances in Private Subnet Cannot Access Internet (p. 151).
3. (Optional) Terminate your instances if you no longer require them. For more information, see Terminate
Your Instance in the Amazon EC2 User Guide for Linux Instances.
Topics
• NAT Gateway Goes to a Status of Failed (p. 150)
• You've Reached Your Elastic IP Address or NAT Gateway Limit (p. 151)
• The Availability Zone is Unsupported (NotAvailableInZone) (p. 151)
• You Created a NAT Gateway and It's No Longer Visible (p. 151)
• NAT Gateway Doesn't Respond to a Ping Command (p. 151)
• Instances in Private Subnet Cannot Access Internet (p. 151)
• Traceroute Output Does Not Display NAT Gateway Private IP Address (p. 152)
• Internet Connection Drops After 5 Minutes (p. 152)
• IPSec Connection Cannot be Established (p. 152)
• Cannot Initiate More Connections to a Destination (p. 152)
149
Amazon Virtual Private Cloud User Guide
NAT Gateways
The following table lists the possible causes of the failure as indicated in the Amazon VPC console. After
you've applied any of the remedial steps indicated, you can try to create a NAT gateway again.
Subnet has insufficient free ad- The subnet you specified does You can check how many IP ad-
dresses to create this NAT gate- not have any free private IP ad- dresses are available in your sub-
way dresses. The NAT gateway re- net by going to the Subnets page
quires a network interface with a in the Amazon VPC console, and
private IP address allocated from viewing the Available IPs field in
the subnet's range. the details pane for your subnet.
To create free IP addresses in
your subnet, you can delete un-
used network interfaces, or termin-
ate instances that you do not re-
quire.
Network vpc-xxxxxxxx has no A NAT gateway must be created Create and attach an Internet
Internet gateway attached in a VPC with an Internet gate- gateway to your VPC. For more
way. information, see Attaching an Inter-
net Gateway (p. 140).
Elastic IP address eipalloc- The Elastic IP address that you Check the allocation ID of the
xxxxxxxx could not be associated specified does not exist or could Elastic IP address to ensure that
with this NAT gateway not be found. you entered it correctly. Ensure
that you have specified an Elastic
IP address that's in the same re-
gion in which you're creating the
NAT gateway.
Elastic IP address eipalloc- The Elastic IP address that you You can check which resource is
xxxxxxxx is already associated specified is already associated associated with the Elastic IP ad-
with another resource, and can- dress by going to the Elastic IPs
not be associated with the NAT page in the Amazon VPC console,
gateway. and viewing the values specified
for the instance ID or network in-
terface ID. If you do not require
the Elastic IP address for that re-
source, you can disassociate it.
Alternatively, allocate a new
Elastic IP address to your ac-
count. For more information, see
Working with Elastic IP Ad-
dresses (p. 123).
Network interface eni-xxxxxxxx, There was a problem creating or You cannot fix this error. Try creat-
created and used internally by using the network interface for ing a NAT gateway again.
this NAT gateway is in an invalid the NAT gateway.
state. Please try again.
150
Amazon Virtual Private Cloud User Guide
NAT Gateways
If you've reached your NAT gateway limit, you can do one of the following:
• Request a limit increase using the Amazon VPC Limits form. The NAT gateway limit is enforced per
Availability Zone.
• Check the status of your NAT gateway. A status of Pending, Available, or Deleting counts against
your limit. 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 limit.
For more information about limits, see Amazon VPC Limits (p. 210).
To test that your NAT gateway is working, see Testing a NAT Gateway (p. 147).
• 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
Goes to a Status of Failed (p. 150).
• 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. For more information, see Creating a Custom Route Table (p. 141).
• Your instance must be in a private subnet with a route table that routes Internet traffic to the NAT
gateway. For more information, see Updating Your Route Table (p. 147).
• 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.
151
Amazon Virtual Private Cloud User Guide
NAT Gateways
• 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.
Note
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.
Note
You can enable flow logs to help you diagnose dropped connections because of network ACL
or security group rules. For more information, see VPC Flow Logs (p. 110).
• If you are using the ping command, ensure that you are pinging a website that has ICMP enabled. If
not, 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.
• 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.
• 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.
• Close idle connections to release the capacity.
152
Amazon Virtual Private Cloud User Guide
NAT Instances
Note
If the destination IP address, the destination port, or the protocol (TCP/UDP/ICMP) changes,
you can create an additional 65,000 connections.
NAT Instances
You can use a network address translation (NAT) instance in a public subnet in your VPC to enable
instances in the private subnet to initiate outbound traffic to the Internet or other AWS services, but prevent
the instances from receiving inbound traffic initiated by someone on the Internet.
For more information about public and private subnets, see Subnet Routing (p. 52). For more information
about NAT, see NAT (p. 143).
Note
You can also use a NAT gateway, which is a managed NAT service that provides better
availability, higher bandwidth, and requires less administrative effort. For common use cases,
we recommend that you use a NAT gateway rather than a NAT instance. For more information,
see NAT Gateways (p. 144) and Comparison of NAT Instances and NAT Gateways (p. 161).
Topics
• NAT Instance Basics (p. 154)
• Setting up the NAT Instance (p. 155)
153
Amazon Virtual Private Cloud User Guide
NAT Instances
Amazon provides Amazon Linux AMIs that are configured to run as NAT instances. These AMIs include
the string amzn-ami-vpc-nat in their names, so you can search for them in the Amazon EC2 console.
When you launch an instance from a NAT AMI, the following configuration occurs on the instance:
154
Amazon Virtual Private Cloud User Guide
NAT Instances
Your NAT instance limit depends on your instance type limit for the region. For more information, see the
EC2 FAQs. For a list of available NAT AMIs, see the Amazon Linux AMI matrix.
2. Create the NATSG security group (see Creating the NATSG Security Group (p. 156)). You'll specify
this security group when you launch the NAT instance.
3. Launch an instance into your public subnet from an AMI that's been configured to run as a NAT
instance. Amazon provides Amazon Linux AMIs that are configured to run as NAT instances. These
AMIs include the string amzn-ami-vpc-nat in their names, so you can search for them in the
Amazon EC2 console.
i. On the Choose an Amazon Machine Image (AMI) page, select the Community AMIs
category, and search for amzn-ami-vpc-nat. In the results list, each AMI's name includes
the version to enable you to select the most recent AMI, for example, 2013.09. Choose
Select.
ii. On the Choose an Instance Type page, select the instance type, then choose Next:
Configure Instance Details.
iii. On the Configure Instance Details page, select the VPC you created from the Network
list, and select your public subnet from the Subnet list.
iv. (Optional) Select the Public IP check box to request that your NAT instance receives a
public IP address. If you choose not to assign a public IP address now, you can allocate an
Elastic IP address and assign it to your instance after it's launched. For more information
about assigning a public IP at launch, see Assigning a Public IP Address During
Launch (p. 122). Choose Next: Add Storage.
v. You can choose to add storage to your instance, and on the next page, you can add tags.
Choose Next: Configure Security Group when you are done.
vi. On the Configure Security Group page, select the Select an existing security group
option, and select the NATSG security group that you created. Choose Review and Launch.
vii. Review the settings that you've chosen. Make any changes that you need, and then choose
Launch to choose a key pair and launch your instance.
155
Amazon Virtual Private Cloud User Guide
NAT Instances
4. (Optional) Connect to the NAT instance, make any modifications that you need, and then create your
own AMI that's configured to run as a NAT instance. You can use this AMI the next time that you
need to launch a NAT instance. For more information about creating an AMI, see Creating Amazon
EBS-Backed AMIs in the Amazon EC2 User Guide for Linux Instances.
5. Disable the SrcDestCheck attribute for the NAT instance (see Disabling Source/Destination
Checks (p. 158))
6. If you did not assign a public IP address to your NAT instance during launch (step 3), you need to
associate an Elastic IP address with it.
7. Update the main route table to send traffic to the NAT instance. For more information, see Updating
the Main Route Table (p. 158).
To get the ID of an AMI that's configured to run as a NAT instance, use a command to describe images,
and use filters to return results only for AMIs that are owned by Amazon, and that have the
amzn-ami-vpc-nat string in their names. The following example uses the AWS CLI:
Inbound
156
Amazon Virtual Private Cloud User Guide
NAT Instances
Public IP address range of your TCP 22 Allow inbound SSH access to the NAT
home network instance from your home network
(over the Internet gateway)
Outbound
a. Choose Edit.
b. Choose Add another rule, and select HTTP from the Type list. In the Source field, specify the
IP address range of your private subnet.
c. Choose Add another rule, and select HTTPS from the Type list. In the Source field, specify
the IP address range of your private subnet.
d. Choose Add another rule, and select SSH from the Type list. In the Source field, specify the
public IP address range of your network.
e. Choose Save.
6. Add rules for outbound traffic using the Outbound Rules tab as follows:
a. Choose Edit.
b. Choose Add another rule, and select HTTP from the Type list. In the Destination field, specify
0.0.0.0/0
c. Choose Add another rule, and select HTTPS from the Type list. In the Destination field, specify
0.0.0.0/0
d. Choose Save.
For more information about security groups, see Security Groups for Your VPC (p. 63).
157
Amazon Virtual Private Cloud User Guide
NAT Instances
You can disable the SrcDestCheck attribute for a NAT instance that's either running or stopped using
the console or the command line.
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon VPC (p. 6).
For more information about route tables, see Route Tables (p. 126).
158
Amazon Virtual Private Cloud User Guide
NAT Instances
private subnet, configure SSH agent forwarding to access instances in your private subnet, connect to
your instance, and then test the Internet connectivity.
• On the Choose an Amazon Machine Image (AMI) page, select an Amazon Linux AMI from the
Quick Start category.
• On the Configure Instance Details page, select your private subnet from the Subnet list, and do
not assign a public IP address to your instance.
• On the Configure Security Group page, ensure that your security group includes an inbound rule
that allows SSH access from your NAT instance's private IP address, or from the IP address range
of your public subnet, and ensure that you have an outbound rule that allows outbound ICMP
traffic.
• In the Select an existing key pair or create a new key pair dialog box, select the same key pair
you used to launch the NAT instance.
1. From your local machine, add your private key to the authentication agent.
2. Connect to your NAT instance using the -A option to enable SSH agent forwarding, for example:
ssh -A [email protected]
159
Amazon Virtual Private Cloud User Guide
NAT Instances
1. Download and install Pageant from the PuTTY download page, if not already installed.
2. Convert your private key to .ppk format. For more information, see Converting Your Private Key
Using PuTTYgen.
3. Start Pageant, and then choose Add Key. Select the .ppk file you created, enter the passphrase if
required, choose OK, and then close the Pageant Key List window.
4. Start a PuTTY session to connect to your NAT instance. In the Auth category, ensure that you select
the Allow agent forwarding option, and leave the Private key file for authentication field blank.
1. Test that your NAT instance can communicate with the Internet by running the ping command for
a website that has ICMP enabled; for example:
3. From your private instance, test that you can connect to the Internet by running the ping command:
• Check that your NAT instance's security group rules allow inbound ICMP traffic from your private
subnet. If not, your NAT instance cannot receive the ping command from your private instance.
• Check that you've configured your route tables correctly. For more information, see Updating the
Main Route Table (p. 158).
• Ensure that you've disabled source/destination checking for your NAT instance. For more
information, see Disabling Source/Destination Checks (p. 158).
• Ensure that you are pinging a website that has ICMP enabled. If not, you will not receive reply
packets. To test this, perform the same ping command from the command line terminal on your
own computer.
160
Amazon Virtual Private Cloud User Guide
Comparison of NAT Instances and NAT Gateways
4. (Optional) Terminate your private instance if you no longer require it. For more information, see
Terminate Your Instance in the Amazon EC2 User Guide for Linux Instances.
Availabil- Highly available. NAT gateways in each Use a script to manage failover between in-
ity Availability Zone are implemented with redund- stances.
ancy. Create a NAT gateway in each Availab-
ility Zone to ensure zone-independent archi-
tecture.
Mainten- Managed by AWS.You do not need to perform Managed by you, for example, by installing
ance any maintenance. software updates or operating system
patches on the instance.
Perform- Software is optimized for handling NAT traffic. A generic Amazon Linux AMI that's con-
ance figured to perform NAT.
Cost Charged depending on the number of NAT Charged depending on the number of NAT
gateways you use, duration of usage, and instances that you use, duration of usage,
amount of data that you send through the NAT and instance type and size.
gateways.
Type and Uniform offering; you don’t need to decide on Choose a suitable instance type and size,
size the type or size. according to your predicted workload.
Public IP Choose the Elastic IP address to associate Use an Elastic IP address or a public IP ad-
ad- with a NAT gateway at creation. dress with a NAT instance. You can change
dresses the public IP address at any time by associ-
ating a new Elastic IP address with the in-
stance.
Private Automatically selected from the subnet's IP Assign a specific private IP address from the
IP ad- address range when you create the gateway. subnet's IP address range when you launch
dresses the instance.
Security Cannot be associated with a NAT gateway. Associate with your NAT instance and the
groups You can associate security groups with your resources behind your NAT instance to con-
resources behind the NAT gateway to control trol inbound and outbound traffic.
inbound and outbound traffic.
Network Use a network ACL to control the traffic to and Use a network ACL to control the traffic to
ACLs from the subnet in which your NAT gateway and from the subnet in which your NAT in-
resides. stance resides.
Flow logs Use flow logs to capture the traffic. Use flow logs to capture the traffic.
161
Amazon Virtual Private Cloud User Guide
DHCP Options Sets
Topics
• Overview of DHCP Options Sets (p. 162)
• Amazon DNS Server (p. 163)
• Changing DHCP Options (p. 164)
• Working with DHCP Options Sets (p. 164)
• API and Command Overview (p. 165)
DHCP options sets are associated with your AWS account so that you can use them across all of your
virtual private clouds (VPC).
The Amazon EC2 instances you launch into a nondefault VPC are private by default; they're not assigned
a public IP address unless you specifically assign one during launch, or you modify the subnet's public
IP address attribute. By default, all instances in a nondefault VPC receive an unresolvable host name
that AWS assigns (for example, ip-10-0-0-202).You can assign your own domain name to your instances,
and use up to four of your own DNS servers. To do that, you must specify a special set of DHCP options
to use with the VPC.
The following table lists all the supported options for a DHCP options set.You can specify only the options
you need in your DHCP options set. For more information about the options, see RFC 2132.
162
Amazon Virtual Private Cloud User Guide
Amazon DNS Server
The Amazon DNS server in your VPC is used to resolve the DNS domain names that you specify in a
private hosted zone in Amazon Route 53. For more information about private hosted zones, see Working
with Private Hosted Zones in the Amazon Route 53 Developer Guide.
Services that use the Hadoop framework, such as Amazon EMR, require instances to resolve their own
fully qualified domain names (FQDN). In such cases, DNS resolution can fail if the domain-name-servers
option is set to a custom value. To ensure proper DNS resolution, consider adding a conditional forwarder
on your DNS server to forward queries for the domain region-name.compute.internal to the Amazon
DNS server. For more information about launching an Amazon EMR cluster into a VPC, see Setting Up
a VPC to Host Clusters in the Amazon Elastic MapReduce Developer Guide.
Note
You can use the Amazon DNS server IP address 169.254.169.253, though some servers don't
allow its use. Windows Server 2008, for example, disallows the use of a DNS server located in
the 169.254.x.x network range.
163
Amazon Virtual Private Cloud User Guide
Changing DHCP Options
You can have multiple sets of DHCP options, but you can associate only one set of DHCP options with
a VPC at a time. If you delete a VPC, the DHCP options set associated with the VPC are also deleted.
After you associate a new set of DHCP options with a VPC, any existing instances and all new instances
that you launch in the VPC use these options. You don't need to restart or relaunch the instances. They
automatically pick up the changes within a few hours, depending on how frequently the instance renews
its DHCP lease. If you want, you can explicitly renew the lease using the operating system on the instance.
Topics
• Creating a DHCP Options Set (p. 164)
• Changing the Set of DHCP Options a VPC Uses (p. 164)
• Changing a VPC to use No DHCP Options (p. 165)
• Deleting a DHCP Options Set (p. 165)
The new set of DHCP options appears in your list of DHCP options.
4. Make a note of the ID of the new set of DHCP options (dopt-xxxxxxxx). You will need it to associate
the new set of options with your VPC.
Although you've created a set of DHCP options, you must associate it with your VPC for the options to
take effect. You can create multiple sets of DHCP options, but you can associate only one set of DHCP
options with your VPC at a time.
164
Amazon Virtual Private Cloud User Guide
API and Command Overview
Note
The following procedure assumes that you've already created the DHCP options set you want
to change to. If you haven't, create the options set now. For more information, see Creating a
DHCP Options Set (p. 164).
After you associate a new set of DHCP options with the VPC, any existing instances and all new instances
that you launch in that VPC use the options. You don't need to restart or relaunch the instances. They
automatically pick up the changes within a few hours, depending on how frequently the instance renews
its DHCP lease. If you want, you can explicitly renew the lease using the operating system on the instance.
You don't need to restart or relaunch the instances. They automatically pick up the changes within a few
hours, depending on how frequently the instance renews its DHCP lease. If you want, you can explicitly
renew the lease using the operating system on the instance.
165
Amazon Virtual Private Cloud User Guide
DNS
Associate a set of DHCP options with the specified VPC, or no DHCP options
Domain Name System (DNS) is a standard by which names used on the Internet are resolved to their
corresponding IP addresses. A DNS hostname is a name that uniquely and absolutely names a computer;
it's composed of a host name and a domain name. DNS servers resolve DNS hostnames to their
corresponding IP addresses.
We provide an Amazon DNS server. To use your own DNS server, update the DHCP options set for your
VPC. For more information, see DHCP Options Sets (p. 162).
To enable an EC2 instance to be publicly accessible, it must have a public IP address, a DNS hostname,
and DNS resolution.
Topics
• Viewing DNS Hostnames for Your EC2 Instance (p. 166)
• Updating DNS Support for Your VPC (p. 167)
• Using Private Hosted Zones (p. 169)
You can view the DNS hostnames for a running instance or a network interface using the Amazon EC2
console or the command line.
166
Amazon Virtual Private Cloud User Guide
Updating DNS Support for Your VPC
Instance
To view DNS hostnames for an instance using the console
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon VPC (p. 6).
Network Interface
To view DNS hostnames for a network interface using the console
To view DNS hostnames for a network interface using the command line
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon VPC (p. 6).
We support the following VPC attributes to control DNS support. Be sure to set both attributes to true
if you want your instances to have public DNS hostnames that are accessible from the Internet.
167
Amazon Virtual Private Cloud User Guide
Updating DNS Support for Your VPC
Attribute Description
The Amazon DNS server cannot resolve private DNS hostnames if your VPC's IP address range falls
outside of the private IP addresses ranges specified by RFC 1918.
If you enable DNS hostnames and DNS support in a VPC that didn't previously support them, an instance
that you already launched into that VPC gets a public DNS hostname if it has a public IP address or an
Elastic IP address.
To describe and update DNS support for a VPC using the console
5. To update these settings, choose Actions and either Edit DNS Resolution or Edit DNS Hostnames.
In the dialog box that opens, choose Yes or No, and Save.
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon VPC (p. 6).
You can use one of the following commands. For more information about these command line interfaces,
see Accessing Amazon VPC (p. 6).
168
Amazon Virtual Private Cloud User Guide
Using Private Hosted Zones
To access resources using custom DNS domain names, you must be connected to an instance within
your VPC. From your instance, you can test that your resource in your private hosted zone is accessible
from its custom DNS name by using the ping command; for example, ping
mywebserver.example.com. (You must ensure that your instance's security group rules allow inbound
ICMP traffic for the ping command to work.)
You can access a private hosted zone from an EC2-Classic instance that is linked to your VPC via
ClassicLink, provided your VPC is enabled for ClassicLink DNS support. For more information, see
Enabling ClassicLink DNS Support in the Amazon EC2 User Guide for Linux Instances. Otherwise, private
hosted zones do not support transitive relationships outside of the VPC; for example, you cannot access
your resources using their custom private DNS names from the other side of a VPN connection.
Important
If you are using custom DNS domain names defined in a private hosted zone in Amazon Route 53,
you must set the following VPC attributes to true: enableDnsHostnames and
enableDnsSupport. For more information, see Updating DNS Support for Your VPC (p. 167).
VPC Peering
A VPC peering connection is a networking connection between two VPCs that enables you to route traffic
between them using private IP addresses. Instances in either VPC can communicate with each other as
if they are within the same network. You can create a VPC peering connection between your own VPCs,
or with a VPC in another AWS account within a single region.
AWS uses the existing infrastructure of a VPC to create a VPC peering connection; it is neither a gateway
nor a VPN connection, and does not rely on a separate piece of physical hardware. There is no single
point of failure for communication or a bandwidth bottleneck.
A VPC peering connection can help you to facilitate the transfer of data; for example, if you have more
than one AWS account, you can peer the VPCs across those accounts to create a file sharing network.
You can also use a VPC peering connection to allow other VPCs to access resources you have in one
of your VPCs. For more examples of scenarios in which you can use a VPC peering connection, see the
Amazon VPC Peering Guide.
Topics
• VPC Peering Basics (p. 170)
• Working with VPC Peering Connections (p. 172)
169
Amazon Virtual Private Cloud User Guide
VPC Peering Basics
A VPC peering connection is a one to one relationship between two VPCs. You can create multiple VPC
peering connections for each VPC that you own, but transitive peering relationships are not supported:
you will not have any peering relationship with VPCs that your VPC is not directly peered with.
The following diagram is an example of one VPC peered to two different VPCs. There are two VPC
peering connections: VPC A is peered with both VPC B and VPC C. VPC B and VPC C are not peered,
and you cannot use VPC A as a transit point for peering between VPC B and VPC C. If you want to enable
routing of traffic between VPC B and VPC C, you must create a unique VPC peering connection between
them.
For more information about VPC peering limitations, see VPC Peering Limitations (p. 171). For more
information and examples of peering relationships that are supported, see the Amazon VPC Peering
Guide.
The charges for transferring data within a VPC peering connection are the same as the charges for
transferring data across Availability Zones. For more information, see Amazon EC2 Pricing.
170
Amazon Virtual Private Cloud User Guide
VPC Peering Basics
• Initiating-request: A request for a VPC peering connection has been initiated. At this stage, the peering
connection may fail or may go to pending-acceptance.
• Failed: The request for the VPC peering connection has failed. During this state, it cannot be accepted
or rejected. The failed VPC peering connection remains visible to the requester for 2 hours.
• Pending-acceptance: The VPC peering connection request is awaiting acceptance from the owner
of the peer VPC. During this state, the owner of the requester VPC can delete the request, and the
owner of the peer VPC can accept or reject the request. If no action is taken on the request, it will expire
after 7 days.
• Expired: The VPC peering connection request has expired, and no action can be taken on it by either
VPC owner. The expired VPC peering connection remains visible to both VPC owners for 2 days.
• Rejected: The owner of the peer VPC has rejected a pending-acceptance VPC peering connection
request. During this state, the request cannot be accepted. The rejected VPC peering connection
remains visible to the owner of the requester VPC for 2 days, and visible to the owner of the peer VPC
for 2 hours. If the request was created within the same AWS account, the rejected request remains
visible for 2 hours.
• Provisioning: The VPC peering connection request has been accepted, and will soon be in the active
state.
• Active: The VPC peering connection is active. During this state, either of the VPC owners can delete
the VPC peering connection, but cannot reject it.
• Deleted: An active VPC peering connection has been deleted by either of the VPC owners, or a
pending-acceptance VPC peering connection request has been deleted by the owner of the requester
VPC. During this state, the VPC peering connection cannot be accepted or rejected. The VPC peering
connection remains visible to the party that deleted it for 2 hours, and visible to the other party for 2
days. If the VPC peering connection was created within the same AWS account, the deleted request
remains visible for 2 hours.
• You cannot create a VPC peering connection between VPCs that have matching or overlapping CIDR
blocks.
• You cannot create a VPC peering connection between VPCs in different regions.
• You have a limit on the number active and pending VPC peering connections that you can have per
VPC. For more information about VPC limits, see Amazon VPC Limits (p. 210).
• VPC peering does not support transitive peering relationships; in a VPC peering connection, your VPC
will not have access to any other VPCs that the peer VPC may be peered with. This includes VPC
peering connections that are established entirely within your own AWS account. For more information
and examples of peering relationships that are supported, see the Amazon VPC Peering Guide.
171
Amazon Virtual Private Cloud User Guide
Working with VPC Peering Connections
• You cannot have more than one VPC peering connection between the same two VPCs at the same
time.
• The Maximum Transmission Unit (MTU) across a VPC peering connection is 1500 bytes.
• A placement group can span peered VPCs; however, you will not get full-bisection bandwidth between
instances in peered VPCs. For more information about placement groups, see Placement Groups in
the Amazon EC2 User Guide for Linux Instances.
• Unicast reverse path forwarding in VPC peering connections is not supported. For more information,
see Routing for Response Traffic in the Amazon VPC Peering Guide.
• You cannot reference a security group from the peer VPC as a source or destination for ingress or
egress rules in your security group. Instead, reference CIDR blocks of the peer VPC as the source or
destination of your security group's ingress or egress rules.
• An instance's public DNS hostname will not resolve to its private IP address across peered VPCs.
• Name: You can optionally name your VPC peering connection. Doing so creates a tag with a key
of Name and a value that you specify.
• Local VPC to peer: Select the VPC in your account with which you want to create the VPC peering
connection.
• Select a VPC to peer with: Ensure My account is selected, and select another of your VPCs
from the VPC ID list. Only VPCs in the current region are displayed.
Important
Ensure that your VPCs do not have overlapping CIDR blocks. If they do, the status of the
VPC peering connection immediately goes to failed.
172
Amazon Virtual Private Cloud User Guide
Working with VPC Peering Connections
5. A confirmation dialog box provides the ID of the VPC peering connection, as well as information
about the VPCs in the peering connection. Click OK.
6. To view all VPC peering connections that are pending your acceptance, select Requests pending
my approval from the filter list.
7. Select the VPC peering connection that you've created, and click Accept request.
8. In the confirmation dialog, click Yes, Accept. A second confirmation dialog displays; click Modify
my route tables now to go directly to the route tables page, or click Close to do this later.
Now that your VPC peering connection is active, you must add an entry to your VPCs' route tables to
enable traffic to be directed between the peered VPCs. For more information, see Updating Route Tables
for Your VPC Peering Connection (p. 174).
• Name: You can optionally name your VPC peering connection. Doing so creates a tag with a key
of Name and a value that you specify. This tag is only visible to you; the owner of the peer VPC
can create their own tags for the VPC peering connection.
• Local VPC to peer: Select the VPC in your account with which to create the VPC peering
connection.
• Select a VPC to peer with: Select Another account, and enter the AWS account ID and the ID
of the VPC with which to create the VPC peering connection.
Important
If your VPC and the peer VPC have overlapping CIDR blocks, or if the account ID and
VPC ID are incorrect or do not correspond with each other, the status of the VPC peering
connection immediately goes to failed.
5. A confirmation dialog box provides the ID of the VPC peering connection, as well as information
about the VPCs in the peering connection. Click OK.
The VPC peering connection that you've created is not active. To activate it, the owner of the peer VPC
must accept the VPC peering connection request. To enable traffic to be directed to the peer VPC, update
your VPC's route table. For more information, see Updating Route Tables for Your VPC Peering
Connection (p. 174).
173
Amazon Virtual Private Cloud User Guide
Working with VPC Peering Connections
Important
Do not accept VPC peering connections from AWS accounts that you do not know. A malicious
user may have sent you a VPC peering connection request to gain unauthorized network access
to your VPC. This is known as peer phishing. You can safely reject unwanted VPC peering
connection requests without any risk of the requester gaining access to any information about
your AWS account or your VPC. For more information about rejecting VPC peering requests,
see Rejecting a VPC Peering Connection (p. 174). You can also ignore the request and let it
expire; by default, the request expires after 7 days.
Now that your VPC peering connection is active, you must add an entry to your VPC's route table to
enable traffic to be directed to the peer VPC. For more information, see Updating Route Tables for Your
VPC Peering Connection (p. 174).
Similarly, the owner of the other VPC in the peering connection must add a route to one of their VPC's
route tables to direct traffic back to your VPC. For more examples of supported route table configurations
for VPC peering connections, see the Amazon VPC Peering Guide.
You can add a route for a VPC peering connection that's in the pending-acceptance state; however,
the route will have a state of blackhole and have no effect until the VPC peering connection is in the
active state.
For more information about route tables, see Route Tables (p. 126).
174
Amazon Virtual Private Cloud User Guide
Working with VPC Peering Connections
Warning
If you have a VPC peered with multiple VPCs that have overlapping or matching CIDR blocks,
ensure that your route tables are configured to avoid sending response traffic from your VPC to
the incorrect VPC. AWS currently does not support unicast reverse path forwarding in VPC
peering connections that checks the source IP of packets and routes reply packets back to the
source. For more information, see Routing for Response Traffic in the Amazon VPC Peering
Guide.
175
Amazon Virtual Private Cloud User Guide
API and CLI Overview
Note
Deleting a VPC in the VPC console that's part of an active VPC peering connection deletes the
VPC peering connection. If you have requested a VPC peering connection with a VPC in another
account, and you delete your VPC before the other party has accepted the request, the VPC
peering connection is deleted. You cannot delete a VPC for which you have a
pending-acceptance request from a VPC in another account. You must first reject the VPC
peering connection request.
176
Amazon Virtual Private Cloud User Guide
Controlling Access to VPC Peering Connections
For example policies for working with VPC peering connections, see Controlling Access to Amazon VPC
Resources (p. 90).
VPC Endpoints
A VPC endpoint enables you to create a private connection between your VPC and another AWS service
without requiring access over the Internet, through a NAT device, a VPN connection, or AWS Direct
Connect. Endpoints are virtual devices. They are horizontally scaled, redundant, and highly available
VPC components that allow communication between instances in your VPC and AWS services without
imposing availability risks or bandwidth constraints on your network traffic.
Important
Currently, we support endpoints for connections with Amazon S3 only. We'll add support for
other AWS services later. Endpoints are supported within the same region only.
An endpoint enables instances in your VPC to use their private IP addresses to communicate with
resources in other services. Your instances do not require public IP addresses, and you do not need an
Internet gateway, a NAT device, or a virtual private gateway in your VPC. You use endpoint policies to
control access to resources in other services. Traffic between your VPC and the AWS service does not
leave the Amazon network.
There is no additional charge for using endpoints. Standard charges for data transfer and resource usage
apply. For more information about pricing, see Amazon EC2 Pricing.
177
Amazon Virtual Private Cloud User Guide
Endpoint Basics
Topics
• Endpoint Basics (p. 178)
• Controlling the Use of Endpoints (p. 182)
• Controlling Access to Services (p. 182)
• Working with Endpoints (p. 185)
• API and CLI Overview (p. 187)
Endpoint Basics
To create an endpoint, specify the VPC and the service to which you're connecting. A service is identified
by a prefix list, or the name and ID of a service for a region. A prefix list ID uses the form pl-xxxxxxx
and a prefix list name uses the form com.amazonaws.<region>.<service>. You use the prefix list
name (service name) to create an endpoint.
You can attach an endpoint policy to your endpoint that allows access to some or all of the service to
which you're connecting. For more information, see Using Endpoint Policies (p. 182). To control the routing
of traffic between your VPC and the other service, you can specify one or more route tables that are used
by the VPC to reach the endpoint. Subnets that use these route tables have access to the endpoint, and
traffic from instances in these subnets to the service is then routed through the endpoint.
You can also use the VPC wizard on the dashboard of the Amazon VPC console to create a new VPC,
and request an endpoint for the service that you specify.
After you've created an endpoint, you can modify the policy that's attached to your endpoint, and add or
remove the route tables that are used by the endpoint.
You can create multiple endpoints in a single VPC, for example, to multiple services. You can also create
multiple endpoints for a single service, and you can use different route tables to enforce different access
policies from different subnets to the same service.
Topics
• Routing for Endpoints (p. 178)
• Endpoints for Amazon S3 (p. 180)
• Endpoint Limitations (p. 181)
We use the most specific route that matches the traffic to determine how to route the traffic (longest prefix
match). If you have an existing route in your route table for all Internet traffic (0.0.0.0/0) that points to
an Internet gateway, the endpoint route takes precedence for all traffic destined for the service, because
the IP address range for the service is more specific than 0.0.0.0/0. All other Internet traffic goes to
your Internet gateway, including traffic that's destined for the service in other regions. However, if you
have existing, more specific routes to IP address ranges that point to an Internet gateway or a NAT device,
those routes take precedence. If you have existing routes destined for an IP address range that is identical
to the IP address range used by the service, then your routes take precedence.
178
Amazon Virtual Private Cloud User Guide
Endpoint Basics
To view the current IP address range for a service, you can use the describe-prefix-lists command or the
ec2-describe-prefix-lists command.
Note
The range of public IP addresses for a service may change from time to time. Consider the
implications before you make routing or other decisions based on the current IP address range
for a service.
You can have multiple endpoint routes to different services in a route table, and you can have multiple
endpoint routes to the same service in different route tables, but you cannot have multiple endpoints to
the same service in a single route table. For example, if you have two endpoints to Amazon S3 in your
VPC, you cannot use the same route table for both endpoints.
You cannot explicitly add, modify, or delete an endpoint route in your route table by using the route table
APIs, or by using the Route Tables page in the VPC console. You can only add an endpoint route by
associating a route table with an endpoint. The endpoint route is automatically deleted when you remove
the route table association from the endpoint (by modifying the endpoint), or when you delete your endpoint.
To change the route tables that are associated with your endpoint, you can modify the endpoint. For more
information, see Modifying an Endpoint (p. 186).
In this scenario, you have an existing route in your route table for all Internet traffic (0.0.0.0/0) that
points to an Internet gateway. Any traffic from the subnet that's destined for another AWS service uses
the Internet gateway.
Destination Target
10.0.0.0/16 Local
0.0.0.0/0 igw-1a2b3c4d
You create an endpoint to Amazon S3, and associate your route table with the endpoint. An endpoint
route is automatically added to the route table, with a destination of pl-1a2b3c4d (assume this represents
Amazon S3). Now, any traffic from the subnet that's destined for Amazon S3 in the same region goes to
the endpoint, and does not go to the Internet gateway. All other Internet traffic goes to your Internet
gateway, including traffic that's destined for other services, and destined for Amazon S3 in other regions.
Destination Target
10.0.0.0/16 Local
0.0.0.0/0 igw-1a2b3c4d
pl-1a2b3c4d vpce-11bb22cc
In this scenario, you have configured your route table to enable instances in your subnet to communicate
with Amazon S3 buckets through an Internet gateway. You've added a route with 54.123.165.0/24
as a destination (assume this is an IP address range currently within Amazon S3), and the Internet
gateway as the target. You then create an endpoint, and associate this route table with the endpoint. An
endpoint route is automatically added to the route table. You then use the describe-prefix-lists command
to view the IP address range for Amazon S3. The range is 54.123.160.0/19, which is less specific
than the range that's pointing to your Internet gateway. This means that any traffic destined for the
54.123.165.0/24 IP address range continues to use the Internet gateway, and does not use the
endpoint (for as long as this remains the public IP address range for Amazon S3).
179
Amazon Virtual Private Cloud User Guide
Endpoint Basics
Destination Target
10.0.0.0/16 Local
54.123.165.0/24 igw-1a2b3c4d
pl-1a2b3c4d vpce-11bb22cc
To ensure that all traffic destined for Amazon S3 in the same region is routed via the endpoint, you must
adjust the routes in your route table. To do this, you can delete the route to the Internet gateway. Now,
all traffic to Amazon S3 in the same region uses the endpoint, and the subnet that's associated with your
route table is a private subnet.
Destination Target
10.0.0.0/16 Local
pl-1a2b3c4d vpce-11bb22cc
• Your endpoint has a policy that controls the use of the endpoint to access Amazon S3 resources. The
default policy allows access by any user or service within the VPC, using credentials from any AWS
account, to any Amazon S3 resource; including Amazon S3 resources for an AWS account other than
the account with which the VPC is associated. For more information, see Controlling Access to
Services (p. 182).
• The source IP addresses from instances in your affected subnets as received by Amazon S3 will change
from public IP addresses to the private IP addresses from your VPC. An endpoint switches network
routes, and disconnects open TCP connections. Your tasks will be interrupted during the changeover,
and any previous connections using public IP addresses will not be resumed. We recommend that you
do not have any critical tasks running when you create or modify an endpoint; or that you test to ensure
that your software can automatically reconnect to Amazon S3 after the connection break.
• If you've used IP address conditions in your bucket policies to control access to your S3 buckets (using
the aws:SourceIp condition), access to your buckets is denied when the source IP addresses change
to private IP addresses.You cannot use the aws:SourceIp condition in your bucket policies for private
IP addresses in your VPC — that condition is ignored for any requests to Amazon S3 via the endpoint.
Instead, adjust your bucket policy to limit access to a specific VPC or a specific endpoint. For more
information, see Using Amazon S3 Bucket Policies (p. 183).
• You must enable DNS resolution in your VPC for endpoints to work. For more information, see Using
DNS with Your VPC (p. 166).
• Endpoints currently do not support cross-region requests—ensure that you create your endpoint in the
same region as your bucket. You can find the location of your bucket by using the Amazon S3 console,
or by using the get-bucket-location command. Use a region-specific Amazon S3 endpoint to access
your bucket; for example, mybucket.s3-us-west-2.amazonaws.com. For more information about
region-specific endpoints for Amazon S3, see Amazon Simple Storage Service (S3) in Amazon Web
Services General Reference. If you use the AWS CLI to make requests to Amazon S3, set your default
region to the same region as your bucket, or use the --region parameter in your requests.
Note
Treat Amazon S3's US Standard region as mapped to the us-east-1 region.
180
Amazon Virtual Private Cloud User Guide
Endpoint Basics
If you use other AWS services in your VPC, such as Amazon Elastic MapReduce, they may use S3
buckets for certain tasks. Ensure that your endpoint policy allows full access to Amazon S3 (the default
policy), or that it allows access to the specific buckets that are used by these services. Alternatively, only
create an endpoint in a subnet that is not used by any of these services, to allow the services to continue
accessing S3 buckets using public IP addresses.
The following table lists AWS services that may be affected by an endpoint, and any specific information
for each service.
AWS CloudFormation If you have resources in your VPC that must re-
spond to a wait condition or custom resource re-
quest, your endpoint policy must allow at least ac-
cess to the specific buckets that are used by these
resources. For more information, see AWS Cloud-
Formation and VPC Endpoints.
Amazon Elastic MapReduce Your subnet's route table must include a route to
an Internet gateway, and your endpoint policy must
allow full access to Amazon S3. For more informa-
tion, see VPC Errors in the Amazon Elastic
MapReduce Developer Guide.
Traffic between your VPC and S3 buckets does not leave the Amazon network.
Endpoint Limitations
To use endpoints, you need to be aware of the current limitations:
181
Amazon Virtual Private Cloud User Guide
Controlling the Use of Endpoints
• You cannot use prefix list IDs to create an outbound rule in a network ACL that allows or denies outbound
traffic to the service specified in an endpoint. Instead, you can use a prefix list ID in an outbound security
group rule. For more information, see Security Groups (p. 185).
• You cannot create an endpoint between a VPC and an AWS service in a different region.
• You cannot tag an endpoint.
• You cannot transfer an endpoint from one VPC to another, or from one service to another.
• Endpoint connections cannot be extended out of a VPC. Resources on the other side of a VPN
connection, a VPC peering connection, an AWS Direct Connect connection, or a ClassicLink connection
in your VPC cannot use the endpoint to communicate with resources in the endpoint service.
• When using Amazon S3 endpoints, you cannot use a bucket policy or an IAM policy to allow access
from a VPC CIDR range (the private IP address range). VPC CIDR blocks can be overlapping or
identical, which may lead to unexpected results. Instead, you can use a bucket policy to restrict access
to a specific endpoint or to a specific VPC, and you can use your route tables to control which instances
can access resources in Amazon S3 via the endpoint.
Endpoint policies and Amazon S3 bucket policies must be written in JSON format.
Topics
• Using Endpoint Policies (p. 182)
• Using Amazon S3 Bucket Policies (p. 183)
• Security Groups (p. 185)
You cannot attach more than one policy to an endpoint; however, you can modify the policy at any time.
Note that if you do modify a policy, it can take a few minutes for the changes to take effect. For more
information, see Modifying an Endpoint (p. 186). For more information about writing policies, see Overview
of IAM Policies in the IAM User Guide.
Your endpoint policy can be like any IAM policy; however, take note of the following:
182
Amazon Virtual Private Cloud User Guide
Controlling Access to Services
• Only the parts of the policy that relate to the specified service will work. You cannot use an endpoint
policy to allow resources in your VPC to perform other actions; for example, if you add EC2 actions to
an endpoint policy for an endpoint to Amazon S3, they will have no effect.
• Your policy must contain a Principal element. For more information, see Principal in the IAM User
Guide.
You can create a policy that restricts access to specific S3 buckets only. This is useful if you have other
AWS services in your VPC that use S3 buckets. The following is an example of a policy that restricts
access to my_secure_bucket only.
{
"Statement": [
{
"Sid": "Access-to-specific-bucket-only",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::my_secure_bucket",
"arn:aws:s3:::my_secure_bucket/*"]
}
]
}
The Amazon Linux AMI repositories are Amazon S3 buckets in each region. If you want instances in your
VPC to access the repositories through an endpoint, you can create an endpoint policy that enables
access to these buckets.
{
"Statement": [
{
"Sid": "AmazonLinuxAMIRepositoryAccess",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::packages.*.amazonaws.com/*",
"arn:aws:s3:::repo.*.amazonaws.com/*"
]
}
]
}
183
Amazon Virtual Private Cloud User Guide
Controlling Access to Services
For more information about bucket policies for Amazon S3, see Using Bucket Policies and User Policies
in Amazon Simple Storage Service Developer Guide.
The following is an example of an S3 bucket policy that allows access to a specific bucket,
my_secure_bucket, from endpoint vpce-1a2b3c4d only. The policy denies all access to the bucket if
the specified endpoint is not being used. The aws:sourceVpce condition is used to specify the endpoint.
The aws:sourceVpce condition does not require an ARN for the VPC endpoint resource, only the
endpoint ID.
{
"Version": "2012-10-17",
"Id": "Policy1415115909152",
"Statement": [
{
"Sid": "Access-to-specific-VPCE-only",
"Principal": "*",
"Action": "s3:*",
"Effect": "Deny",
"Resource": ["arn:aws:s3:::my_secure_bucket",
"arn:aws:s3:::my_secure_bucket/*"],
"Condition": {
"StringNotEquals": {
"aws:sourceVpce": "vpce-1a2b3c4d"
}
}
}
]
}
You can create a bucket policy that restricts access to a specific VPC by using the aws:sourceVpc
condition. This is useful if you have multiple endpoints configured in the same VPC, and you want to
manage access to your S3 buckets for all of your endpoints. The following is an example of a policy that
allows VPC vpc-111bbb22 to access my_secure_bucket and its objects. The policy denies all access
to the bucket if the specified VPC is not being used. The aws:sourceVpc condition does not require an
ARN for the VPC resource, only the VPC ID.
{
"Version": "2012-10-17",
"Id": "Policy1415115909152",
"Statement": [
{
"Sid": "Access-to-specific-VPC-only",
"Principal": "*",
"Action": "s3:*",
"Effect": "Deny",
"Resource": ["arn:aws:s3:::my_secure_bucket",
"arn:aws:s3:::my_secure_bucket/*"],
"Condition": {
"StringNotEquals": {
"aws:sourceVpc": "vpc-111bbb22"
}
}
}
184
Amazon Virtual Private Cloud User Guide
Working with Endpoints
]
}
Security Groups
By default, Amazon VPC security groups allow all outbound traffic, unless you've specifically restricted
outbound access. If your security group's outbound rules are restricted, you must add a rule that allows
outbound traffic from your VPC to the service that's specified in your endpoint. To do this, you can use
the service's prefix list ID as the destination in the outbound rule. For more information, see Modifying
Your Security Group (p. 186).
Topics
• Creating an Endpoint (p. 185)
• Modifying Your Security Group (p. 186)
• Modifying an Endpoint (p. 186)
• Describing Your Endpoints (p. 187)
• Deleting an Endpoint (p. 187)
Creating an Endpoint
To create an endpoint, you must specify the VPC in which you want to create the endpoint, and the service
to which you want to establish the connection. You can also attach a policy to the endpoint, and specify
the route tables that will be used by the endpoint.
To create an endpoint
• Select a VPC in which to create the endpoint, and the service to which you want to connect.
(Currently, only the Amazon S3 service is available.)
• Choose the type of policy. You can leave the default option, Full Access, to allow full access to
the service. Alternatively, you can select Custom, and then use the AWS Policy Generator to
create a custom policy, or type your own policy in the policy window.
5. In the second step of the wizard, select the route tables that will be used by the endpoint. The wizard
automatically adds a route to those tables that points traffic destined for the service to the endpoint.
When you are done, choose Create Endpoint.
You can use the VPC wizard to create a new VPC and to create an endpoint at the same time. Instead
of specifying the route tables that are used by the endpoint, you specify the subnets that will have access
to the endpoint. The wizard adds an endpoint route to the route tables associated with those subnets.
185
Amazon Virtual Private Cloud User Guide
Working with Endpoints
• Select the subnets that will have access to the endpoint from the Subnet list. The route tables
associated with the subnets will include an endpoint route.
• Select the type of policy from the Policy list. You can leave the default option, Full Access, to
allow full access to the service. Alternatively, choose Custom, and then use the AWS Policy
Generator to create a custom policy, or type your own policy in the policy window.
5. If applicable, complete the rest of the steps in the wizard, and then click Create VPC.
For more information about security groups, see Security Groups for Your VPC (p. 63).
Modifying an Endpoint
You can modify your endpoint by changing or removing its policy, and adding or removing the route tables
that are used by the endpoint.
186
Amazon Virtual Private Cloud User Guide
API and CLI Overview
Note
It can take a few minutes for policy changes to take effect.
On the Route Tables tab, you can view information about the route tables that are used by the
endpoint. On the Policy tab, you can view the IAM policy that's attached to your endpoint.
Note
The Policy tab only displays the endpoint policy. It does not display any information about
IAM policies for IAM users that have permission to work with endpoints. It also does not
display service-specific policies; for example, S3 bucket policies.
Deleting an Endpoint
If you no longer require an endpoint, you can delete it. Deleting an endpoint also deletes the endpoint
routes in the route tables that were used by the endpoint, but doesn't affect any security groups associated
with the VPC in which the endpoint resides.
To delete an endpoint
187
Amazon Virtual Private Cloud User Guide
API and CLI Overview
Get the prefix list name, ID, and IP address range for an AWS service
188
Amazon Virtual Private Cloud User Guide
VPN Connections
You can connect your VPC to remote networks by using a VPN connection. The following are some of
the connectivity options available to you.
AWS hardware VPN You can create an IPsec, hardware VPN connection between your VPC and
your remote network. On the AWS side of the VPN connection, a virtual
private gateway provides two VPN endpoints for automatic failover. You
configure your customer gateway, which is the physical device or software
application on the remote side of the VPN connection. For more information,
see Adding a Hardware Virtual Private Gateway to Your VPC (p. 190), and
the Amazon VPC Network Administrator Guide.
AWS Direct Connect AWS Direct Connect provides a dedicated private connection from a remote
network to your VPC.You can combine this connection with an AWS hardware
VPN connection to create an IPsec-encrypted connection. For more informa-
tion, see What is AWS Direct Connect? in the AWS Direct Connect User
Guide.
AWS VPN CloudHub If you have more than one remote network (for example, multiple branch of-
fices), you can create multiple AWS hardware VPN connections via your VPC
to enable communication between these networks. For more information,
see Providing Secure Communication Between Sites Using VPN
CloudHub (p. 202).
Software VPN You can create a VPN connection to your remote network by using an Amazon
EC2 instance in your VPC that's running a software VPN appliance. AWS
does not provide or maintain software VPN appliances; however, you can
choose from a range of products provided by partners and open source
communities. Find software VPN appliances on the AWS Marketplace.
189
Amazon Virtual Private Cloud User Guide
Hardware Virtual Private Gateway
For more information about the different VPC and VPN connectivity options, see the Amazon Virtual
Private Cloud Connectivity Options whitepaper.
You can complete this process manually, as described on this page, or let the VPC creation wizard take
care of many of these steps for you. For more information about using the VPC creation wizard to set up
the virtual private gateway, see Scenario 3: VPC with Public and Private Subnets and Hardware VPN
Access (p. 32) or Scenario 4: VPC with a Private Subnet Only and Hardware VPN Access (p. 41).
Although the term VPN connection is a general term, in the Amazon VPC documentation, a VPN connection
refers to the connection between your VPC and your own network. AWS supports Internet Protocol
security (IPsec) VPN connections.
Topics
• Components of Your VPN (p. 190)
• VPN Configuration Examples (p. 191)
• VPN Routing Options (p. 192)
• What You Need for a VPN Connection (p. 192)
• Configuring Two VPN Tunnels for Your VPN Connection (p. 193)
• Using Redundant VPN Connections to Provide Failover (p. 194)
• Setting Up the VPN Connection (p. 195)
• Testing the End-to-End Connectivity of Your Instance (p. 198)
• Replacing Compromised Credentials (p. 199)
• Editing Static Routes for a VPN Connection (p. 199)
• Deleting a VPN Connection (p. 199)
• API and CLI Overview (p. 200)
For information about how you're charged for using a VPN connection with your VPC, see the Amazon
VPC product page.
For information about how many virtual private gateways you can have per region, as well as the limits
for other components within your VPC, see Amazon VPC Limits (p. 210).
190
Amazon Virtual Private Cloud User Guide
VPN Configuration Examples
Customer Gateway
A customer gateway is a physical device or software application on your side of the VPN connection.
When you create a VPN connection, the VPN tunnel comes up when traffic is generated from your side
of the VPN connection. The virtual private gateway is not the initiator; your customer gateway must initiate
the tunnels. If your VPN connection experiences a period of idle time (usually 10 seconds, depending on
your configuration), the tunnel may go down. To prevent this, you can use a network monitoring tool to
generate keepalive pings; for example, by using IP SLA.
For more information about customer gateways, see Your Customer Gateway in the Amazon VPC Network
Administrator Guide.
For a list of customer gateways that we have tested with Amazon VPC, see Amazon Virtual Private Cloud
FAQs.
When you create multiple VPN connections to a single VPC, you can configure a second customer
gateway to create a redundant connection to the same external location. You can also use it to create
VPN connections to multiple geographic locations.
191
Amazon Virtual Private Cloud User Guide
VPN Routing Options
The type of routing that you select can depend on the make and model of your VPN devices. If your VPN
device supports Border Gateway Protocol (BGP), specify dynamic routing when you configure your VPN
connection. If your device does not support BGP, specify static routing. For a list of static and dynamic
routing devices that have been tested with Amazon VPC, see the Amazon Virtual Private Cloud FAQs.
When you use a BGP device, you don't need to specify static routes to the VPN connection because the
device uses BGP to advertise its routes to the virtual private gateway. If you use a device that doesn't
support BGP, you must select static routing and enter the routes (IP prefixes) for your network that should
be communicated to the virtual private gateway. Only IP prefixes that are known to the virtual private
gateway, whether through BGP advertisement or static route entry, can receive traffic from your VPC.
The virtual private gateway does not route any other traffic destined outside of the received BGP
advertisements, static route entries, or its attached VPC CIDR.
We recommend that you use BGP-capable devices, when available, because the BGP protocol offers
robust liveness detection checks that can assist failover to the second VPN tunnel if the first tunnel goes
down. Devices that don't support BGP may also perform health checks to assist failover to the second
tunnel when needed.
192
Amazon Virtual Private Cloud User Guide
Configuring Two VPN Tunnels for Your VPN Connection
connection. Your network administrator typically performs this configuration. For information about the
customer gateway requirements and configuration, see the Amazon VPC Network Administrator Guide.
The following table lists the information that you need to have so that we can establish your VPN
connection.
The type of customer gateway Specifies how to format the re- For information about the specific
(for example, Cisco ASA, Juniper turned information that you use devices that we've tested, see
J-Series, Juniper SSG, Yamaha) to configure the customer gate- What customer gateway devices
way. are known to work with Amazon
VPC? in the Amazon VPC FAQ.
Internet-routable IP address Used to create and configure The IP address value must be
(static) of the customer gateway's your customer gateway (it's re- static and may be behind a device
external interface. ferred to as YOUR_UPLINK_ performing network address
ADDRESS) translation (NAT). To ensure that
NAT traversal (NAT-T) can func-
tion, you must adjust your firewall
rules to unblock UDP port 4500.
(Optional) Border Gateway Pro- Used to create and configure You can use an existing ASN as-
tocol (BGP) Autonomous System your customer gateway (referred signed to your network. If you
Number (ASN) of the customer to as YOUR_BGP_ASN). don't have one, you can use a
gateway, if you are creating a If you use the VPC wizard in the private ASN (in the 64512–65534
dynamically routed VPN connec- console to set up your VPC, we range). For more information
tion. automatically use 65000 as the about ASNs, see the Wikipedia
ASN. article.
Amazon VPC supports 2-byte
ASN numbers.
The following diagram shows the two tunnels of the VPN connection.
193
Amazon Virtual Private Cloud User Guide
Using Redundant VPN Connections to Provide Failover
The following diagram shows the two tunnels of the VPN connection and two customer gateways.
194
Amazon Virtual Private Cloud User Guide
Setting Up the VPN Connection
Dynamically routed VPN connections use the Border Gateway Protocol (BGP) to exchange routing
information between your customer gateways and the virtual private gateways. Statically routed VPN
connections require you to enter static routes for the network on your side of the customer gateway.
BGP-advertised and statically entered route information allow gateways on both sides to determine which
tunnels are available and reroute traffic if a failure occurs. We recommend that you configure your network
to use the routing information provided by BGP (if available) to select an available path. The exact
configuration depends on the architecture of your network.
195
Amazon Virtual Private Cloud User Guide
Setting Up the VPN Connection
These procedures assume that you have a VPC with one or more subnets, and that you have the required
network information (see What You Need for a VPN Connection (p. 192)).
• In the Name tag field, optionally enter a name for your customer gateway. Doing so creates a tag
with a key of Name and the value that you specify.
• Select the routing type from the Routing list.
• If you selected dynamic routing, enter the Border Gateway Protocol (BGP) Autonomous System
Number (ASN) in the BGP ASN field.
• Enter the static, Internet-routable IP address for your customer gateway device in the IP Address
field. The address may be behind a device performing network address translation (NAT).
1. In the navigation pane, choose Virtual Private Gateways, and then Create Virtual Private Gateway.
2. You can optionally enter a name for your virtual private gateway, and then choose Yes, Create.
3. Select the virtual private gateway that you created, and then choose Attach to VPC.
4. In the Attach to VPC dialog box, select your VPC from the list, and then choose Yes, Attach.
For static routing, the static IP prefixes that you specify for your VPN configuration are propagated to the
route table after you've created the VPN connection. For dynamic routing, the BGP-advertised routes
from your customer gateway are propagated to the route table when the status of the VPN connection is
UP.
196
Amazon Virtual Private Cloud User Guide
Setting Up the VPN Connection
1. In the navigation pane, choose Route Tables, and then select the route table that's associated with
the subnet; by default, this is the main route table for the VPC.
2. On the Route Propagation tab in the details pane, choose Edit, select the virtual private gateway
that you created in the previous procedure, and then choose Save.
Note
For static routing, if you do not enable route propagation, you must manually enter the static
routes used by your VPN connection. To do this, select your route table, then on the Routes
tab in the details pane, choose Edit. Add the static route used by your VPN connection in the
Destination field, select the virtual private gateway ID from the Target list, and then choose
Save.
1. In the navigation pane, choose Security Groups, and then select the default security group for the
VPC.
2. On the Inbound tab in the details pane, add rules that allow inbound SSH, RDP, and ICMP access
from your network, and then choose Save. For more information about adding inbound rules, see
Adding and Removing Rules (p. 67).
1. In the navigation pane, choose VPN Connections, and then Create VPN Connection.
2. In the Create VPN Connection dialog box, do the following, and then choose Yes, Create:
• In the Name tag field, optionally enter a name for your VPN connection. Doing so creates a tag
with a key of Name and the value that you specify.
• Select the virtual private gateway that you created earlier.
• Select the customer gateway that you created earlier.
• Select one of the routing options based on whether your VPN router supports Border Gateway
Protocol (BGP):
• If your VPN router supports BGP, select Dynamic (requires BGP).
• If your VPN router does not support BGP, select Static. In the Static IP Prefixes field, specify
each IP prefix for the private network of your VPN connection, separated by commas.
3. It may take a few minutes to create the VPN connection. When it's ready, select the connection, and
then choose Download Configuration.
4. In the Download Configuration dialog box, select the vendor, platform, and software that corresponds
to your customer gateway device or software, and then choose Yes, Download.
5. Give the configuration file to your network administrator, along with this guide: Amazon VPC Network
Administrator Guide. After the network administrator configures the customer gateway, the VPN
connection is operational.
197
Amazon Virtual Private Cloud User Guide
Testing the End-to-End Connectivity of Your Instance
You can monitor the status of your VPN connections using the Amazon VPC console or by using the
Amazon EC2 API/CLI. You can view information about your VPN connections, including its state, the
time since last state change, and descriptive error text.
1. After the instance is running, get its private IP address (for example, 10.0.0.4). The Amazon EC2
console displays the address as part of the instance's details.
2. From a computer in your network that is behind the customer gateway, use the ping command with
the instance's private IP address. A successful response is similar to the following:
198
Amazon Virtual Private Cloud User Guide
Replacing Compromised Credentials
You can now use SSH or RDP to connect to your instance in the VPC. For more information about how
to connect to a Linux instance, see Connect to Your Linux Instance in the Amazon EC2 User Guide for
Linux Instances. For more information about how to connect to a Windows instance, see Connect to Your
Windows Instance in the Amazon EC2 User Guide for Microsoft Windows Instances.
1. Delete the VPN connection. For more information, see Deleting a VPN Connection (p. 199).You don't
need to delete the VPC or the virtual private gateway.
2. Create a new VPN connection and download the new configuration file. For more information, see
Create a VPN Connection and Configure the Customer Gateway (p. 197).
Note
If you have not enabled route propagation for your route table, you must manually update the
routes in your route table to reflect the updated static IP prefixes in your VPN connection. For
more information, see Enable Route Propagation in Your Route Table (p. 196).
199
Amazon Virtual Private Cloud User Guide
API and CLI Overview
If you no longer require a customer gateway, you can delete it. You can't delete a customer gateway
that's being used in a VPN connection.
If you no longer require a virtual private gateway for your VPC, you can detach it.
If you no longer require a detached virtual private gateway, you can delete it. You can't delete a virtual
private gateway that's still attached to a VPC.
200
Amazon Virtual Private Cloud User Guide
API and CLI Overview
• For more information about working with security groups using a CLI, see API and CLI Overview (p. 69).
201
Amazon Virtual Private Cloud User Guide
VPN CloudHub
The following diagram shows the VPN CloudHub architecture, with blue dashed lines indicating network
traffic between remote sites being routed over their VPN connections.
202
Amazon Virtual Private Cloud User Guide
VPN CloudHub
To use the AWS VPN CloudHub, you must create a virtual private gateway with multiple customer
gateways. You can use the same Border Gateway Protocol (BGP) Autonomous System Number (ASN)
for each, or if you prefer, you can use a unique ASN for each. Customer gateways advertise the appropriate
routes (BGP prefixes) over their VPN connections. These routing advertisements are received and
re-advertised to each BGP peer, enabling each site to send data to and receive data from the other sites.
The routes for each spoke must have unique ASNs and the sites must not have overlapping IP ranges.
Each site can also send and receive data from the VPC as if they were using a standard VPN connection.
Sites that use AWS Direct Connect connections to the virtual private gateway can also be part of the
AWS VPN CloudHub. For example, your corporate headquarters in New York can have an AWS Direct
Connect connection to the VPC and your branch offices can use VPN connections to the VPC. The branch
offices in Los Angeles and Miami can send and receive data with each other and with your corporate
headquarters, all using the AWS VPN CloudHub.
To configure the AWS VPN CloudHub, you use the AWS Management Console to create multiple customer
gateways, each with the unique public IP address of the gateway and the ASN. Next, you create a VPN
connection from each customer gateway to a common virtual private gateway. Each VPN connection
must advertise its specific BGP routes. This is done using the network statements in the VPN configuration
files for the VPN connection. The network statements differ slightly depending on the type of router you
use.
When using an AWS VPN CloudHub, you pay typical Amazon VPC VPN connection rates. You are billed
the connection rate for each hour that each VPN is connected to the virtual private gateway. When you
send data from one site to another using the AWS VPN CloudHub, there is no cost to send data from
your site to the virtual private gateway. You only pay standard AWS data transfer rates for data that is
relayed from the virtual private gateway to your endpoint. For example, if you have a site in Los Angeles
and a second site in New York and both sites have a VPN connection to the virtual private gateway, you
pay $.05 per hour for each VPN connection (for a total of $.10 per hour). You also pay the standard AWS
data transfer rates for all data that you send from Los Angeles to New York (and vice versa) that traverses
each VPN connection; network traffic sent over the VPN connection to the virtual private gateway is free
but network traffic sent over the VPN connection from the virtual private gateway to the endpoint is billed
at the standard AWS data transfer rate. For more information, see VPN Connection Pricing.
203
Amazon Virtual Private Cloud User Guide
Dedicated Instance Basics
Dedicated Instances
Dedicated instances are Amazon EC2 instances that run in a virtual private cloud (VPC) on hardware
that's dedicated to a single customer.Your Dedicated instances are physically isolated at the host hardware
level from your instances that aren't Dedicated instances and from instances that belong to other AWS
accounts.
This topic discusses the basics of Dedicated instances and shows you how to implement them.
Note
A Dedicated Host is also a physical server that's dedicated for your use. With a Dedicated Host,
you have visibility and control over how instances are placed on the server. For more information,
see Dedicated Hosts in the Amazon EC2 User Guide for Linux Instances.
Topics
• Dedicated Instance Basics (p. 204)
• Working with Dedicated Instances (p. 206)
• API and Command Overview (p. 208)
Value Description
You cannot change the tenancy of a default instance after you've launched it.You can change the tenancy
of an instance from dedicated to host after you've launched it, and vice versa. For more information,
see Changing the Tenancy of an Instance (p. 207).
Each VPC has a related instance tenancy attribute.You can't change the instance tenancy of a VPC after
you create it. This attribute has the following values.
204
Amazon Virtual Private Cloud User Guide
Dedicated Instances Limitations
Value Description
default An instance launched into the VPC is a Dedicated instance only if the tenancy attribute
for the instance is dedicated.
dedicated All instances launched into the VPC are Dedicated instances, regardless of the value
of the tenancy attribute for the instance.
If you are planning to use Dedicated instances, you can implement them using either method:
• Create the VPC with the instance tenancy set to dedicated (all instances launched into this VPC are
Dedicated instances).
• Create the VPC with the instance tenancy set to default, and specify dedicated tenancy for any
instances that should be Dedicated instances when you launch them.
Some instance types cannot be launched into a VPC with the instance tenancy set to dedicated. For
more information about supported instances types, see Amazon EC2 Dedicated Instances.
When you purchase a Dedicated Reserved instance, you are purchasing the capacity to launch a Dedicated
instance into a VPC at a much reduced usage fee; the price break in the hourly charge applies only if
you launch an instance with dedicated tenancy. However, if you purchase a Reserved instance with a
default tenancy value, you won't get a Dedicated Reserved instance if you launch an instance with
dedicated instance tenancy.
In addition, you can't change the tenancy of a Reserved instance after you've purchased it.
205
Amazon Virtual Private Cloud User Guide
Working with Dedicated Instances
Topics
• Creating a VPC with an Instance Tenancy of Dedicated (p. 206)
• Launching Dedicated Instances into a VPC (p. 206)
• Displaying Tenancy Information (p. 207)
• Changing the Tenancy of an Instance (p. 207)
To create a VPC with an instance tenancy of dedicated (Create VPC dialog box)
To launch an instance with a tenancy of dedicated into a VPC with a tenancy of default
206
Amazon Virtual Private Cloud User Guide
Displaying Tenancy Information
8. Continue as prompted by the wizard. When you've finished reviewing your options on the Review
Instance Launch page, choose Launch to choose a key pair and launch the Dedicated instance.
For more information about launching an instance with a tenancy of host, see Launching Instances on
Dedicated Hosts in Amazon EC2 User Guide for Linux Instances.
• Choose Edit Table Columns (the gear-shaped icon), Tenancy in the Show/Hide Columns dialog
box, and then Close.
• Select the instance.The Description tab in the details pane displays information about the instance,
including its tenancy.
207
Amazon Virtual Private Cloud User Guide
API and Command Overview
Set the supported tenancy options for instances that you launch into a VPC
Describe the supported tenancy options for instances launched into the VPC
208
Amazon Virtual Private Cloud User Guide
ClassicLink
ClassicLink allows you to link an EC2-Classic instance to a VPC in your account, within the same region.
This allows you to associate the VPC security groups with the EC2-Classic instance, enabling
communication between your EC2-Classic instance and instances in your VPC using private IP addresses.
ClassicLink removes the need to make use of public IP addresses or Elastic IP addresses to enable
communication between instances in these platforms. For more information about private and public IP
addresses, see IP Addressing in Your VPC (p. 120).
ClassicLink is available to all users with accounts that support the EC2-Classic platform, and can be used
with any EC2-Classic instance.
There is no additional charge for using ClassicLink. Standard charges for data transfer and instance hour
usage apply.
For more information about ClassicLink and how to use it, see the following topics in the Amazon EC2
User Guide:
• ClassicLink Basics
• ClassicLink Limitations
• Working with ClassicLink
• ClassicLink API and CLI Overview
209
Amazon Virtual Private Cloud User Guide
VPC and Subnets
The following tables list the limits related to Amazon VPC. Unless indicated otherwise, you can request
an increase for any of these limits by using the Amazon VPC Limits form.
Topics
• VPC and Subnets (p. 210)
• Elastic IP Addresses (p. 211)
• Flow Logs (p. 211)
• Gateways (p. 211)
• Network ACLs (p. 212)
• Network Interfaces (p. 212)
• Route Tables (p. 212)
• Security Groups (p. 213)
• VPC Peering Connections (p. 214)
• VPC Endpoints (p. 214)
• VPN Connections (p. 214)
Subnets per VPC 200 If you need to increase this limit, submit a
request.
210
Amazon Virtual Private Cloud User Guide
Elastic IP Addresses
Elastic IP Addresses
Resource Default Comments
limit
Elastic IP addresses per region for each 5 This is the limit for the number of VPC
AWS account Elastic IP addresses you can allocate within
a region. This is a separate limit from the
Amazon EC2 Elastic IP address limit. If you
need to increase this limit, submit a request.
Flow Logs
Resource Default Comments
limit
Flow logs per single network interface, single 2 You can effectively have 6 flow logs per
subnet, or single VPC in a region network interface if you create 2 flow logs for
the subnet, and 2 flow logs for the VPC in
which your network interface resides. This
limit cannot be increased.
Gateways
Resource Default Comments
limit
Customer gateways per region 50 If you need to increase this limit, contact
AWS Support.
Internet gateways per region 5 This limit is directly correlated with the limit
on VPCs per region. You cannot increase
this limit individually; the only way to increase
this limit is to increase the limit on VPCs per
region. Only one Internet gateway can be
attached to a VPC at a time.
NAT gateways per Availability Zone 5 If you need to increase this limit, submit a
request. A NAT gateway in the pending,
active, or deleting state counts against
your limit.
Virtual private gateways per region 5 If you need to increase this limit, contact
AWS Support; however, only one virtual
private gateway can be attached to a VPC
at a time.
211
Amazon Virtual Private Cloud User Guide
Network ACLs
Network ACLs
Resource Default Comments
limit
Network ACLs per VPC 200 You can associate one network ACL to one
or more subnets in a VPC. This limit is not
the same as the number of rules per network
ACL.
Rules per network ACL 20 This is the one-way limit for a single network
ACL, where the limit for ingress rules is 20,
and the limit for egress rules is 20. This limit
can be increased upon request up to a
maximum if 40; however, network perform-
ance may be impacted due to the increased
workload to process the additional rules.
Network Interfaces
Resource Default Comments
limit
Network interfaces per instance - This limit varies by instance type. For more
information, see Private IP Addresses Per
ENI Per Instance Type.
Network interfaces per VPC 100 This limit is calculated by multiplying your
On-Demand instance limit by 5. The default
limit for On-Demand instances is 20. You
can increase the number of network inter-
faces per VPC by contacting AWS Support,
or by increasing your On-Demand instance
limit.
Route Tables
Resource Default Comments
limit
Route tables per VPC 200 Including the main route table.You can asso-
ciate one route table to one or more subnets
in a VPC.
Routes per route table (non-propagated 50 This is the limit for the number of non-
routes) propagated entries per route table. You can
submit a request for an increase of up to a
maximum of 100; however, network perform-
ance may be impacted.
212
Amazon Virtual Private Cloud User Guide
Security Groups
BGP advertised routes per route table 100 You can have up to 100 propagated routes
(propagated routes) per route table; however, the total number
of propagated and non-propagated entries
per route table cannot exceed 100. For ex-
ample, if you have 50 non-propagated entries
(the default limit for this type of entry), you
can only have 50 propagated entries. This
limit cannot be increased. If you require more
than 100 prefixes, advertise a default route.
Security Groups
Resource Default Comments
limit
Security groups per VPC 500 If you need to increase this limit, you can
submit a request.
Inbound or outbound rules per security group 50 You can have 50 inbound and 50 outbound
rules per security group (giving a total of 100
combined inbound and outbound rules). If
you need to increase or decrease this limit,
you can contact AWS Support — a limit
change applies to both inbound and out-
bound rules. However, the multiple of the
limit for rules per security group and the limit
for security groups per network interface
cannot exceed 250. For example, if you want
100 rules per security group, we decrease
your number of security groups per network
interface to 2.
Security groups per network interface 5 If you need to increase or decrease this limit,
you can contact AWS Support. The maxim-
um is 16. The multiple of the limit for security
groups per network interface and the limit for
rules per security group cannot exceed 250.
For example, if you want 10 security groups
per network interface, we decrease your
number of rules per security group to 25.
213
Amazon Virtual Private Cloud User Guide
VPC Peering Connections
Active VPC peering connections per VPC 50 If you need to increase this limit, contact
AWS Support . The maximum limit is 125
peering connections per VPC. The number
of entries per route table should be increased
accordingly; however, network performance
may be impacted.
Outstanding VPC peering connection re- 25 This is the limit for the number of outstanding
quests VPC peering connection requests that you've
requested from your account. If you need to
increase this limit, contact AWS Support.
Expiry time for an unaccepted VPC peering 1 week If you need to increase this limit, contact
connection request (168 AWS Support.
hours)
VPC Endpoints
Resource Default Comments
limit
VPC endpoints per region 20 If you need to increase this limit, contact
AWS Support; up to a maximum of 255 end-
points per VPC.
VPN Connections
Resource Default Comments
limit
VPN connections per region 50 If you need to increase this limit, submit a
request.
VPN connections per VPC (per virtual private 10 If you need to increase this limit, submit a
gateway) request.
214
Amazon Virtual Private Cloud User Guide
Document History
The following table describes the important changes in each release of this Amazon VPC guide.
NAT gateways 2015-10- You can create a NAT gateway in a public subnet 17 Decem-
01 and enable instances in a private subnet to initiate ber 2015
outbound traffic to the Internet or other AWS ser-
vices. For more information, see NAT Gate-
ways (p. 144).
VPC flow logs 2015-04- You can create a flow log to capture information 10 June
15 about the IP traffic going to and from network inter- 2015
faces in your VPC. For more information, see VPC
Flow Logs (p. 110).
VPC endpoints 2015-03- An endpoint enables you to create a private con- 11 May
01 nection between your VPC and another AWS ser- 2015
vice without requiring access over the Internet,
through a VPN connection, through a NAT instance,
or through AWS Direct Connect. For more inform-
ation, see VPC Endpoints (p. 177).
Use private hosted 2014-09- You can access resources in your VPC using cus- 5 Novem-
zones 01 tom DNS domain names that you define in a private ber 2014
hosted zone in Amazon Route 53. For more inform-
ation, see Using Private Hosted Zones (p. 169).
215
Amazon Virtual Private Cloud User Guide
Modify a subnet's public 2014-06- You can modify the public IP addressing attribute 21 June
IP addressing attribute 15 of your subnet to indicate whether instances 2014
launched into that subnet should receive a public
IP address. For more information, see Modifying
Your Subnet's Public IP Addressing Behavi-
or (p. 121).
VPC peering 2014-02- You can create a VPC peering connection between 24 March
01 two VPCs, which allows instances in either VPC to 2014
communicate with each other using private IP ad-
dresses - as if they are within the same VPC. For
more information, see VPC Peering (p. 169).
New EC2 launch wizard 2013-10- Added information about the redesigned EC2 10 October
01 launch wizard. For more information, see Step 3: 2013
Launch an Instance into Your VPC (p. 13).
Assigning a public IP 2013-07- Added information about a new public IP address- 20 August
address 15 ing feature for instances launched in a VPC. For 2013
more information, see Assigning a Public IP Ad-
dress During Launch (p. 122).
Enabling DNS host- 2013-02- By default, DNS resolution is enabled. You can 11 March
names and disabling 01 now disable DNS resolution using the Amazon VPC 2013
DNS resolution console, the Amazon EC2 command line interface,
or the Amazon EC2 API actions.
VPN connections using 2012-08- You can create IPsec VPN connections to Amazon 13 Septem-
static routing configura- 15 VPC using static routing configurations. Previously, ber 2012
tion VPN connections required the use of the Border
Gateway Protocol (BGP). We now support both
types of connections and are excited to announce
that you can now establish connectivity from
devices that do not support BGP, including Cisco
ASA and Microsoft Windows Server 2008 R2.
Automatic route 2012-08- You can now configure automatic propagation of 13 Septem-
propagation 15 routes from your VPN and Direct Connect links to ber 2012
your VPC routing tables. This feature simplifies the
effort to create and maintain connectivity to Amazon
VPC.
AWS VPN CloudHub You can securely communicate from one site to 29 Septem-
and redundant VPN another with or without a VPC.You can use redund- ber 2011
connections ant VPN connections to provide a fault-tolerant
connection to your VPC.
216
Amazon Virtual Private Cloud User Guide
VPC Everywhere 2011-07- Support in five AWS regions, VPCs in multiple 03 August
15 Availability Zones, multiple VPCs per AWS account, 2011
multiple VPN connections per VPC, Microsoft
Windows Server 2008 R2 and Microsoft SQL
Server Reserved Instances.
Dedicated Instances 2011-02- Dedicated Instances are Amazon EC2 instances 27 March
28 launched within your VPC that run hardware dedic- 2011
ated to a single customer. Dedicated Instances let
you take full advantage of the benefits of Amazon
VPC and AWS elastic provisioning, pay only for
what you use, and a private, isolated virtual net-
work—all while isolating your instances at the
hardware level.
217
Amazon Virtual Private Cloud User Guide
AWS Glossary
Blank
placeholder This page redirects to the AWS Glossary in the AWS General Reference.
218