AWS CLIからIAM Identity CenterへサインインしてCodeCommitのリポジトリを使用する
Macで操作しました。
目次
AWS CLIバージョンアップ
1 2 |
aws --version |
aws-cli/2.1.38 Python/3.8.8 Darwin/23.2.0 exe/x86_64 prompt/off
ローカルでCLI使うの久しぶりでしたのでAWS CLI の最新バージョンのインストールまたは更新を参照してバージョンアップしました。
1 2 3 |
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" sudo installer -pkg ./AWSCLIV2.pkg -target / |
1 2 |
aws --version |
aws-cli/2.15.30 Python/3.11.8 Darwin/23.2.0 exe/x86_64 prompt/off
バージョンアップも楽になりましたね。
IAM Identity Centerのプロファイルを設定する
[aws configure sso ウィザードでプロファイルを設定する](aws configure sso ウィザードでプロファイルを設定する)の手順です。
1 2 3 4 5 6 |
aws configure sso SSO session name (Recommended): tr-sso SSO start URL [None]: https://xxxxxxxxxx.xxxxxxx.com/start SSO region [None]: ap-northeast-1 SSO registration scopes [sso:account:access]: |
aws configure ssoを実行して、SSO session nameは覚えやすい名前にしました。
SSO start URLはIAM Identity CenterのAWSアクセスポータルのURLです。
SSO regionには、IAM Identity Centerを設定しているリージョンを指定しました。
SSO registration scopesはデフォルトのsso:account:accessのままでEnterを押下しました。
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
https://device.sso.ap-northeast-1.amazonaws.com/
Then enter the code:
上記のメッセージが表示されて、ブラウザが開きました。
[Confirm and continue]を押下しました。
IAM Identity Centerにサインインしました。
MFAも設定されているので安心です。
[Allow]を押下しました。
認証が完了してMacのターミナルに戻ります。
続いてAWSプロファイルの設定が聞かれたので指定しました。
1 2 3 4 |
CLI default client Region [us-east-1]: ap-northeast-1 CLI default output format [None]: json CLI profile name [RoleName-xxxxxxxxx]: tr-sso-codecommit |
.aws/configのプロファイルが作成されました。
1 2 |
aws sts get-caller-identity --profile tr-sso-codecommit |
{
“UserId”: “XXXXXXXXXXXXXX:xxxxxxxxx@xxxxxxxxx”,
“Account”: “123456789012”,
“Arn”: “arn:aws:sts::123456789012:assumed-role/RoleName/xxxxxxxxx@xxxxxxxxx”
}
プロファイル指定のget-caller-identityコマンドで確認して、IAM Identity Centerから引き受けたIAMロールの認証を使っていることがわかりました。
1 2 3 4 5 6 7 8 9 10 11 12 |
[profile tr-sso-codecommit] sso_session = tr-sso sso_account_id = 123456789012 sso_role_name = RoleName region = ap-northeast-1 output = json [sso-session tr-sso] sso_start_url = https://xxxxxxxxxx.xxxxxxx.com/start sso_region = ap-northeast-1 sso_registration_scopes = sso:account:access |
.aws/configには上記の設定ができていました。
プロファイルtr-sso-codecommitがsso-sessionセクションを使用しています。
.gitconfigの設定
[credential “https://git-codecommit.ap-northeast-1.amazonaws.com”]
helper = !aws –profile tr-sso-codecommit codecommit credential-helper $@
UseHttpPath = true
東京リージョンのCodeCommitですので、https://git-codecommit.ap-northeast-1.amazonaws.comに対してのgitコマンドを実行時に使用する認証情報として、CodeCommit認証情報ヘルパーでtr-sso-codecommitプロファイルを指定しました。
1 2 |
git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/RepositoryName |
該当のディレクトリに移動して無事クローンできました。
認証情報がなくなると次のようなメッセージが出力されました。
Error loading SSO Token: Token for tr-sso does not exist
プロファイル名を指定してIAM Identity Centerにログインすればまたgitコマンドでの操作ができます。
1 2 |
aws sso login --profile tr-sso-codecommit |
最後までお読みいただきましてありがとうございました!
「AWS認定資格試験テキスト&問題集 AWS認定ソリューションアーキテクト - プロフェッショナル 改訂第2版」という本を書きました。

「AWS認定資格試験テキスト AWS認定クラウドプラクティショナー 改訂第3版」という本を書きました。

「ポケットスタディ AWS認定 デベロッパーアソシエイト [DVA-C02対応] 」という本を書きました。

「要点整理から攻略するAWS認定ソリューションアーキテクト-アソシエイト」という本を書きました。

「AWSではじめるLinux入門ガイド」という本を書きました。


開発ベンダー5年、ユーザ企業システム部門通算9年、ITインストラクター5年目でプロトタイプビルダーもやりだしたSoftware Engineerです。
質問はコメントかSNSなどからお気軽にどうぞ。
出来る限りなるべく答えます。
このブログの内容/発言の一切は個人の見解であり、所属する組織とは関係ありません。
このブログは経験したことなどの共有を目的としており、手順や結果などを保証するものではありません。
ご参考にされる際は、読者様自身のご判断にてご対応をお願いいたします。
また、勉強会やイベントのレポートは自分が気になったことをメモしたり、聞いて思ったことを書いていますので、登壇者の意見や発表内容ではありません。
ad
ad
関連記事
-
-
Amazon CloudWatch Anomaly Detectionをダッシュボードに設定
Amazon CloudWatch クロスリージョンクロスアカウントダッシュボー …
-
-
Rocket.ChatにAWS Lambda(Python)から投稿する
Rocket.ChatにAPIで投稿するテスト(Postman)をやってみて、使 …
-
-
Lambda関数をPython3.6から3.9に変更
CodeGuru ProfilerでLambda関数(Python 3.9)のパ …
-
-
AWS APIリクエストにPostmanで署名を作成する
新年明けましておめでとうございます! 署名バージョン4 「AWSはマネジメントコ …
-
-
AWS Secrets ManagerのローテーションでLambda関数の管理が必要なくなりました
Amazon RDS と AWS Secrets Manager の統合を発表と …
-
-
Amazon Glacierのプロビジョニングされた迅速取り出し容量をなぜか購入しました
過去1年ぐらいのAWSコストをCost Explorerで見てまして、10/10 …
-
-
Rocket.ChatにAPIで投稿するテスト(Postman)
トレーニング期間中で一時利用するチャットが欲しいなあと思い、Rocket.Cha …
-
-
Amazon SESの受信ルールでSNSトピックを追加
SESの受信ルールにSNSトピックを設定してみました。 [View Active …
-
-
AWS Cost Explorerの設定で「EC2リソースの推奨事項を受け取る」を有効にしました
「EC2リソースの推奨事項を受け取る」という機能がAWS Cost Explor …
-
-
CloudWatch Internet Monitor(プレビュー)を試しました
Amazon CloudWatch Internet Monitor プレビュー …