AWS CodeCommit is a managed Git service that integrates tightly with other AWS services. Here’s how to go from zero to pushing code with AWS CLI and Git.
The AWS Command Line Interface (CLI) allows you to interact with AWS services via commands in your terminal.
aws --version
You should see the AWS CLI version displayed.
Next, we’ll set up AWS CLI with your credentials.
aws configure
You’ll be prompted for four pieces of information:
us-east-1, eu-west-2 json Don’t have access keys? Create them in the AWS IAM console.
If you haven’t already, install Git.
git --version
Here’s where the magic happens - configuring Git to use CodeCommit seamlessly.
git config --global credential.helper '!aws codecommit credential-helper $@'
This tells Git to use the AWS credential helper for all CodeCommit repos.
git config --global credential.UseHttpPath true
This is crucial for CodeCommit authentication to work properly.
If you haven’t configured your Git user info yet:
git config --global user.name "Your Full Name"
git config --global user.email you@example.com
Let’s create your first CodeCommit repo:
aws codecommit create-repository \
--repository-name my-awesome-project \
--repository-description "My first CodeCommit project"
Replace
my-awesome-projectand the description as needed.
Take note of the cloneUrlHttp from the output - you’ll need it to clone the repo.
Now get the repository onto your local machine:
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-awesome-project
Replace the region and repo name as appropriate.
You might see a warning about cloning an empty repository - that’s expected.
cd my-awesome-project
echo "# My Awesome Project" > README.md
git add README.md
git commit -m "Initial commit"
git push origin main
Your changes are now securely stored in AWS CodeCommit!
aws configure to verify AWS CLI is set up correctly.