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.
Step 1: Install AWS CLI
The AWS Command Line Interface (CLI) allows you to interact with AWS services via commands in your terminal.
-
Download the installer for your operating system.
-
Run the installer and follow the prompts.
-
Open your terminal and verify the installation:
aws --version
You should see the AWS CLI version displayed.
Step 2: Configure AWS CLI
Next, we’ll set up AWS CLI with your credentials.
-
In your terminal, run:
aws configure
-
You’ll be prompted for four pieces of information:
-
AWS Access Key ID: Enter your key.
-
AWS Secret Access Key: Enter your secret.
-
Default region name: e.g.,
us-east-1,eu-west-2 -
Default output format: Enter
json
-
Don’t have access keys? Create them in the AWS IAM console.
Step 3: Install Git
If you haven’t already, install Git.
-
Visit https://git-scm.com/
-
Download and run the installer for your OS.
-
Verify installation:
git --version
Step 4: Configure Git for AWS CodeCommit
Here’s where the magic happens — configuring Git to use CodeCommit seamlessly.
-
Set up the AWS CodeCommit credential helper:
git config --global credential.helper '!aws codecommit credential-helper $@'
This tells Git to use the AWS credential helper for all CodeCommit repos.
-
Then configure Git to use the repository’s full path for authentication:
git config --global credential.UseHttpPath true
This is crucial for CodeCommit authentication to work properly.
Step 5: Set Up Your Git User Information
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
Step 6: Create a CodeCommit Repository
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.
Step 7: Clone Your Repository
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.
Step 8: Start Using Your Repository
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!
🛠 Troubleshooting
-
Permission Denied: Make sure your IAM user has CodeCommit permissions.
-
Wrong Region: Double-check that you’re using the right AWS region in your commands.
-
Credential Helper Not Working: Re-run
aws configureto verify AWS CLI is set up correctly.
Got feedback? Ping me on LinkedIn.