Skip to content

I cannot access via HTTP even though I have applied the IAM role.

0

I cannot access via HTTP even though I have applied the IAM role.

When I accessed localhost from within ec2 using curl, the desired html was returned.

However, when I executed curl http://169.254.169.254, the following html was returned.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>401 - Unauthorized</title>
 </head>
 <body>
  <h1>401 - Unauthorized</h1>
 </body>
</html>

I tried the following:

  • Installing, configuring and starting nginx
    • I have confirmed that the nginx settings (IP, etc.) are correct.
  • Security group settings
    • Allow port 22 from 0.0.0.0/0
    • Allow port 80 from 0.0.0.0/0
    • Allow port 443 from 0.0.0.0/0
  • IAM role settings
    • AmazonEC2ReadOnlyAccess
    • AmazonRDSFullAccess
    • AmazonS3ReadOnlyAccess
    • EC2InstanceConnect

Environment

Platform: Amazon Linux Nginx Docker Rails

asked 2 years ago259 views
2 Answers
3

With imds v2 you have to grab an authorisation token first before you can access the metadata otherwise you will receive the 401 error.

Follow the Linux or windows example in the link

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-v2-how-it-works.html

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
1

Hi,

You can only access EC2 instance metadata via CURL from the inside of the instance itself.

See https://medium.com/@radhagayathripatel/retrieving-aws-ec2-instance-metadata-using-metadata-in-scripts-251bf18dbabf

Best,

Didier

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
  • The article above only works with imdsv1

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.