Closed2
cdkがprofileで指定されたcredentialを認識しない

~/.aws/config 、~/.aws/credentials は設定済みの状態で以下のエラー
$ cdk bootstrap aws://123456789012/ap-northeast-1 --profile hoge
❌ Environment aws://123456789012/ap-northeast-1 failed bootstrapping: Error: Need to perform AWS calls for account 123456789012, but no credentials have been configured
at SdkProvider.forEnvironment (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:411:659633)
at async _BootstrapStack.lookup (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:450:20871)
at async Bootstrapper.modernBootstrap (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:451:1084)
at async /opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:2329
at async Promise.all (index 0)
at async CdkToolkit.bootstrap (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:2174)
at async exec4 (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:508:54331)
Need to perform AWS calls for account 123456789012, but no credentials have been configured
-vをつけて再度実行
$ cdk bootstrap aws://123456789012/ap-northeast-1 --profile hoge -v
・・・略・・・
Could not refresh notices: Error: unable to get local issuer certificate
・・・略・・・
ローカルの証明書が利用できていないことがわかる
cdk自体はnodeで実行されているが、aws cliはpython
この時、python側でcertifiがimportできない状態になっていた。
ただaws cli(version2)はpythonの組み込みバージョンが使われているので関係なさそう(これはこれで修正)
Python 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import certifi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'certifi'
aws cliを再インストールし、再実行
$ cdk bootstrap aws://123456789012/ap-northeast-1 --profile hoge
⏳ Bootstrapping environment aws://123456789012/ap-northeast-1...
・・・略・・・
✅ Environment aws://123456789012/ap-northeast-1 bootstrapped
cdk側のIssueを追って無駄に時間を取られてしまった。

--profile オプションだとプロファイルを読んでくれない
$ npm run cdk:deploy --profile hoge
環境変数で指定すればOK
$ AWS_PROFILE=hoge npm run cdk:deploy
このスクラップは2024/08/01にクローズされました