Deployment failed: Error: Unable to resolve AWS account to use. It must be either configured when you define your CDK Stack, or through the environment

CDK実行時

 ❌ Deployment failed: Error: Unable to resolve AWS account to use. It must be either configured when you define your CDK Stack, or through the environment
    at SdkProvider.resolveEnvironment (/home/user/.asdf/installs/nodejs/20.5.1/lib/node_modules/aws-cdk/lib/index.js:356:14622)
    at async Deployments.prepareSdkFor (/home/user/.asdf/installs/nodejs/20.5.1/lib/node_modules/aws-cdk/lib/index.js:446:7691)
    at async Deployments.isSingleAssetPublished (/home/user/.asdf/installs/nodejs/20.5.1/lib/node_modules/aws-cdk/lib/index.js:446:11602)
    at async /home/user/.asdf/installs/nodejs/20.5.1/lib/node_modules/aws-cdk/lib/index.js:446:138953

Unable to resolve AWS account to use. It must be either configured when you define your CDK Stack, or through the environment

原因

AWSの認証が通ってない(or切れた)

対処

認証する(Assume/Swith Role再実行、AWS SSO実行など)

補足

aws s3 lsとかすると普通にデータ取れて、認証切れてないじゃん!と思うんだけど、そのあとすぐ今度はaws s3 lsがとおらなくなったりするので、なんでさっきの時点でaws s3 lsは通ってcdkは通らないか不明なんだけど、とにかくcdkではAWSの認証が切れてる。なのでとりあえずAWS認証し直す。うまくいかない場合はもう一回やってみるとか数分置いてやってみるとか。