无法将AWS开发工具包与Browserify捆绑在一起以在K6中使用SDK库

时间:2019-01-18 09:05:24

标签: javascript browserify 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)

对于任何帮助都将非常有帮助。

1 个答案:

答案 0 :(得分:2)

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