Sub topic 14
Sharing networks and resources across accounts
This chapter assumes you know the AWS Organizations structure from earlier chapters (management account, OUs, member accounts). It also assumes you know VPC basics (subnets, route tables, Availability Zones) and can read IAM and Terraform. The chapter covers how to share a network and other resources between accounts without copying them into each one.
The problem: isolation versus duplication
Separate accounts give you strong isolation. They also push you toward duplication. If every workload account builds its own VPC, NAT gateways and DNS rules, you pay for the same infrastructure many times. You also end up with dozens of network designs to audit.
Two approaches address this:
- Share the resource. One account owns it, and other accounts use it. This is done with AWS Resource Access Manager (RAM).
- Connect the networks. Each account keeps its own VPC, and you link them with Transit Gateway or peering. Transit Gateway can itself be shared through RAM.
AWS Resource Access Manager
AWS Resource Access Manager (RAM) is a service that lets an account share resources it owns with other accounts. A resource share has three parts:
- The resources being shared.
- The principals that receive access. These are accounts, OUs, or the whole organization.
- The managed permissions that define what the principals may do.
Common shareable resources include VPC subnets, Transit Gateways, Route 53 Resolver rules, customer-managed prefix lists, and License Manager configurations. Shares are regional. Share a subnet in eu-west-1 and only principals working in eu-west-1 see it.
Enabling sharing with your organization
By default, RAM treats each account as separate and sends invitations. Once you enable sharing with AWS Organizations, shares to an account, OU or the organization take effect immediately, with no invitation to accept. Run this once, from the management account:
aws ram enable-sharing-with-aws-organizationThis creates a service-linked role that lets RAM read your organization's structure. After that, the account that owns the resource creates the share:
aws ram create-resource-share \
--name shared-app-subnets \
--resource-arns arn:aws:ec2:eu-west-1:444455556666:subnet/subnet-0a1b2c3d4e5f6a7b8 \
--principals arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111 \
--no-allow-external-principals \
--region eu-west-1--no-allow-external-principals restricts the share to your organization. Without it, the owner could share with arbitrary outside accounts.
Sharing subnets: the shared VPC model
VPC sharing is the most common use of RAM in multi-account designs. A central network account owns the VPC and its subnets. Workload accounts, called participants, launch their resources into those subnets.
Who can do what
| Action | Owner (network account) | Participant |
|---|---|---|
| Create, modify or delete the VPC, subnets, route tables, network ACLs | Yes | No |
| Launch EC2, RDS, Lambda and similar resources in the subnet | Yes | Yes |
| Create and manage its own security groups in the shared VPC | Yes | Yes, for its own groups |
| Modify or terminate another account's resources | No | No |
The owner controls the network. Each participant controls only what it launched. Participants cannot see each other's instances, but they can reach each other over the VPC's private addresses, subject to security groups and network ACLs.
Edge cases to know
- Availability Zone names differ per account. AWS maps the name
eu-west-1ato a physical zone separately in each account. Two accounts using the same name may be in different zones. When you plan which subnets to share, use AZ IDs such aseuw1-az1, which are the same everywhere. - Default VPC subnets cannot be shared. Only subnets in non-default VPCs can.
- Deletion is blocked while participants use the subnet. The owner cannot delete a shared subnet until participants remove their resources from it.
- Cost lands on both sides. The owner pays for VPC-level items such as NAT gateways and Transit Gateway attachments. Each participant pays for its own instances. Data transfer between zones is billed to the account that generates it.
- Quotas and limits are per account. A participant's instance quotas are its own, even though the subnet is not.
Sharing a Transit Gateway
A Transit Gateway is a regional hub that connects VPCs and on-premises networks. When the networking team owns the gateway, other accounts need permission to attach to it. Share it through RAM:
resource "aws_ram_resource_share" "tgw" {
name = "shared-transit-gateway"
allow_external_principals = false
}
resource "aws_ram_resource_association" "tgw" {
resource_arn = aws_ec2_transit_gateway.hub.arn
resource_share_arn = aws_ram_resource_share.tgw.arn
}
resource "aws_ram_principal_association" "org" {
principal = "arn:aws:organizations::111111111111:organization/o-exampleorgid"
resource_share_arn = aws_ram_resource_share.tgw.arn
}Once shared, each account creates a VPC attachment to the gateway from its own account. By default, the owner must accept each attachment, unless you turn on auto-accept. Route tables on the gateway decide which attachments can talk to each other. That makes it the right place to enforce separation, for example keeping production attachments away from development.
Sharing DNS rules
Route 53 Resolver rules forward queries for a domain (for example corp.example.com) to on-premises DNS servers. Create the rule once in the network account and share it. Each participant then associates the rule with its own VPCs. Without sharing, every account would need its own copy of the rule and its own outbound endpoint.
Choosing between sharing and connecting
| Factor | Shared VPC subnets | Separate VPCs with Transit Gateway |
|---|---|---|
| Isolation between workloads | Weaker. They share one network and its limits. | Stronger. Each account owns its VPC. |
| Network ownership | Central team controls all routing | Each team controls its own VPC |
| Cost | Fewer NAT gateways and endpoints | More per-VPC components and attachment fees |
| IP address planning | One large CIDR to divide | Non-overlapping CIDRs per VPC |
| Blast radius of a network mistake | Larger | Smaller |
Many organizations use both. They share subnets for tightly related workloads in one environment, and connect separate environments through a Transit Gateway.
Governing sharing with SCPs
RAM is itself an API that SCPs can control. This SCP prevents any member account from creating shares that include accounts outside the organization:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyExternalResourceShares",
"Effect": "Deny",
"Action": [
"ram:CreateResourceShare",
"ram:UpdateResourceShare"
],
"Resource": "*",
"Condition": {
"Bool": {
"ram:RequestedAllowsExternalPrincipals": "true"
}
}
}
]
}Keep in mind that SCPs apply to the account performing the action. A participant's SCPs apply to what it does in a shared subnet. The owner's SCPs apply to what the owner does to the subnet.
Common errors
- The share exists but participants cannot see it. Check that sharing with Organizations is enabled and that the participant is in the target OU. Check that the participant is working in the same Region.
- The subnet appears, but the instance launch fails. The participant's role may lack EC2 permissions. A resource share grants access to the resource, but it does not grant IAM permissions to the caller.
- Resources land in the wrong zone. Someone chose a subnet by AZ name instead of AZ ID.
- A share created from the management account. The management account can share resources, but avoid running workloads or network resources there. Use a dedicated network account.
Exercise
A network account shares subnets with the Workloads OU. A new account is moved into that OU a week later. Does it see the subnets, and what must still be true before a user there can launch an EC2 instance in one?
Show answer
Yes, it sees them, because a share to an OU covers all current and future accounts in it, with no invitation once sharing with Organizations is enabled. A user there still needs IAM permissions to launch EC2 instances, and no SCP may deny the action. The share grants access to the subnet, not IAM permissions.
Exercise
Why should you pick shared subnets by AZ ID rather than AZ name?
Show answer
AZ names such as eu-west-1a are mapped to physical zones separately for each account, so two accounts can see the same name for different zones. AZ IDs such as euw1-az1 refer to the same physical zone in every account.