If you use AWS CodeCommit as your version control repo, you may want to set up a credential helper so that you can easily sync your code from VS Code. Fortunately, the AWS CLI includes just such a credential helper.
Setting up the AWS CLI Credentials
To check that you have the AWS CLI installed and view the existing configuration of your AWS CLI, run:
aws configure list
This will show the variable values for the default profile. It also lists where your config
file is stored. If your configuration is empty, you can either edit the file directly or provide the values interactively by running aws configure
. To set up a specific AWS CLI configuration profile, add the --profile
switch and value to the aws
command, for example: aws --profile myProfile configure
.
Setting up the Git Client to use the AWS Credential Helper
Once you have the configuration set up, you need to connect your git client to the credential helper. You have several options for this: you can connect your git client globally, so that the same credential helper is used for all git calls, or you can connect a specific repo to the credential helper. For any connection to the credential helper, you can also specify an AWS config profile (if one is not specified, the default profile will be used).
Git Global Set Up
To globally connect your git client to the AWS CLI credential helper, run the following:
git config --global credential.helper '!aws --profile myProfile codecommit credential-helper $@'
git config --global credential.UseHttpPath true
If you want to use the default profile, you can omit the --profile
switch and value. Now you should be able to go to Code Commit, copy the HTTPS clone endpoint, and clone the repository using git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name
.
Git Local Set Up
If you want to keep your current credential helper for all other repos but use the AWS CLI credential helper for a specific repository, you can configure the credential helper for the current repository only. Since this setup is specific to a repo, you will have to have an initialized repository set up, rather than simply cloning from Code Commit. To do this, navigate to the directory where you want to store the code, and run git init
. Now, you can set up the local credential helper. The process is the same as for the global setup, except that you replace the --global
switch with --local
:
git config --local credential.helper '!aws --profile myProfile codecommit credential-helper $@'
git config --local credential.UseHttpPath true
To connect your local repo to the Code Commit repo, add the HTTPS clone endpoint as a remote origin, and map the local and remote branches:
git remote add origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name
git branch --set-upstream-to=origin/master master
You should now be able to run git fetch
and git pull
to populate the repo!