Ubuntu APT Mirrors Configuration on AWS EC2
Bottom line
Ubuntu EC2 instances use region-specific APT mirrors at <region>.ec2.archive.ubuntu.com, auto-configured by cloud-init at boot. These mirrors are not hosted on AWS infrastructure - the S3-backed mirror feature that Canonical introduced in 2012 was discontinued around 2022-2023 (community-reported, no official announcement).
In practice, apt traffic from an EC2 instance must traverse the public internet, which has three consequences. Private-subnet instances need a NAT Gateway (~$32.40/month/AZ + $0.045/GB), apt operations can suffer latency spikes or regional outages, and there is no VPC-endpoint-based solution. This contrasts unfavorably with both Amazon Linux 2023 (S3-backed repos reachable via VPC Gateway Endpoint) and Debian (CloudFront CDN, AWS-sponsored). For fleets of Ubuntu instances, the practical mitigation options are. Accept the NAT Gateway cost, deploy a local apt-mirror (300-550 GB), run apt-cacher-ng as a caching proxy, or switch to a CDN mirror like CloudFront-backed community mirrors.
Key findings
-
Finding: Ubuntu EC2 AMIs default to
<region>.ec2.archive.ubuntu.commirrors, configured automatically by cloud-init's DataSourceEC2 module. This is industry-standard behavior and works transparently for public-subnet instances. Why it matters: Understanding this default is the foundation for any customization - if you want to change mirrors, you must override cloud-init's behavior or the AMI-baked sources.List. -
Finding: The S3-backed mirror feature (
<region>.ec2.archive.ubuntu.com.s3.amazonaws.com) that previously allowed VPC-Endpoint-based apt access is no longer available. Why it matters: This removes the cleanest architectural pattern for private-subnet Ubuntu instances; every apt operation now requires internet egress or local infrastructure. -
Finding: Debian and Amazon Linux both provide AWS-native package delivery (CloudFront CDN and S3 respectively) while Ubuntu doesn't. Why it matters: This is a tangible competitive gap for Ubuntu on AWS that affects operational cost and architectural simplicity, especially in security-sensitive private-subnet deployments.
Background
Canonical has maintained region-specific APT mirrors for AWS EC2 since at least 2012, when "Regional S3 Backed EC2 Mirrors" were announced for testing. The mirror naming convention is <aws-region>.ec2.archive.ubuntu.com (e.G., us-east-1.ec2.archive.ubuntu.com, ap-south-1.ec2.archive.ubuntu.com). These mirrors were initially backed by S3, making them accessible via S3 VPC Gateway Endpoints - an elegant architecture for instances in private subnets. At some point between ~2015 and 2023, S3 backing was removed, and the mirrors moved to non-AWS infrastructure.
Cloud-init, the industry-standard instance initialization tool, is responsible for configuring these mirrors at first boot. Its EC2 DataSource detects the AWS region from instance metadata and substitutes it into the mirror URL template. Cloud-init also supports explicit mirror override via the apt cloud-config key, offering uri, search (fallback list), and search_dns (DNS-based discovery) options.
Current state (as of May 2026)
- cloud-init 26.1 is the current documentation version and maintains the same mirror-selection behavior.
- Ubuntu 24.04+ uses deb822-format
.sourcesfiles in/etc/apt/sources.list.d/instead of legacysources.list. - The
ec2.archive.ubuntu.commirrors use unencrypted HTTP (APT verifies package integrity via GPG signatures, making encryption less critical for content but relevant for privacy/metadata). - Canonical's main archive experienced a significant outage on September 5, 2025 (36 minutes downtime on
archive.ubuntu.comandsecurity.ubuntu.com), with mirror synchronization issues persisting for ~2 days. Notably, EC2-specific mirrors were reported to remain functional during this outage. - The full Ubuntu package archive is about 3.6 TB as of September 2025.
Technical details
Mirror selection mechanism
Cloud-init resolves the apt mirror in this priority order:
- Explicit
uriorsearchlist in cloud-config user-data search_dns- looks for<distro>-mirrorDNS entry in instance FQDN, localdomain, then search domains- DataSource-provided mirror - on EC2:
<region>.ec2.archive.ubuntu.com(constructed from instance metadata region) - Distro default -
http://archive.ubuntu.com/ubuntu
The security mirror is resolved similarly, using <distro>-security-mirror for DNS search and http://security.ubuntu.com/ubuntu as the default.
cloud-init apt configuration example
#cloud-config
apt:
preserve_sources_list: false
primary:
- arches: [default]
uri: http://us-east-1.ec2.archive.ubuntu.com/ubuntu/
security:
- arches: [default]
uri: http://security.ubuntu.com/ubuntu/
Or using search with fallback:
#cloud-config
apt:
primary:
- arches: [default]
search:
- http://local-mirror.internal/ubuntu
- http://archive.ubuntu.com/ubuntu
AMI-level vs cloud-init-level configuration
Mirror selection happens at two levels: AMI build time (sources.List is customized per region during image publication) and cloud-init runtime. For Ansible-based configuration, setting preserve_sources_list: true in cloud-init and managing sources via Ansible's apt_repository or direct file management is a common pattern.
Evidence, comparisons, and related context
Comparison: Debian on AWS
Debian uses deb.debian.org which resolves via SRV DNS records to both Fastly and Amazon CloudFront (sponsored by AWS). The dedicated endpoint cdn-aws.deb.debian.org serves packages entirely through AWS's CDN. In practice, Debian instances on EC2 download packages from within AWS's network - no internet egress, no NAT Gateway cost. HTTPS is also supported.
Comparison: Amazon Linux 2023
AL2023 hosts its package repositories on S3, served through CloudFront. Instances in private subnets can reach them via an S3 VPC Gateway Endpoint (free, except for data processing at standard S3 rates). No NAT Gateway is required for yum/dnf operations. This is documented as a first-class AWS feature.
Local mirror (apt-mirror)
A full local mirror requires 300-350 GB initially (Ubuntu 24.04 amd64) plus 150-200 GB over the release lifetime. Syncs run every 4 hours via cron. For fleets of 10+ Ubuntu hosts, this economically pays for itself quickly by eliminating per-instance internet egress.
Caching proxy (apt-cacher-ng)
Apt-cacher-ng acts as a caching HTTP proxy for APT traffic. First download of a package hits the internet; subsequent requests from other instances are served from local cache. Much lighter than a full mirror (no need to sync entire archive - only packages actually used are cached).
Ansible integration patterns
For the ansible-role-ubuntu-2604 use case, three Ansible-native approaches exist:
- Inline sed/user-data: Replace mirror in
/etc/apt/sources.listor/etc/apt/sources.list.d/ubuntu.sources - cloud-init user-data: Set
apt.primary.urito the desired mirror in the instance launch configuration - Local infrastructure: Deploy apt-cacher-ng or apt-mirror within the VPC and point all instances at the internal endpoint
Limitations and critiques
-
No VPC-endpoint path: Unlike Amazon Linux 2023 and Debian, Ubuntu has no AWS-native delivery mechanism for packages. This is a genuine architectural gap that forces either internet access, NAT Gateway cost, or self-managed mirror infrastructure.
-
HTTP-only transport: All default Ubuntu APT mirrors use unencrypted HTTP. While package integrity is verified via GPG signatures, metadata leakage (which packages an instance is downloading) and potential for downgrade/blocking attacks exist. Debian's CloudFront mirrors support HTTPS.
-
S3 discontinuation undocumented: No official Canonical announcement or documentation was found regarding the removal of S3 backing. The only evidence is a March 2023 Server Fault comment. This lack of transparency makes it difficult for operators to plan migrations.
-
Mirror performance variability: Community reports (2015-2025) document
ec2.archive.ubuntu.comspeeds varying from 6 MB/s to as low as 157 bytes/second. This can cause autoscaling health-check failures if instances can't apt-update within grace periods. -
New AWS region lag: There is no documented guarantee that new AWS regions immediately receive
ec2.archive.ubuntu.commirrors. Instances may fall back toarchive.ubuntu.comif the region-specific DNS doesn't resolve. -
Mirror sync inconsistency during outages: The September 2025 incident showed that when the primary archive has issues, mirrors that sync during the incident window can serve broken content for hours afterward.
Open questions
- What is the exact current (2026) backend infrastructure for
ec2.archive.ubuntu.com? (S3 is confirmed gone; is it CloudFront, direct EC2 instances, or something else?) - When exactly did Canonical discontinue S3 backing, and was it announced anywhere?
- Does Canonical have plans to offer a VPC-endpoint-compatible or CDN-backed mirror solution for AWS?
- What is the SLA or availability commitment for
ec2.archive.ubuntu.commirrors? - Do newly launched AWS regions get
ec2.archive.ubuntu.commirrors immediately, and what is the fallback behavior?
Practical takeaways
-
For public-subnet instances: The default
ec2.archive.ubuntu.commirrors work well with no configuration needed. Considermirror://mirrors.ubuntu.com/mirrors.txtas a fallback for resilience. -
For private-subnet instances: You have three options. (A) run a NAT Gateway and accept the cost, (b) deploy an internal apt-mirror or apt-cacher-ng, or (c) switch to a CDN-based mirror that supports VPC-endpoint routing if one emerges. The self-managed mirror is the most cost-effective for fleets of 10+ instances.
-
For Ansible roles: Set
apt.primary.uriin cloud-init user-data to point at your chosen mirror. If using an internal mirror, also explicitly setapt.security.urito avoid instances reaching out tosecurity.ubuntu.comdirectly. For Ubuntu 24.04+, manage/etc/apt/sources.list.d/ubuntu.sourcesin deb822 format rather than legacysources.list. -
For cost-sensitive deployments: Calculate whether
NAT_Gateway_cost > mirror_infrastructure_cost. At ~$32/month per AZ plus data charges, a t3.Small mirror instance with attached EBS volume may break even at surprisingly small fleet sizes. -
Monitor the mirror landscape: Canonical's mirror infrastructure is evolving. Watch
status.canonical.comand theubuntu-mirrors-announcemailing list for changes. The Debian CloudFront model suggests a path Canonical could adopt.
Sources used
- Cloud-init 26.1 Documentation - Configure APT - https://cloudinit.readthedocs.io/en/latest/reference/yaml_examples/apt.html
- Cloud-init GitHub - cloud-config-apt.Txt example - https://github.com/canonical/cloud-init/blob/main/doc/examples/cloud-config-apt.txt
- Ubuntu Project Documentation - Mirrors - https://documentation.ubuntu.com/project/release-team/mirrors/
- Cloud-init GitHub Issue #2262 - sources.List configuration doesn't cover security - https://github.com/canonical/cloud-init/issues/2262
- ComputingForGeeks - Create Local Ubuntu Mirror with apt-mirror - https://computingforgeeks.com/ubuntu-apt-mirror/
- Thomas James - Making Ubuntu apt faster on EC2 - https://www.thomasvjames.com/2015/03/ubuntu-apt-slow-on-ec2/
- Server Fault - Use Apt Inside AWS VPC Without NAT Instance - https://serverfault.com/questions/700603/use-apt-inside-aws-vpc-without-nat-instance
- CloudCostKit - NAT Gateway cost optimization - https://cloudcostkit.com/guides/aws-nat-gateway-cost-optimization/
- Crusoe Support - Switch Ubuntu to Alternative Mirrors - https://support.crusoecloud.com/hc/en-us/articles/40749220333851
- Ask Ubuntu - September 5, 2025 archive.Ubuntu.Com outage - https://askubuntu.com/questions/1555546/
- Debian Mirrors via CloudFront - https://cdn-aws.deb.debian.org/
- AWS AL2023 - Managing package and OS updates - https://docs.aws.amazon.com/linux/al2023/ug/managing-repos-os-updates.html
- Stack Overflow - Stuck at Connecting to us-west-2.Ec2.Archive.Ubuntu.Com - https://stackoverflow.com/questions/34973953/
- AWS re:Post - Unable to connect to ap-south-1.Ec2.Archive.Ubuntu.Com - https://www.repost.aws/questions/QUgBAgNyk2QgWlalqLYeBUYA/
- Unix & Linux StackExchange - sources.List contents for EC2 instances - https://unix.stackexchange.com/questions/217516/
- DeepWiki - cloud-init EC2 DataSource - https://deepwiki.com/canonical/cloud-init/2.2-ec2-and-url-based-datasources