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.

(cli): A way to get profile name in stack when it's specified in the command-line option

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rayrapetyancommented, Apr 3, 2021

Why this issue is closed? It’s still actual, generic and is unrelated to “using SDK from CDK anti-pattern”.

0reactions
adam-nielsencommented, Oct 17, 2022

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 standard AWS_PROFILE environment variable:

AWS_PROFILE=my-aws-profile npx cdk deploy

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

describe-stacks — AWS CLI 1.27.37 Command Reference
Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created....
Read more >
Setting active profile and config location from command line in ...
Option 1: Java System Properties (VM Arguments). It's important that the -D parameters are before your application.jar otherwise they are not recognized. java...
Read more >
Databricks CLI | Databricks on AWS - Databricks documentation
The Databricks command-line interface (CLI) provides an easy-to-use ... To check whether you set up your connection profiles correctly, ...
Read more >
The java Command - Oracle Help Center
If -jar is specified, then its argument is the name of the JAR file containing ... --add-module options that may be have been...
Read more >
App Manifest Attribute Reference | Cloud Foundry Docs
Each of these attributes can also be specified by a command line option. Command-line options override the manifest. Note: In cf CLI v6,...
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