diff --git a/httpd-to-cloudwatch.py b/httpd-to-cloudwatch.py index 95d3b7b2be4d5edd433e0c8b98bb9445f2ca8991..87d6fbbe6153e63df1a07f9c2495a8a496120de3 100755 --- a/httpd-to-cloudwatch.py +++ b/httpd-to-cloudwatch.py @@ -1,8 +1,7 @@ #!/usr/bin/python import boto3 -import urllib2 -import json +import requests import sys #import re #import tempfile @@ -41,8 +40,8 @@ def main(): # Returns the region the instance is currently running in (eg: 'us-east') def get_region(): - instance_info = urllib2.urlopen('http://169.254.169.254/2018-09-24/dynamic/instance-identity/document/').read() - instance_info = json.loads(instance_info) + session_token = requests.put('http://169.254.169.254/latest/api/token', headers={'X-aws-ec2-metadata-token-ttl-seconds': 60}).text + instance_info = requests.get('http://169.254.169.254/2018-09-24/dynamic/instance-identity/document/', headers={'X-aws-ec2-metadata-token': session_token}).json() return instance_info['region'] # Returns the instance_id of this VM.