[英]Configure vscode to run tests with AWS profile
我想使用 vscode 中的運行配置針對我的 AWS 環境運行測試。
測試需要訪問 AWS 帳戶以檢索存儲桶名稱、用戶池 ID 等信息。
我在[dev-user]
下的~/.aws/credentials
中配置了我的憑據,例如:
[dev-user]
aws_access_key_id=*************
aws_secret_access_key=***************************************
我可以使用export AWS_PROFILE=dev-user
從命令行運行它,然后npm run test
。
如何在 vscode 中創建具有相同功能的啟動配置? 目前它不工作。 我嘗試了以下方法:添加環境變量或預啟動任務。 但它們都不起作用:
環境變量: 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"}
}
]
}
預啟動任務: 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"
}
]
}
以上都不能讓我從我的測試中訪問 AWS 賬戶。 我需要如何配置launch.json
和/或tasks.json
才能在我的測試中訪問 AWS 賬戶?
事實證明,將"env": { "AWS_PROFILE": "dev-user"}
添加到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"}
}
]
}
我不知道它是否會對任何人有幫助,但對我來說我有一個密鑰和密碼應該在請求中發送,我下載了 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.