'Configure vscode to run tests with AWS profile
I want to run tests against my AWS environment using a run configuration in vscode.
The tests need access to the AWS account to retrieve information like the name of a bucket, a user pool id ..
I have my credentials configured in ~/.aws/credentials under [dev-user] like:
[dev-user]
aws_access_key_id=*************
aws_secret_access_key=***************************************
I can run this from the command line with export AWS_PROFILE=dev-user and then npm run test.
How do I create a launch config in vscode that does the same? Currently it is not working. I've tried the following: adding env variables or a prelaunch task. But neither of them work:
Env vars:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"env": { "AWS_PROFILE": "dev-user"}
}
]
}
Pre launch task:
launch.json
{
"version": "2.0.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"preLaunchTask": "setProfile",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "setProfile",
"command": "export AWS_PROFILE=dev-user",
"args": ["test"],
"type": "shell"
}
]
}
None of the above gives me access to the AWS account from my tests.
How do I need to configure launch.json and / or tasks.json to get access to the AWS account in my tests?
Solution 1:[1]
It turns out that adding "env": { "AWS_PROFILE": "dev-user"} to your configuration in launch.json does work.
So this is correct:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"env": { "AWS_PROFILE": "dev-user"}
}
]
}
Solution 2:[2]
I don't know if it will help anyone, but for me I had a key and password that should be sent in the request, I downloaded aws plugin and it didn't work, searching a lot I managed to solve it, you will have to post vscode and edit the launch file, the vscode has "env" property for variables .... I did it like this: .... env": { "AWS_DEFAULT_REGION":"xxxxxx", "AWS_ACCESS_KEY_ID":"xxxxxxxxxxxx", "AWS_SECRET_ACCESS_KEY":"xxxxxxxxxxxxxxxxxx" } ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | xtra |
| Solution 2 | Gabriel Gerlin Dias |
