ちょっとメモ。
前提条件
- AWS SSOを使っている
- aws-vaultを使っている
- AWS SSOのプロファイルは作成済みであること
- アクセスキーとかシークレットアクセスキーは使わない
CodeCommitでレポジトリ作成
とりあえず空のレポジトリを作成。レポジトリ名は"testrepo"とした。
右上の「URLのクローン」から「HTTPSのクローン」をクリック
クリップボードにレポジトリのURLがコピーされる。今回のURLはhttps://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/testrepo
。
gitでclone/push
ではcloneする。ちょっとややこしいけど、Git 認証情報ヘルパーがaws-vault経由でAWS認証情報を使用するように設定する。
$ git clone \ --config 'credential.helper=!aws-vault exec SSOプロファイル名 -- aws codecommit credential-helper $@' \ --config 'credential.UseHttpPath=true' \ https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/testrepo
こんな感じでSSOのログインを促すメッセージが表示されて・・・
Cloning into 'testrepo'... Opening the SSO authorization page in your default browser (use Ctrl-C to abort) https://device.sso.us-east-1.amazonaws.com/?user_code=ZXQQ-LFXR
ブラウザが立ち上がるので"Sign In to AWS CLI"をクリックする
サインインできたらターミナルに戻る。
cloneされている。今回は空なのでwarningが出ているだけ。
warning: You appear to have cloned an empty repository.
$ ls
testrepo
cloneしたディレクトリで適当にpushする
$ cd testrepo $ echo "# testrepo" >> README.md $ git add . $ git commit -m "initial commit" [master (root-commit) XXXXXXX] initial commit 1 file changed, 1 insertion(+) create mode 100644 README.md $ git push Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 248 bytes | 248.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/testrepo * [new branch] master -> master
CodeCommitを見てみるとちゃんとpushされている。
参考
ここがとても参考になった。
ここの「おまけ」にあるエラーは必ず経験するはず。Linuxの場合はpassとかを使うけど、認証情報のタイムラグみたいなことは同じように起きる。結構面倒。