无法将 aws-sdk 与 browserify 捆绑在一起以在 k6 中使用 sdk 库

Can not bundle aws-sdk with browserify to use sdk library in k6

我非常喜欢 k6 性能工具背后的想法。目前正试图在 Locust 和 k6 之间做出最终选择,因此一切都归结为一个特定用例的解决方案: 我需要在我的性能脚本中使用 aws sdk(例如,发送 SQS 消息)。基于此文档 (https://docs.k6.io/docs/modules#section-importing-javascript-libraries) 以及 aws js sdk 与 browserify 兼容的事实,认为它可能有效,但事实并非如此。

我做了什么:

git clone https://github.com/aws/aws-sdk-js.git
npm install
browserify index.js -s aws > aws.js

之后我尝试使用捆绑的 sdk 创建简单的 k6 脚本来测试这个:

import { check, sleep } from "k6";
import http from "k6/http";
import aws from "./sdk/aws-sdk-js/aws.js";

export default function() {
    var s3 = new aws.S3();
    s3.listBuckets(function(err, data) { console.log(err, data); });
    console.log(Object.getOwnPropertyNames(aws.SQS()));
    let res = http.get("https://google.com/");
    check(res, {
        "is status 200": (r) => r.status === 200
    });
    sleep(3);
};

但不断得到:

ERRO[0001] ReferenceError: escape is not defined
 at /Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:282360:21(632)
 at urlParse (/Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:282168:10(26))
 at urlParse (/Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:276923:26(8))
 at Endpoint (/Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:268402:44(89))
 at initialize (/Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:273218:21(74))
 at Service (/Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:273202:20(76))
 at /Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:277464:36(12)
 at /Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:277464:36(12)
 at /Users/ybushnev/k6/k6/sdk/aws-sdk-js/aws.js:277464:36(12)

对任何帮助都会很有帮助。

作为解决方法,您应该能够使用 AWS REST API 并使用此方法来签署您的请求:https://support.loadimpact.com/4.0/test-scripting/examples/#aws-signature-v4-authentication