I've figured something out. For those of you that are curious:
I can grab EC instance information via http://169.254.169.254/latest/meta-data/
. In particular I want my EC2 instance id
I can determine a list of all my beanstalk environments via describe-environments
For each environment I can run describe-environment-resources
. This call returns a list of instances, which I can match the current instance's instance id against. Thus I can figure out my environment name.
Finally, I can refer to the result of describe-environments
to also determine a version label for the currently deployed code.
Before I can do any of this, I need to configure my ec2 instances to have access to the elastic beanstalk information. I can do this by assigning the right access policy to the role associated with my ec2 instances, and grabbing the authentication information, again via the instance metadata at http://169.254.169.254/latest/meta-data/
Since I'm using the python boto
library, all of the operations i've described above already have pre-baked library functions to perform them for me.
guh
I haven't coded it yet, but if I can get it to work I'll post a snipped here
Edit
working code
The syntax of your services section isn't quite right i.e.
"services": {
"myservice": {
"enabled": "true",
"ensureRunning": "true"
}
}
If you look at the documentation http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html#aws-resource-init-services it states ...
You can use the services key to define which services should be enabled or disabled when the instance is launched. On Linux systems, this key is supported by using sysvinit
. On Windows systems, it is supported by using the windows
service manager.
Because you're running a Linux system your "services"
section should look like ...
"services": {
"sysvinit" : {
"myservice": {
"enabled": "true",
"ensureRunning": "true"
}
}
}
Hopefully that should do the trick!
Best Answer
I had the same issue. With a little testing I came up with an updated version of what New Relic provides that allows use of environment variables from the application config in elastic beanstalk.
Final version looked like this
Just replace
APP_NR_LIC
with whatever variable you use to set you license key. This is working reliably for me.