(cli): A way to get profile name in stack when it's specified in the command-line option
See original GitHub issueI use AWS SDK in my CDK stack to fetch information that is not managed by CDK. When I set the profile name by using ‘–profile’ option, it only affects to stack itself but not the inner AWS SDK. It means that CDK stack will deploy on Account A but AWS SDK fetch the information from Account B.
Of course, when I set the profile manually in the source code like this, it works. But it’s not flexible especially when I want to switch deploy stages.
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: 'MyProfileNameForAccountA' });
Is there any way to get the profile name specified in the command line option? If not, I would like to ask you to add the way to get the profile name in the stack like this.
const profileName = // A way to get profile name that is specified in the command-line option.
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: profileName });
Use Case
This feature is useful for those who want or need to use AWS SDK in the stacks even if it is not a recommended way to manage resources.
Proposed Solution
A way to get profile name when it is specified in the command-line option.
I saw the profile name in the result of cdk deploy --verbose
as command-line arguments, so I hope the information is passed to the stack. (But cannot get it directly for now.)
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top GitHub Comments
Why this issue is closed? It’s still actual, generic and is unrelated to “using SDK from CDK anti-pattern”.
I worked around this by changing the way I specified the profile. Instead of
npx cdk --profile my-aws-profile deploy
I specified it in the standardAWS_PROFILE
environment variable:This worked just the same as using
--profile
, but with the added advantage that the AWS SDK also picked up the profile automatically so I could do the lookups I needed that CDK doesn’t support.