I've created a CloudFormation template to run my web application that contains an Elastic Loadbalancer, three EC2 instances running Tomcat servers, and an Elasticache. There is a Chef recipe I run on boot that, among other things, configures each Tomcat's context.xml file to point to the Elasticache.
I'm wondering what the best way is to configure the Elasticache in the recipe so all I need to do is make a quick change in the CloudFormation template to bring up a bunch of them (stack1-elasticache, stack2-elasticache, etc.)
Right now I simple have a hard-coded variable replacement (not ideal for Chef since any change will update on every Chef'd box unless there is a separate recipe for each), but I wonder if there is a way to use the AWS CLI and Chef's lazy node evaluation to do something like:
ruby_block 'Get Elasticache endpoint' do
block do
node.run_state['elasticache'] = `some aws command to get the Elasticache endpoint I want`
end
end
source "context.xml.erb"
variables(lazy{
{
:tomcat_version => elasticache
}
}
What's tripping me up is how to get the Elasticache name from Amazon. I plan to do something very similar to my example, incrementing the number of each new Elasticache, and their naming scheme will correspond with the Tomcats (stack1-TC1, stack2-TC2, etc.). How can I achieve this?