A quick guide to using AWS CodeCommit using the AWS CLI.
Enough for getting around!
Generate SSH credentials
Required for cloning a repository:
ssh-keygen -f ~/.ssh/codecommit_rsa
Then, set this up with CodeCommit:
Sign to the AWS Console.
Open your IAM Users page, and select the
user you wish to give CodeCommit access to with this SSH key (or create a new one and use it for
the rest of the steps).
Click Add permissions, then Attach existing policies directly.
Use the Filter policies search box to search for "codecommit". Choose the checkbox
near either AWSCodeCommitFullAccess (to allow repository deletion) or AWSCodeCommitPowerUser
to allow write permission.
Click Next: Review, then Add permissions.
Switch to the Security Credentials tab for your IAM user, and click the
Upload SSH public key button.
Copy the contents of
~/.ssh/codecommit_rsa.pub and paste it into the Upload
SSH public key dialog.
Create (or edit)
~/.ssh/config, and add the following contents:
You'll fill in that sample
REPLACEME value next...
That last setting,
PubkeyAcceptedKeyTypes, was required on my Fedora installation
because the ssh-rsa algorithm used by CodeCommit has been deprecated.
Back in the AWS console, copy the SSH key ID from your IAM user's Summary page, and
paste it in place of
REPLACEME in the
Save and close the file.
Go to your command-line, and change
~/.ssh/config's permissions to
You should now be able to use the SSH key to access your CodeCommit repositories!
- For more info
Creating a repository
aws codecommit create-repository --repository-name
Creates a repository using
repositoryName as the repository name, and prints its info (the
same info you get when running aws codecommit get-repository).
After creating a repository, you can clone it to add files to your
new, blank repository.
Listing your repositories
aws codecommit list-repositories
Prints a listing of the repositories for your account. For each, it reports the
Getting info about a repository
aws codecommit get-repository --repository-name
Lists the metadata associated with the repository, including:
accountId - The ID of your AWS account.
repositoryId - A GUID that represents your repository.
repositoryName - The "friendly" name of the repository.
repositoryDescription - A description of the repository. You can change this by using the
aws codecommit update-repository-descripotion command.
defaultBranch - The branch that will be cloned when one is not specified. You can change this
by using the
aws codecommit update-default-branch command.
lastModifieddate - The last modified date of the repository.
creationDate - The creation date of the repository
cloneUrlHttps - The URL to use when cloning the repository using HTTPS
cloneUrlSsh - The URL to use when cloning the repository with SSH
Arn - The AWS Resource Name (ARN) for the repository.
cloneUrlSsh field, in particular, is important when you want to clone the repository in order to work with its files.
Cloning a repository
Once you've set up your SSH credentials correctly, you can clone the
Using the aws codecommit get-repository command to get the
cloneUrlSsh value for cloning the repository.
cloneUrlSsh value to clone your repository like any other git
Once you've cloned the repository, you can use normal git commands to work with your
local copy, or git pull and git push to interact with your codecommit
Migrating your existing git repository to CodeCommit
Here's an example that puts it all together. ;)
Say that I have a repository (
repositoryName) hosted at another server and I want to move it to
CodeCommit, without losing any of my history. I can do it all with an AWS CLI command and a few
Clone the repository I want to move:
Enter the cloned repository directory:
Create the new repository on CodeCommit:
aws codecommmit create-repository --repository-name
This prints information about your repository. For example:
Create a new git remote, using the value of cloneUrlSsh:
git remote add codecommit
Now, push your repository to the new remote:
git push codecommit
Remove the old origin remote:
Rename your codecommit remote as origin:
git remote rename codecommit origin
For more information about using CodeCommit, head over to the official AWS documentation: