Last active
August 29, 2015 14:04
-
-
Save gansbrest/ecf6bf75fd75aa944887 to your computer and use it in GitHub Desktop.
Little trick to get AWS instance_id as variable in Nginx. Source: distinctplace.com/2014/07/22/little-trick-to-get-aws-instance_id-as-variable-in-nginx/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl_set $instance_id ' | |
sub { | |
if ($id) | |
{ | |
# since this gets executed for EACH request, so use simple caching | |
return $id; | |
} | |
# GET AWS instance metadata | |
$id = `curl -s http://169.254.169.254/latest/meta-data/instance-id`; | |
$id =~ s/(i\-)|(\s)//g; | |
return $id; | |
} | |
'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment