Search code examples
aws-sdk-js

Should aws-sdk (for Javascript) work on deno?


I'm trying the following:

import { config } from "https://deno.land/x/dotenv/mod.ts";
import { S3Client, ListObjectsV2Command } from 'https://cdn.skypack.dev/@aws-sdk/client-s3'

const client = new S3Client({
    region: 'us-east-1',
    credentials: {
        AccessKeyId: config.AWS_ACCESS_KEY_ID,
        SecretAccessKey: config.AWS_SECRET_ACCESS_KEY,
    }
})

async function list() {
s3/interfaces/listobjectsv2commandinput.html
    const objs = await client.send(new ListObjectsV2Command({
        Bucket: 'my-bucket'
    }))

    console.log(objs)
}

list()

and receiving the following error:

error: Uncaught (in promise) TypeError: Cannot read property 'byteLength' of undefined
    return data.byteLength === 0;
                ^
    at isEmptyData (https://cdn.skypack.dev/-/@aws-crypto/[email protected]/dist=es2020,mode=imports/optimized/@aws-crypto/sha256-js.js:273:17)
    at Sha2563.update (https://cdn.skypack.dev/-/@aws-crypto/[email protected]/dist=es2020,mode=imports/optimized/@aws-crypto/sha256-js.js:227:11)
    at Sha2563.update (https://cdn.skypack.dev/-/@aws-crypto/[email protected]/dist=es2020,mode=imports/optimized/@aws-crypto/sha256-browser.js:223:17)
    at hmac (https://cdn.skypack.dev/-/@aws-sdk/[email protected]/dist=es2020,mode=imports/optimized/@aws-sdk/signature-v4.js:113:8)
    at https://cdn.skypack.dev/-/@aws-sdk/[email protected]/dist=es2020,mode=imports/optimized/@aws-sdk/signature-v4.js:56:22
    at step (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/optimized/tslib.js:221:23)
    at Object.next (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/optimized/tslib.js:168:18)
    at https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/optimized/tslib.js:154:71
    at new Promise (<anonymous>)
    at __awaiter2 (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/optimized/tslib.js:136:14)

I'm just wondering whether someone with more experience might recognize this as something I've not done properly or already knows this is an issue with running on Deno.

Thank you


Solution

  • Simply camel casing those props worked:

    const client = new S3Client({
        region: 'us-east-1',
        credentials: {
            accessKeyId: config.AWS_ACCESS_KEY_ID,
            secretAccessKey: config.AWS_SECRET_ACCESS_KEY,
        }
    })