Skip to content

Instantly share code, notes, and snippets.

@gansbrest
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gansbrest/ecf6bf75fd75aa944887 to your computer and use it in GitHub Desktop.
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/
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