shou2017.com
JP

Using AWS CodeCommit

Sat Mar 17, 2018
Sat Aug 10, 2024
Git

This blog previously used Bitbucket along with AWS S3, Route53, and CloudFront for operations. However, I decided to switch from Bitbucket to AWS CodeCommit for Git management, consolidating all tools under AWS.

Here are the steps I followed:

Check Git Remote

Run git remote -v to check the current remote. It should show Bitbucket. We will change this to AWS CodeCommit.

$ git remote -v
origin	[email protected]:boku/blog.git (fetch)
origin	[email protected]:boku/blog.git (push)

Create a Repository in CodeCommit

From the AWS Console, select CodeCommit and create a repository.

For “Connect to Repository,” choose SSH. Since root users cannot use SSH, create an IAM user.

Instructions for creating an IAM user can be found here.

SSH Connection

From the IAM user, select authentication information and click “Upload SSH Public Key.” Paste your public key.

Using AWS CodeCommit

If you haven’t created a public key, refer to Setting Up Public and Private Keys for Bitbucket.

Once the public key is uploaded, an SSH Key ID will be generated. Add this SSH Key ID to your ~/.ssh/config file:

$ vim ~/.ssh/config
Host git-codecommit.*.amazonaws.com
  User APKAEIBAERJR2EXAMPLE # SSH Key ID
  IdentityFile ~/.ssh/codecommit_rsa # Path to private key

This completes the SSH connection setup.

Next, verify the connection:

When prompted with Are you sure you want to continue connecting (yes/no)?, type yes.

If the connection is successful, you will see:

$ ssh git-codecommit.us-east-1.amazonaws.com
You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.Connection to git-codecommit.us-east-1.amazonaws.com closed by remote host.
Connection to git-codecommit.us-east-1.amazonaws.com closed.

Now, use git remote set-url origin to change the Git push destination to CodeCommit.

Select the clone URL for the repository and paste it as follows:

Using AWS CodeCommit

$ git remote set-url origin ssh://git-codecommit.us-east-1.amazonaws.com

Verify the change:

$ git remote -v
origin	ssh://git-codecommit.us-east-1.amazonaws.com/ (fetch)
origin	ssh://git-codecommit.us-east-1.amazonaws.com/ (push)

Finally, test pushing to the repository:

$ git push

It worked!

Using AWS CodeCommit

See Also