2

Is there a best practice or standarized way to clone a git repository (currently using CloudCommit to make permissions easier) into an EC2 instance on startup?

I'm using the userdata section with a cloud-init script that has:

runcmd:
- git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/myrepo

But my cloud-init-output.log file shows that the git command could not connect to the server. When I attempt to do it outside of the cloud-init script, I get:

The config profile (default) could not be found

as the error message. So I'm assuming the user that runs the userdata init scripts does not have an aws cli config profile set up and therefore can't run a git clone? What is the proper way to do this? My EC2 instance does have a role that allows it to read from CodeCommit so I shouldn't need SSH keys.

tbox
  • 199
  • 1
  • 11

1 Answers1

1

Just to add a perhaps helpful note, the AWS documents recommend the following git configuration:

git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true

I found that using --system for the git-config commands worked much better than using --global, which requires $HOME to be set (it's not, BTW). This will set the configuration system-wide, however.. so any user can run pull from CodeCommit repo with the permissions of the EC2 instance assumed role. It might not be what is good or needed for you, but it works well in my circumstance (using codecommit to pull configuration information).

Eric Horne
  • 103
  • 1
  • 6