|
| 1 | +# k6-jslib-aws |
| 2 | + |
| 3 | +TypeScript library that lets k6 load test scripts interact with AWS services (S3, SQS, KMS, Lambda, Kinesis, EventBridge, SecretsManager, SSM). |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +Each AWS service has a client class in `src/internal/`. These inherit from `AWSClient`, which handles endpoint construction, request params, and k6 HTTP error classification. Every client signs requests with AWS V4 signatures via `SignatureV4` in `src/internal/signature.ts`. |
| 8 | + |
| 9 | +Public API lives in thin re-export files at `src/` root (one per service). `src/index.ts` re-exports everything. `build.mjs` uses esbuild to bundle each service into a standalone ES module under `dist/`, plus an `index.js` that contains all services. |
| 10 | + |
| 11 | +Tests are end-to-end k6 scripts in `tests/`. They run against LocalStack (Docker Compose) and use k6-chaijs for assertions. Each service has a test suite function exported from `tests/internal/{service}.js` and called from `tests/index.js`. LocalStack init scripts in `localstack/init/ready.d/` seed test fixtures. |
| 12 | + |
| 13 | +## Build and test |
| 14 | + |
| 15 | +Requires: Deno v2+, Docker, k6. |
| 16 | + |
| 17 | +```bash |
| 18 | +deno task build # bundle to dist/ |
| 19 | +deno task release # production build (minified, no console/debugger) |
| 20 | +deno task fmt # format src, tests, examples |
| 21 | +deno task lint # lint src, tests, examples |
| 22 | +deno task test # build + start LocalStack + run k6 e2e tests |
| 23 | +deno task test:ci # build + run k6 tests (expects LocalStack already running) |
| 24 | +``` |
| 25 | + |
| 26 | +`deno task test` spins up LocalStack via Docker Compose, waits 15 seconds for init scripts, then runs k6. CI uses `test:ci` with a separate compose step and a 30-second sleep. |
| 27 | + |
| 28 | +## Gotchas |
| 29 | + |
| 30 | +- No unit tests. All tests are e2e against LocalStack and require Docker running. The `deno task test` sleep (15s local, 30s CI) is a fixed wait for LocalStack readiness, not a health check. |
| 31 | +- `AWSClient.baseRequestParams` forces `responseType: "text"` to override k6's `discardResponseBodies` option. This exists so library calls always return data even when the user's k6 config discards bodies. |
| 32 | +- The library ships as ESM bundles. k6 imports from `https://jslib.k6.io/aws/{version}/{service}.js`. Publishing a new version means opening a PR on the separate `grafana/jslib.k6.io` repo with the built artifacts. |
| 33 | +- Adding a new service requires changes in five places: `src/internal/{service}.ts`, `src/{service}.ts` re-export, `src/index.ts` barrel export, `build.mjs` entry point, and `tests/internal/{service}.js` test suite registered in `tests/index.js`. |
| 34 | +- Version bumps require updating `deno.json`, running `deno update` for the lockfile, rebuilding, and replacing the old version string across README and `examples/`. |
0 commit comments