1

I'm new to VScode and trying to figure out if there's a simple way to implement this. Essentially I've a lot of AWS accounts / profiles and for local testing I need to be able to switch between the accounts , run something and then check the logs.

However when I click run it's using the default credentials I have

Connected as other account but showing buckets from default account

Is there a correct way of getting the "Run" feature to use whatever AWS Toolkit profile is selected at the time?

My use case is that 99% of the time I will want to create a random ad-hoc script to do something simple and want to avoid having to mess with config files.

If this isn't possible is there a recommended way to quickly switch

rioV8
  • 24,506
  • 3
  • 32
  • 49
segaps
  • 47
  • 6

2 Answers2

1

You should have a AWS ToolKit extension widget in the bottom left hand corner of the window.

AWS Extension Widget

Clicking it will bring up this menu to select from your locally configured credentials.

Credential Menu

Ciara Spencer
  • 111
  • 2
  • 11
  • So I've tried that but even with the profile selected it seems to be using my base credentials https://ibb.co/qsgvwFQ and what we see when running in VS with the profile selected and loaded -> https://ibb.co/1MMzp0B – segaps May 01 '23 at 20:00
  • 1
    So the terminal itself could be set up to source [previously configured credentials via AWS CLI](https://github.com/aws/aws-toolkit-vscode/issues/1609#issuecomment-811141566). When you set-up the configuration profiles did you create them via the VSCode command palette using [AWS Toolkit Create Credentials Profile](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-credentials.html)? Alternatively, if the profiles vary from project to project, you can specify the AWS Profile to use for each in [launch.json](https://stackoverflow.com/a/65500570/14436643) env configuration. – Ciara Spencer May 05 '23 at 17:59
0

How to configure VSCode for multiple AWS Accounts provides some solutions:

  • In your code, call boto3.setup_default_session(profile_name='profile-name')
  • Set "env": { "AWS_PROFILE": "dev-user"} in the relevant launch.json item. (Full example for reference).

I will want to create a random ad-hoc script to do something simple and want to avoid having to mess with config files.

Not currently possible with AWS Toolkit. The details of how the SDK (boto3 in your example) can get the credentials, are not obvious (environment variables?). The "Play" button in your screenshot is provided by the vscode Python extension, not AWS Toolkit.

A related idea is for the current AWS Toolkit credentials to flow into vscode Terminals. Work in progress for that: https://github.com/aws/aws-toolkit-vscode/pull/3040

Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60