Reason: Here this will happen if your instance doesn’t have internet access.
Solution: Kindly modify the security groups and allow internet access for updating or installing any packages that will resolve your issue.
Also, learn more about AWS, and become a master by enrolling for Intellipaat's AWS Online Certification!
For more information refer to this aws tutorial.