How to Set up Dual-Authentication to GitHub and AWS CodeCommit

Both GitHub and AWS CodeCommit are used to version-control your source code. I use GitHub to share my code with the wider community and CodeCommit for production code for AWS. You may use other source control systems like BitBucket. Whatever the choice you make, it is convenient to set up your local machine to commit code to multiple Git-like code repositories.

In this post, I will show you how to set up dual-authentication to GitHub and AWS CodeCommit repositories. You can pretty much use the same way to set up Git connections to other tools. At work, I do the dual-authentication to CodeCommit and BitBucket in the same way.

Prerequisite

We assume you have AWS and BitBucket account and of course Git installed.

Steps

(1) Create SSH keys for both GitHub and CodeCommit. Use the online documentation here for GitHub and here for CodeCommit.

(2) Each SSH key pair will be created in the .ssh directory (usually located in your home directory). Name the keys so that you can differentiate them. Then, create config file as below.

(3) In the config file, you can define hosts, user ids and the paths to the private keys as below. For CodeCommit, user can be retrieved from the management console as described here. For GitHub, user is the user name.

# AWS Code Commit
Host git-codecommit.*.amazonaws.com
  User you-user-id
  IdentityFile ~/.ssh/codecommit_rsa

# Default GitHub
Host github.com
  HostName github.com
  User your-user-name
  IdentityFile ~/.ssh/id_rsa_git

(4) Create a repository named test_github in GitHub and test_codecommit in CodeCommit. Using UI is the easiest for GitHub. For CodeCommit, you can run AWS CLI command as below.

aws codecommit create-repository ^
--repository-name test_codecommit ^
--repository-description "test_codecommit"

(5) You can check the authentication in each system.

ssh -T git@github.com
ssh git-codecommit.(your aws region).amazonaws.com

(6) Let’s test by running the script below.

BitBucket

mkdir test_github
cd test_github
touch test.txt
echo hellogithub >> test.txt
git init
git add *
git status
git commit -m "git hub connectivity check"
git remote add origin git@github.com:(your username)/test_github
git push origin master

CodeCommit

mkdir test_codecommit
cd test_codecommit
touch test.txt
echo hellocodecommit >> test.txt
git init
git add *
git status
git commit -m "git hub connectivity check"
git remote add origin ssh://git-codecommit.(your region).amazonaws.com/v1/repos/test_codecommit
git push origin master

You can see the file is committed to the remote branches for both. Yay!

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …