question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
rix0rrrcommented, Oct 11, 2019

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

0reactions
github-actions[bot]commented, Jun 13, 2022

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Named profiles for the AWS CLI
A named profile is a collection of settings and credentials that you can apply to a AWS CLI command. When you specify a...
Read more >
Configuring the AWS CLI - AWS Command Line Interface
Configure the AWS Command Line Interface (AWS CLI) and specify the settings for interacting with AWS.
Read more >
Configuration basics - AWS Command Line Interface
This section explains how to quickly configure basic settings using the config and credentials files that the AWS Command Line Interface (AWS CLI)...
Read more >
Configuration and credential file settings - AWS Documentation
The files are divided into profiles . By default, the AWS CLI uses the settings found in the profile named default .
Read more >
Configuring the AWS CLI to use AWS IAM Identity Center ...
Automatically, using the aws configure sso and aws configure sso-session commands. Manually, by editing the config file that stores the named profiles.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found