Amazon EC2 instance can't update or use yum

amazon ec2 tutorial
ec2 instance types
ec2 instance pricing
aws ec2 documentation
aws calculator
ec2 instance info
aws console
aws ebs

I am using Amazon's tutorial for installing a LAMP server. The first several instructions involve using yum, but every single way I have tried to do it has resulted in the same message. I have found a few other recent questions about the same issue, none of which change anything on my setup.

Here is the message:

Loaded plugins: priorities, update-motd, upgrade-helper
Could not retrieve mirrorlist http://repo.us-east-1.amazonaws.com/latest/main/mirror.list error was
12: Timeout on http://repo.us-east-1.amazonaws.com/latest/main/mirror.list: (28, 'Connection timed out after 10001 milliseconds')


One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Disable the repository, so yum won't use it by default. Yum will then
    just ignore the repository until you permanently enable it again or use
    --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>

 4. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 Cannot find a valid baseurl for repo: amzn-main/latest

I have done this same thing before without running into any problems, using the same tutorial, but it was several months ago. I don't know what has changed but my meager experience is keeping me from figuring it out.

Looks like the host is having trouble contacting the yum server. Make sure the instance has outbound internet access (check security groups etc). If the instance is in a VPC and the security groups look good you may need to use a nat appliance or attach an elastic IP.

Good luck-

Amazon EC2 Instances, You can choose from a number of globally available AMIs that provide useful instances. For example, if you just want a simple  Amazon EC2 provides different instance types to enable you to choose the CPU, memory, storage, and networking capacity that you need to run your applications. For more information, see Instance Types. Amazon EC2 supports On-Demand Instances (the default), Spot Instances, and Reserved Instances.

If you have an S3 endpoint on your VPC then this will cause yum to fail as repo file is stored in S3. To fix this add the following policy to S3:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": "*",
        "Action": "*",
        "Resource": [
            "arn:aws:s3:::repo.eu-west-1.amazonaws.com",
            "arn:aws:s3:::repo.eu-west-1.amazonaws.com/*"
        ]
    }
]
}

Replace eu-west-1 with the relevant region code that your S3 endpoint is in.

Amazon EC2, Amazon EC2 provides a variety of instance types with different compute, memory, However, when a resource is underused, an instance can consume a higher  Instances and AMIs. An Amazon Machine Image (AMI) is a template that contains a software configuration (for example, an operating system, an application server, and applications). From an AMI, you launch an instance, which is a copy of the AMI running as a virtual server in the cloud.

A lot of first time users of Amazon EC2 run into this issue. In my experience, it's usually the result of not setting the allowed outgoing connections on their instance's security group. The tutorial that Amazon has for configuring Amazon Linux instances only mentions setting the Incoming connections so it's easy to forget that you never set the allowed outgoing ones. Simply allowing HTTP and HTTPS requests to any IP Address should fix the issue.

What is Amazon EC2?, An instance is a virtual server in the AWS cloud. With Amazon EC2, you can set up and configure the operating system and applications that run on your instance​. I have an AWS EC2 Instance that can be accessed via SSH but will not load via its public IP. The page continually loads and then times out. I have checked the security group and the following is

Amazon EC2 FAQs - Amazon Web Services - AWS, From an AMI, you launch an instance, which is a copy of the AMI running as a virtual server in the cloud. You can launch multiple instances of an AMI, as shown in  In this article we will describe how to create a couple of EC2 instances and how to deploy ClusterControl on EC2. We will use MySQL Cluster here, but the same steps are applicable to Galera and MySQL Replication. We assume you already have an EC2 account. We will not cover how you add extra disk capacity in this tutorial.

just assign the default security group along with the one you may have created. This solved my problem. ;)

Instance types, Select a Region for the instance that meets your needs. This choice is important because some Amazon EC2 resources can be shared between Regions, while  The instance is an Amazon EBS-backed instance (meaning that the root volume is an EBS volume). You can either specify the Availability Zone in which your instance runs, or let Amazon EC2 select an Availability Zone for you. When you launch your instance, you secure it by specifying a key pair and security group.

Getting started with Amazon EC2 Linux instances, You can also pay for Dedicated Hosts which provide you with EC2 instance capacity on physical servers dedicated for your use. Free tier. AWS Free Tier includes  Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction.

Instances and AMIs, You can reduce your Amazon EC2 costs by making a commitment to a specific instance configuration, including instance type and Region, for a term of 1 or 3 years. Spot Instances Request unused EC2 instances, which can reduce your Amazon EC2 costs significantly.

Launching an instance using the Launch Instance Wizard, Amazon EC2 is free to try. There are four ways to pay for Amazon EC2 instances: On-Demand, Reserved Instances, and Spot Instances. You can also pay for Dedicated Hosts which provide you with EC2 instance capacity on physical servers dedicated for your use.

Comments
  • did you try yum clean all?
  • I had a similar (same?) issue; I'm behind a proxy at work. Adding outbound rules for HTTP and DNS (UPD and TCP) did the trick.
  • If you have an S3 endpoint on your VPC then this could potentially block yum. See my answer below for a fix.
  • As of April 12, 2017, this behavior is a known issue in EC2 initialization. AWS support suggests a "sleep 60" prior to running yum commands.
  • GraduateOfAcmeU could you explain what is a "sleep 60" means?
  • in my case i unchecked "Automatically assign a public IP address to your instances" while creating the instance.
  • In addition to Chadneal's answer. In case you created a custom/new security group then check and configure the outbound traffic for your instance.
  • check you don't have a rule in iptables which might be causing problems
  • did not have outbound internet access
  • Not sure about munna_1's comment, I had to do exactly the opposite. Without a public IP address (and no NAT) the instance cannot connect to the public internet.