ec2-metadata
ec2-metadata copied to clipboard
HTTPConnectionPool(host='169.254.169.254') timeout in docker bridge mode
Python Version
3.9.13
Package Version
2.10.0
Description
I tried use ec2-metadata inside docker container with bridge mode. Curl "169.254.169.254" got ok but ec2-metadata raised error "requests.exceptions.ReadTimeout: HTTPConnectionPool(host='169.254.169.254', port=80): Read timed out. (read timeout=5.0)"
I need more information. I've never used a docker container with bridge mode. There shouldn't be anything fundamentally different between curl and python... Can you try using netcat, or opening a raw socket in python?
I can connect to 169.254.169.254 with curl or netcat or python urllib.request from docker container in bridge mode. Ec2-metadata works well with --network host.
can you provide a way to recreate this? otherwise I can do no more.
I can recreate the issue as follow:
- Run a docker container on EC2 with default network config such as "docker run -it python bash"
- Install ec2-medata
- Try to get metadata using python
I am facing the same issue. Any resolution/work around for this?
I am getting metadata from ip 169.254.169.254 using requests.
ec2_metadata = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document').json()
If requests
works, this package should work, as it's only a thin layer around requests - see the code:
https://github.com/adamchainz/ec2-metadata/blob/70d1ecdae9a86acaeb8005d353e0cfc53ffdf628/src/ec2_metadata/init.py#L71-L77
It should be but not