diff --git a/moto/core/responses.py b/moto/core/responses.py index 6f8b365fb..7e896e961 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -55,17 +55,26 @@ def metadata_response(request, full_url, headers): http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html """ - parsed_url = urlparse(full_url) tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) + credentials = dict( + AccessKeyId="test-key", + SecretAccessKey="test-secret-key", + Token="test-session-token", + Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ") + ) + path = parsed_url.path.lstrip("/latest/meta-data/") - if path == 'iam/security-credentials/': + if path == '': + result = 'iam' + elif path == 'iam': + result = json.dumps({ + 'security-credentials': { + 'default-role': credentials + } + }) + elif path == 'iam/security-credentials/': result = 'default-role' elif path == 'iam/security-credentials/default-role': - result = json.dumps(dict( - AccessKeyId="test-key", - SecretAccessKey="test-secret-key", - Token="test-session-token", - Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ") - )) + result = json.dumps(credentials) return 200, headers, result diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 47e8b4b16..11c2cc00e 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -9,7 +9,7 @@ from moto import mock_ec2 ################ Test Readme ############### def add_servers(ami_id, count): - conn = boto.connect_ec2('the_key', 'the_secret') + conn = boto.connect_ec2() for index in range(count): conn.run_instances(ami_id) @@ -18,7 +18,7 @@ def add_servers(ami_id, count): def test_add_servers(): add_servers('ami-1234abcd', 2) - conn = boto.connect_ec2('the_key', 'the_secret') + conn = boto.connect_ec2() reservations = conn.get_all_instances() assert len(reservations) == 2 instance1 = reservations[0].instances[0]