ec2-metadata icon indicating copy to clipboard operation
ec2-metadata copied to clipboard

Make it possible to override the service_url via an environment variable

Open ndejong opened this issue 2 years ago • 0 comments

Provides a simple mechanism to override the service_url via the environment variable (EC2METADATA_SERVICE_URL) which in turn makes developing/experimenting with ec2_metadata a little easier.

For example

export EC2METADATA_SERVICE_URL="http://127.0.0.1:8888/latest/"

Which then sets us up to be able to ssh port forward to a remote AWS instance

ssh -L 8888:169.254.169.254:80 ec2-instance.aws.hostname

And thus access the remote AWS-instance ec2_metadata from a local (development) host

user@computer:~/ec2-metadata$ python
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import os
>>> os.getenv("EC2METADATA_SERVICE_URL")
'http://127.0.0.1:8888/latest/'
>>>
>>> from src.ec2_metadata import ec2_metadata
>>>
>>> ec2_metadata.ami_id
'ami-00001111222200000'
>>>

ndejong avatar Feb 25 '22 09:02 ndejong