grafana / k6-jslib-aws

Javascript Library allowing to interact with AWS resources from k6 scripts
Apache License 2.0
18 stars 28 forks source link

Fix endpoint argument in `signature.sign` examples #67

Open oleiade opened 9 months ago

oleiade commented 9 months ago

We recently changed how the library handles endpoints to support third-party S3-compatible providers as per #21, #57, etc.

We have recently noticed that the example didn't reflect the usage of the new endpoint argument of the signature.sign, and signature.presign methods. We should update those, as well as the documentation to reflect it 👍🏻

bd-g commented 7 months ago

I'm trying to use these methods and am having difficulty parsing the new endpoint syntax - any help or intermediate links while you work on the docs would be much appreciated!

oleiade commented 7 months ago

Hey @bd-g thanks for pointing that out, we're gonna improve the documentation accordingly 🤝

Although it's not clearly documented, the Endpoint type is actually exported by the signature module, thus, in the meantime, something along the lines of the following should allow you to move forward:

import { Endpoint, SignatureV4 } from 'https://jslib.k6.io/aws/0.11.0/signature.js';  // or aws.js

// instantiate a signature object
const signer = new SignatureV4(...)

// and pass the endpoint here
signer.sign({
    method: 'POST',
    endpoint: new Endpoint('https://s3.us-west-1.amazonaws.com'),
    path: '/',
    headers: {
        host: 's3.us-west-1.amazonaws.com',
})

For more details, here's the Endpoint type definition: https://github.com/grafana/k6-jslib-aws/blob/main/src/internal/endpoint.ts

Let me know if that unblocked you 🙇🏻

bd-g commented 7 months ago

I'll have to go and check, but that is similar to what I tried to do just from reading the code. I was getting errors with the host name being undefined, somehow my endpoint url wasn't being parsed properly so I'll go back and post my exact example.

oleiade commented 2 months ago

The documentation will be updated to cater to this change in: https://github.com/grafana/k6-docs/pull/1585