Can VSCode use AWS Toolkit credentials for running file

865 Views Asked by At

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

2

There are 2 best solutions below

2
Ciara Spencer On

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

0
Justin M. Keyes On

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