aws-cdk: (core): cdk diff fails with Need to perform AWS calls for account XXX, but the current credentials are for YYY
Describe the bug
When running cdk diff on a project with stack that belong to multiple AWS accounts (bootstrapped so that a IAM role is assumed by CDK), the following error is reported:
[100%] fail: Need to perform AWS calls for account XXX, but the current credentials are for YYY
Failed to create change set with error: 'Failed to publish one or more assets. See the error messages above for more information.', falling back to no change-set diff
This only happens since version 119 (120 is affected too).
Running cdk deploy for the same stack works correctly.
Expected Behavior
cdk diff should work correctly as before
Current Behavior
cdk diff fails
Reproduction Steps
will try and provide an isolated example later, but this only happens for two stacks (out of ~10 identical ones across different accounts).
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.120.0 (build 58b90c4)
Framework Version
No response
Node.js Version
v20.10.0
OS
Linux
Language
TypeScript
Language Version
No response
Other information
No response
About this issue
- Original URL
- State: open
- Created 6 months ago
- Reactions: 12
- Comments: 22 (11 by maintainers)
Thank you. We are going to address the messaging and look into it further. I wanted to make sure this receives the right priority. For example if the command would have failed completely, we would have reverted or released a hot fix.
Definitely keeping this open for further investigation.
Yep. If you are specifically wanting the change-set diff and it’s failing, even with the fall back to classic diff succeeding, definitely a bug. And I think it’s likely your correct on your assessment of what’s going on here.
It looks like the diff proceeds, the messaging is just unnecessarily scary. We will tone down the error messaging
@pahud @mrgrain - as @scarytom mentioned, this behavior appears to be a bug in the diff being able to properly assume the trust role required to download/upload the diff to the metadata directory in the target account and so the CDK is falling back to doing a diff with disk cache locally or the like; this is breaking behavior in an automated environment where CDKPipelines has a single deployment pipeline account that uses a trust role to deploy resources to each target account in the pipeline.
I’ve just upgraded our pipelines to
2.136.0from2.88.0and prior to the upgrade I was not experiencing the error locally.If I locally assume the creds of my pipelines account to run a diff AS the pipelines account against a target account locally on my machine (something I do all the time) using the verbose command, the diff is failing to assume the trust role in the target account and gives the same error message as above but the diff succeeds using disk cache.
If I then run a deploy to the target account of some change, again from my local machine AS the pipelines account, using those same creds, it succeeds (like it did before), but then if I let the change roll through my CDKPipeline in CodeBuild, the pipeline build is not detecting the changes that I deployed locally (AS the pipelines account) because the metadata in the target account from my previous deploy is not getting updated due to this failure.
Previously, in
2.88.0, the local CDK diff & deploy against the target account AS the pipelines account would result in a no-op once the deploy reached that stage in the pipeline because it would see the templates are already the same and have been updated.To summarize:
Because the last one fails, even if I can run a successful deploy locally, the next time a deploy rolls through the pipeline, the metadata hasn’t reflected my local deployment and the pipeline tries to duplicate the changes.
This is blocking for us and I’ve rolled our infra pkg back to the previous rev but this appears to be the behavior I’m seeing.
Here is the error we get, with trace debug on, if that helps.