繁体   English   中英

配置 vscode 以使用 AWS 配置文件运行测试

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM