Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is how to properly select AWS CLI profiles for your stacks/accounts #3961

Closed
jeshan opened this issue Sep 5, 2019 · 5 comments
Closed
Assignees
Labels
management/devenv Related to CDK development/build environment management/tracking Issues that track a subject or multiple issues ops-excellence Operational Excellence package/tools Related to AWS CDK Tools or CLI

Comments

@jeshan
Copy link

jeshan commented Sep 5, 2019

There are various discussions here about how to use select the appropriate CLI profiles. I have not found any suitable solution until now.
In particular, AWS_PROFILE wasn't enough since cdk needs to make calls in different accounts for different stacks.

I wanted a solution that could:

  1. reuse my existing profiles (~/.aws/config), but also
  2. different profiles for different accounts (in my case, this implied different cdk stacks), while
  3. keeping the cli invocation simple.

The trick is to use the plugin feature which really means just a javascript class.
You can define a class which will be loaded at runtime. It allows you to pick some profile for a certain account ID.

Here is the gist and an example cdk.json:
https://gist.github.com/jeshan/178dfa811df0f652b30d3cc61058512d/

Note that you can also specify plugins with: cdk --plugin ... deploy

I'm leaving this here as a how-to for the community. Feel free to copy the class into your project.

If anybody knows of a simpler way to achieve this, please let me know.

@jeshan jeshan added the needs-triage This issue or PR still needs to be triaged. label Sep 5, 2019
@NGL321 NGL321 added management/devenv Related to CDK development/build environment management/tracking Issues that track a subject or multiple issues ops-excellence Operational Excellence package/tools Related to AWS CDK Tools or CLI and removed needs-triage This issue or PR still needs to be triaged. labels Oct 10, 2019
@NGL321 NGL321 pinned this issue Oct 10, 2019
@NGL321
Copy link
Contributor

NGL321 commented Oct 10, 2019

Hey @jeshan,

Thank you so much for sharing your solution! I am pinning this issue for now to increase visibility

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 11, 2019

@ NLG321 I feel this should be merged into the Authentication master issue that is also pinned. Thoughts?

@jeshan
Copy link
Author

jeshan commented Oct 13, 2019

No problem. I must tell you it works well on typical dev setups but not on CodeBuild. I still have not figured the latter out

@NGL321 NGL321 unpinned this issue Oct 15, 2019
@john-tipper
Copy link

To get this to work for me, I needed to change the call to AWS.SharedIniFileCredentials as per the docs, to pass in an object with the key profile and value of the profile name.

i.e.

new AWS.SharedIniFileCredentials({profile: 'myprofile'})

@jeshan jeshan closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
management/devenv Related to CDK development/build environment management/tracking Issues that track a subject or multiple issues ops-excellence Operational Excellence package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants