Hello Everyone,
Wanted to ask how can I pass existing environment variables to my k6 test, I have the following test:
import "core-js";
import "regenerator-runtime/runtime";
import { sleep, check, group } from "k6";
import { Options } from "k6/options";
import { Rate } from "k6/metrics";
import http from "k6/http";
import { ProxyBaseURL } from "proxy-client-ts";
// import { SSMClient, GetParametersCommand } from "@aws-sdk/client-ssm";
import SSMClient from "aws-sdk/clients/ssm";
export let options: Options = {
vus: 1,
duration: "1s",
thresholds: {
// 90% of requests must finish within 3s.
http_req_duration: ["p(95) < 3000"],
// http errors should be less than 1% for health checks
health_req_failed: ["rate<0.01"],
},
};
console.log(__ENV.AWS_ACCESSKEY);
const ssmPath = "/auth/asymmetric/private-key/tenant-service";
const client = new SSMClient({
region: "us-west-2",
credentials: {
accessKeyId: __ENV.AWS_ACCESSKEY,
secretAccessKey: __ENV.AWS_SECRETKEY,
},
});
// const command = new GetParametersCommand({
// Names: [ssmPath],
// WithDecryption: true,
// });
// creating a custom rate metrics
const health_failed = new Rate("health_req_failed");
export default () => {
console.log("before");
group("hitting myself endpoint with authentication", async function () {
console.log("inside");
try {
const keyPairs = await client
.getParameter({
Name: ssmPath,
WithDecryption: true,
})
.promise();
console.log(keyPairs);
} catch (error) {
console.log(error);
}
console.log("after");
const url = `${ProxyBaseURL.DEV_US}/proxy-service/rest/api/2/proxy/rest/api/2/myself`;
const res = http.get(url);
check(res, {
"status is 401": () => res.status === 401,
});
sleep(1);
});
};
I have tried to run this script with the following commands:
aws-vault exec tenant-dev -- k6 run --include-system-env-vars ./dist/proxy.test.js
k6 run --include-system-env-vars -e AWS_ACCESSKEY=$AWS_ACCESSKEY -e AWS_SECRETKEY=$AWS_SECRETKEY ./dist/proxy.test.js
but I alwayse get the following error:
INFO[0000] CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
when i tried to use this command k6 run --include-system-env-vars -e AWS_ACCESSKEY=$AWS_ACCESSKEY -e AWS_SECRETKEY=$AWS_SECRETKEY ./dist/proxy.test.js
it seems that it assigns the text value to the env variable which is not what i want.
so my question is how do i actually pass those credentaisl down to k6?