[英]Configure vscode to run tests with AWS profile
I want to run tests against my AWS environment using a run configuration in vscode.我想使用 vscode 中的运行配置针对我的 AWS 环境运行测试。
The tests need access to the AWS account to retrieve information like the name of a bucket, a user pool id..测试需要访问 AWS 帐户以检索存储桶名称、用户池 ID 等信息。
I have my credentials configured in ~/.aws/credentials
under [dev-user]
like:我在[dev-user]
下的~/.aws/credentials
中配置了我的凭据,例如:
[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
.我可以使用export AWS_PROFILE=dev-user
从命令行运行它,然后npm run test
。
How do I create a launch config in vscode that does the same?如何在 vscode 中创建具有相同功能的启动配置? 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
环境变量: 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
预启动任务: 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.以上都不能让我从我的测试中访问 AWS 账户。 How do I need to configure launch.json
and / or tasks.json
to get access to the AWS account in my tests?我需要如何配置launch.json
和/或tasks.json
才能在我的测试中访问 AWS 账户?
It turns out that adding "env": { "AWS_PROFILE": "dev-user"}
to your configuration in launch.json
does work.事实证明,将"env": { "AWS_PROFILE": "dev-user"}
添加到launch.json
中的配置中确实有效。
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"}
}
]
}
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" }...我不知道它是否会对任何人有帮助,但对我来说我有一个密钥和密码应该在请求中发送,我下载了 aws 插件但它没有用,搜索了很多我设法解决了它,你会必须发布 vscode 并编辑启动文件,vscode 具有变量的“env”属性....我是这样做的:.... env": { "AWS_DEFAULT_REGION":"xxxxxx", "AWS_ACCESS_KEY_ID":" xxxxxxxxxxxx", "AWS_SECRET_ACCESS_KEY":"xxxxxxxxxxxxxxxxxx" }...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.