Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

yum or dnf on an EC2 instance cannot download from the Amazon Linux repository

Erroryum update or dnf upgrade hangs and then times out

Short answer

Amazon Linux repositories live in S3. An instance in a private subnet reaches them only through an S3 gateway endpoint whose policy allows the repo bucket. On Amazon Linux 2 in an IPv6-only subnet, yum also needs one switch turned off. Check which applies by the Amazon Linux version and the subnet.

  • Applies to Amazon Linux 2023, Amazon Linux 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find which Amazon Linux you run and whether the subnet has a route to the internet or to an S3 endpoint.

    grep -E '^(NAME|VERSION_ID)=' /etc/os-release && sudo dnf repolist
  2. 2Match what you see, then jump to its fix

    1. 1Amazon Linux 2023 in a subnet with no internet route; dnf cannot download repo metadataA restrictive S3 gateway endpoint policy blocks the AL2023 repo bucketFix
    2. 2Amazon Linux 2 instance with no IPv4 address; yum cannot reach its repositoryAmazon Linux 2 in an IPv6-only subnet needs the https patch service offFix

What does the error look like?

  • yum update or dnf upgrade hangs and then times out
  • dnf cannot download repository metadata on an instance with no internet route

Cause 1 of 2

A restrictive S3 gateway endpoint policy blocks the AL2023 repo bucket

1Check

To download packages from the AL2023 repositories the instance needs access to AWS-owned S3 buckets. If the VPC uses an S3 endpoint, its policy must allow the bucket for your Region. Open the endpoint in the VPC console and read its policy.

sudo dnf makecache

2Fix

Add the AL2023 repository bucket to the endpoint policy, with your own Region in the ARN.

{
  "Effect": "Allow",
  "Principal": "*",
  "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::al2023-repos-us-east-1-de612dc2/*"
}

3Verify

Run the upgrade again from the instance.

sudo dnf upgrade -y

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 2

Amazon Linux 2 in an IPv6-only subnet needs the https patch service off

1Check

AL2 instances launched into an IPv6-only subnet must be told to use the http patch service to reach the yum repository over IPv6.

ip -6 addr show scope global

2Fix

Connect to the instance and disable the https patch service, then update.

sudo amazon-linux-https disable
sudo yum update

3Verify

yum lists and installs updates.

yum check-update; echo $?

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • When you lock down an S3 endpoint policy, add the Amazon Linux repo bucket before you remove NAT or internet access.
  • Use the dnf command on AL2023; yum remains as a pointer to dnf.
  • Keep a test instance in each subnet type and run dnf check-update there after network changes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.