Hi! I have an application running on two EC2 instances and I would like to automate config change deployments for it. The process is very simple, I just need to build a config file in GitLab CI, upload it to a particular path within my EC2 instances, and then run a command to restart my application so that the new config is picked up.
What would be the proper way of copying my config file to all EC2 instances? I want to avoid manually SCPing to them, as that would require hardcoding the instance URLs. I imagine the right tool is SSM, but I haven’t found a way to do this with it.
You could make instances poll your git repo for changes or configure codebuild to push changes to running instances when there are changes to config file
Create an SSM Document that downloads from S3 and restarts the app. Then setup a CloudWatch Event on your S3 bucket to execute the document on your instances as targets by tag name (in order to do more than one instance). Link: https://docs.aws.amazon.com/systems-manager/latest/userguide/rc-cwe.html
or Chef, or Salt, or Puppet, or Puppet Bolt, or any of the actual config management tools, or if you wanted to get creative watchtower, which watches for changes to git repos. You could even use terraform and null_resource. it all depends which your happier with using and approach. Ansible, bolt or terraform will work really well from available gitlab ci and containers.
Alternatively, you could have the application pull it from a git repo. Same exact idea as using S3, but if it is already in git, it would be one less step (uploading to S3). If it is not in a git repo or there is pain in setting up the instance to pull, S3 is my suggestion as well.
SSM is supposed to be used for patch stuff, but could in principle be uded too, if you bend it a bit.
I’ve just recently gotten more into SSM and it alows you to connect to instances in private subnets without the need for a bastion/jump host OR the need for an ssh key. Really handy if you are working for a number of different customers with different workstation security rules.
Don’t discard SSM, but maybe don’t make it your priority right now
In a perfect world, you don’t need to connect to your machines at all.. CodeDeploy will do anything that you would want to do on the machines just fine.