Skip to content

Latest commit

 

History

History
77 lines (47 loc) · 3.36 KB

create_code_repo.md

File metadata and controls

77 lines (47 loc) · 3.36 KB

Guide to using AWS CodeCommit

Most NIH Cloud Lab users are probably used to using GitHub to manage and access code. The cloud providers also offer their own managed git repositories, which allows you to keep all your code within AWS without any external integrations. Follow this guide to learn how to set up and use AWS CodeCommit.

Create a CodeCommit Repository

  1. Navigate to the CodeCommit page.

  1. Click Create repository

  1. Enter the necessary information for your repository. Feel free to add tags to track costs. Click Create.

Authenticate and Set Up Environment

All the instructions for setting up your environment are outlined in this AWS documentation. Because we are using Short Term Access Keys, we need to use the AWS CLI credential helper.

  1. Open a compute environment of choice, either EC2, a Sagemaker Notebook, or Cloud Shell.

  2. Authenticate the AWS CLI using your Short Term Access Keys. Make sure you redo this whenever you disconnect as these keys reset periodically.

  3. If using an EC2 instance, install Git. AWS Linux machines will install with sudo yum install git -y. Cloud Shell and Sagemaker Instances already have Git installed.

  4. Set up the credential helper. Run the following code to update the git config.

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

Clone the Repository and Push Code

  1. You should not be authenticated and ready to clone the repository locally. To copy the url path, you can (A) click on the HTTPS link on the CodeCommit page.

Or, (B) you can go into the details for your repository, and click Clone URL in the top right.

If you get an error, re-authenticate with your Short Term Access Keys.

  1. Now you can use regular git commands to add, commit, push etc. If you have to reinitialize your keys, then you may need to run git init to reinitialize the repo.

A simple workflow would look like this.

# Clone the repo
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/cloud-lab-test-repo
# CD into the repo
cd cloud-lab-test-repo
# Copy in the files you want to commit to the CodeCommit repository
cp ../example_file.txt .
# Create a new branch, Code Commit does not create a default branch, so you need to create a branch to push to.
git checkout -b cloud-lab-branch
# Stage your files
git add example_file.txt 
# Commit
git commit -m 'cloud lab test commit'
# Push to CodeCommit Repo
git push origin cloud-lab
# Test pulling files back down
git pull git pull origin cloud-lab

You should now see your file(s) in the CodeCommit Repository.