Reputation: 21194
I use graylog to manage logs. I would like to be able to filter in graylog by the node where the code is running.
Is there some way for me to get from the AWS environment the "id" of the node where the code is running. I understand that I can simply use the "localhost" address but I assume this will change between deployments so it's a little less than ideal though I suppose if it's all I've got it will have to do.
Upvotes: 0
Views: 502
Reputation: 2277
Elasticbeanstalk tags the underlying EC2 instances with the environment name (by default). You could use the EC2 API to filter based on the name of your Elasticbeanstalk environment and then parse the response to get the ID of the instance/s running the application. This always returns the current set of running instances under the environment.
ec2-describe-instances --filter "tag:Name=<elasticbeanstalk-env-name>"
Upvotes: 1
Reputation: 18926
You can use the ec2 instance id from EC2 metadata. Read here: Find out the instance id from within an ec2 machine
But like you said if the instance is replaced you will start getting a different instance id. Isn't that what you want though?
Upvotes: 2