Search code examples
aws-cdk

`cdk ls` spits out raw cloudformation (or something) if AWS_PROFILE is set


I am starting a new CDK project (Python)

If I run cdk ls then I see the name of the stack I have defined in my app.py

e.g.

$ cdk ls
Website-EU-examples

However if the AWS_PROFILE env var is set in my terminal then when I cdk ls I get seemingly endless screens of what looks like raw CloudFormation template (?) code printed to the console.

(here is just a tiny sample)

:{Code:{locationName:"code"},Message:{locationName:"message"}}},SpotFleetRequestId:{locationName:"spotFleetRequestId"}}}}}}},CancelSpotInstanceRequests:{input:{type:"structure",required:["SpotInstanceRequestIds"],members:{DryRun:{locationName:"dryRun",type:"boolean"},SpotInstanceRequestIds:{shape:"S8y",locationName:"SpotInstanceRequestId"}}},output:{type:"structure",members:{CancelledSpotInstanceRequests:{locationName:"spotInstanceRequestSet",type:"list",member:{locationName:"item",type:"structure",members:{SpotInstanceRequestId:{locationName:"spotInstanceRequestId"},State:{locationName:"state"}}}}}}},ConfirmProductInstance:{input:{type:"structure",required:["InstanceId","ProductCode"],members:{InstanceId:{},ProductCode:{},DryRun:{locationName:"dryRun",type:"boolean"}}},output:{type:"structure",members:{OwnerId:{locationName:"ownerId"},Return:{locationName:"return",type:"boolean"}}}},CopyFpgaImage:{input:{type:"structure",required:["SourceFpgaImageId","SourceRegion"],members:{DryRun:{type:"boolean"},SourceFpgaImageId:{},Description:{},Name:{},SourceRegion:{},ClientToken:{}}},output:{type:"structure",members:{FpgaImageId:{locationName:"fpgaImageId"}}}},CopyImage:{input:{type:"structure",required:["Name","SourceImageId","SourceRegion"],members:{ClientToken:{},Description:{},Encrypted:{locationName:"encrypted",type:"boolean"},KmsKeyId:{locationName:"kmsKeyId"},Name:{},SourceImageId:{},SourceRegion:{},DestinationOutpostArn:{},DryRun:{locationName:"dryRun",type:"boolean"},CopyImageTags:{type:"boolean"}}},output:{type:"structure",member^C

I assume this is not expected? Any idea what's wrong?

It's quite likely there are other existing CDK deployments in this account, I'd assumed they would just coexist and deploy independent bits of infra - could I be experiencing a symptom of that not being the case?


Solution

  • It turns out that what looked like endless screens of raw CloudFormation template was actually just the preamble to an error message.

    If I actually let it print out the whole thing instead of ctrl+C halfway through then eventually I see at the bottom:

    SSOTokenProviderFailure: SSO Token refresh failed. Please log in using "aws sso login"
        at refreshUnsuccessful2 (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:485588)
        at Response.<anonymous> (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:488573)
        at Request.<anonymous> (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:191855)
        at Request.callListeners (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:90083)
        at Request.emit (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:89531)
        at Request.emit (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:196289)
        at Request.transition (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:189841)
        at AcceptorStateMachine.runTo (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:154713)
        at /Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:155043
        at Request.<anonymous> (/Users/anentropic/.nvm/versions/node/v18.18.0/lib/node_modules/aws-cdk/lib/index.js:362:190133) {
      code: 'SSOTokenProviderFailure',
      time: 2023-10-10T09:33:40.953Z
    }
    
    Node.js v18.18.0
    

    And indeed if I do an aws login and then try again I see the expected output from cdk ls.