Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL-CMS-scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Steiner
UNL-CMS-scripts
Commits
758f8661
Commit
758f8661
authored
1 year ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
More IMDSv2 tokens.
parent
9e506f39
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
httpd-to-cloudwatch.py
+3
-4
3 additions, 4 deletions
httpd-to-cloudwatch.py
with
3 additions
and
4 deletions
httpd-to-cloudwatch.py
+
3
−
4
View file @
758f8661
#!/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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment