Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell all my AWS EC2 instances to pull from git / codecommit?

I am using AWS CodeCommit which seems to be like a stripped down version of git.

If all these EC2 instances have the same role tag how do I accomplish this?

I don't want to do anything fancy, all I want is to be specify a tag, click a button and all those EC2 instances with that tag pull for CodeCommit. I want to do this from my local machine.

I know I need to put the SSH keys to access CodeCommit in each of my EC2 servers and install git on each of them (I will bake this into an AMI). I'm just not sure how to "trigger" each of the EC2 machines to do a git pull? Is there an AWS command?

I am not a dev ops guy and only know basic linux and php.

like image 830
Hard worker Avatar asked Aug 15 '15 20:08

Hard worker


People also ask

How do I get a list of EC2 instances?

Go to the instances section and click on "instances". It will show you all the running instances in the select region.

Which AWS service help you to trigger notification when pull request created on AWS CodeCommit repository?

You can create a trigger for a CodeCommit repository so that events in that repository trigger notifications from an Amazon Simple Notification Service (Amazon SNS) topic.


1 Answers

For EC2 instances that are launched with an IAM role, you don't even have to bake in SSH keys. Git can get CodeCommit credentials from the EC2 instance metadata. Bake a Linux-based AMI with the latest AWS CLI package and the following lines in ~/.gitconfig:

[credential]
    helper = !aws --profile default codecommit credential-helper $@
    UseHttpPath = true

Launch the instance with an IAM role attached, and then you can clone your CodeCommit repo without any more setup.

You might want to look into Capistrano and Capify-EC2 if you want to run git commands across a fleet of EC2 instances based on tags.

Updated: If you're open to using AWS OpsWorks to deploy from CodeCommit, there's a recent blog article about how to do that. You can also use OpsWorks to run arbitrary commands across instances with Capistrano.

like image 147
Clare Liguori Avatar answered Sep 17 '22 00:09

Clare Liguori