- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在我的 cypress 测试中获取 AWS secret,但我一直收到 CredentialsError
Missing credentials in config, if using AWS_CONFIG_FILE, setAWS_SDK_LOAD_CONFIG=1
我确实有一个 ~/.aws/credentials 文件,其中设置了我的 aws_access_key_id 和 aws_secret_access_key。
在我的代码中,我将所有环境变量导出到一个文本文件,我可以看到 AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY 和 AWS_SESSION_TOKEN 的值。
我也尝试设置环境变量 AWS_SDK_LOAD_CONFIG=1
但仍然收到相同的消息。
我需要 ~/.aws/credentials 还是可以通过环境变量来完成?
谁能看到我遗漏了什么:(99% 的代码是亚马逊在 secret 管理器页面上提供的代码我只是想将响应包装在 Cypress 对象中。我已经删除了我的 AWS 详细信息和将它们替换为 REMOVED)
Cypress.Commands.add("aws_secret", () => {
// Use this code snippet in your app.
// If you need more information about configurations or implementing the sample code, visit the AWS docs:
// https://aws.amazon.com/developers/getting-started/nodejs/
cy.exec(`printenv >> envs.txt`);
// Load the AWS SDK
var AWS = require("aws-sdk"),
region = “REMOVED”,
secretName = “REMOVED”,
secret,
decodedBinarySecret;
// Create a Secrets Manager client
var client = new AWS.SecretsManager({
region: region,
});
// In this sample we only handle the specific exceptions for the 'GetSecretValue' API.
// See https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
// We rethrow the exception by default.
client.getSecretValue({ SecretId: secretName }, function (err, data) {
if (err) {
if (err.code === "DecryptionFailureException")
// Secrets Manager can't decrypt the protected secret text using the provided KMS key.
// Deal with the exception here, and/or rethrow at your discretion.
throw err;
else if (err.code === "InternalServiceErrorException")
// An error occurred on the server side.
// Deal with the exception here, and/or rethrow at your discretion.
throw err;
else if (err.code === "InvalidParameterException")
// You provided an invalid value for a parameter.
// Deal with the exception here, and/or rethrow at your discretion.
throw err;
else if (err.code === "InvalidRequestException")
// You provided a parameter value that is not valid for the current state of the resource.
// Deal with the exception here, and/or rethrow at your discretion.
throw err;
else if (err.code === "ResourceNotFoundException")
// We can't find the resource that you asked for.
// Deal with the exception here, and/or rethrow at your discretion.
throw err;
} else {
// Decrypts secret using the associated KMS CMK.
// Depending on whether the secret is a string or binary, one of these fields will be populated.
if ("SecretString" in data) {
secret = data.SecretString;
cy.log("the secret is " + secret);
} else {
let buff = new Buffer(data.SecretBinary, "base64");
decodedBinarySecret = buff.toString("ascii");
cy.log("the decodedBinarySecret is " + decodedBinarySecret);
}
}
// Your code goes here.
cy.wrap(
client.getSecretValue({ SecretId: "REMOVED" }).promise()
).as("key1");
});
});
最佳答案
您无需设置 AWS_SDK_LOAD_CONFIG
。 env
运行该过程并不能保证设置所有相同的环境变量。运行此脚本时如何设置环境变量。
您实际上可以在加载 AWS SDK 之前对此进行测试,添加
console.log('AccessKey: ', process.env.AWS_ACCESS_KEY_ID);
并验证它们是否正在打印。要在节点进程中作为环境变量传递,请执行:导出 AWS_ACCESS_KEY_ID=VALUE;节点./script.js
Docs on setting up Cypress environment variables
以 CYPRESS
为前缀导入:
export CYPRESS_AWS_ACCESS_KEY_ID=VALUE
关于javascript - 配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1(存在凭据文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65041408/
我试图在我的 cypress 测试中获取 AWS secret,但我一直收到 CredentialsError Missing credentials in config, if using AWS_
当我尝试在我的项目中使用 Aws 凭据时,它给出了一个错误,我很难找到解决方案,当我在同一个文件中使用凭据时,它可以工作,但是当我尝试使用时。这是我尝试过的代码 const AWS = require
我正在尝试 添加元素 在 表 在 动态数据库 就像下面的例子,但是当我运行它时,我得到这个错误信息:Missing credentials in the config, if using AWS_CO
我已经将 aws sns 用于消息服务。我使用 dot env 来存储 aws-sdk 的凭据。应用程序在 localhost 中运行良好,但是当我将我的 Node 应用程序部署到 AWS EC2 时
我是一名优秀的程序员,十分优秀!