kun432's blog

Alexaなどスマートスピーカーの話題中心に、Voiceflowの日本語情報を発信してます。たまにAWSやkubernetesなど。

〜スマートスピーカーやVoiceflowの記事は右メニューのカテゴリからどうぞ。〜

AWS SSO環境でCodeCommitを使う

f:id:kun432:20210713025747p:plain

ちょっとメモ。

前提条件

  • AWS SSOを使っている
  • aws-vaultを使っている
  • AWS SSOのプロファイルは作成済みであること
  • アクセスキーとかシークレットアクセスキーは使わない

CodeCommitでレポジトリ作成

とりあえず空のレポジトリを作成。レポジトリ名は"testrepo"とした。

f:id:kun432:20210713030101p:plain

右上の「URLのクローン」から「HTTPSのクローン」をクリック

f:id:kun432:20210713030302p:plain

クリップボードにレポジトリのURLがコピーされる。今回のURLはhttps://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/testrepo

f:id:kun432:20210713030338p:plain

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"をクリックする

f:id:kun432:20210713032726p:plain

サインインできたらターミナルに戻る。

f:id:kun432:20210713032742p:plain

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されている。

f:id:kun432:20210713033137p:plain

参考

ここがとても参考になった。

ここの「おまけ」にあるエラーは必ず経験するはず。Linuxの場合はpassとかを使うけど、認証情報のタイムラグみたいなことは同じように起きる。結構面倒。