aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.06k stars 573 forks source link

@smithy/hash-blob-browser - blobHasher - export error in es6 in browser - s3 client #5969

Closed suryavaddiraju closed 6 months ago

suryavaddiraju commented 6 months ago

Checkboxes for prior research

Describe the bug

I am using js deliver cdn for importing aws sdk in my project while in this s3 client the chrome browser is throwing an error that

Uncaught` SyntaxError: The requested module '/npm/@smithy/hash-blob-browser@2.0.13/+esm' does not provide an export named 'blobHasher'

while importing the s3 client using this module

import awsSdkclientS3 from 'https://cdn.jsdelivr.net/npm/@aws-sdk/client-s3@3.549.0/+esm';
const { S3Client, GetObjectCommand } = awsSdkclientS3;

SDK version number

@aws-sdk/client-s3@3.549.0

Which JavaScript Runtime is this issue in?

Browser

Details of the browser/Node.js/ReactNative version

Chrome Version 123.0.6312.106 (Official Build) (64-bit) on Windows 10

Reproduction Steps

index.html

<!DOCTYPE html>
<html lang="en-IN">
    <head>
        <meta charset="UTF-8">
        <meta name=viewport content="width=device-width, initial-scale=1">
        <title>Home</title>
        <script type="module" src="index.js"></script>
    </head>
    <body>
        hello world
    </body>
</html>

index.js

import awsSdkclientS3 from 'https://cdn.jsdelivr.net/npm/@aws-sdk/client-s3@3.449.0/+esm';
import awsSdkclientSts from 'https://cdn.jsdelivr.net/npm/@aws-sdk/client-sts@3.549.0/+esm';
import { v4 as uuidv4 } from 'https://cdn.jsdelivr.net/npm/uuid@9.0.1/+esm'
const { S3Client, GetObjectCommand } = awsSdkclientS3;
const { STSClient, AssumeRoleWithWebIdentityCommand } = awsSdkclientSts;
const jwt_token = "";
const aws_config = await generate_aws_token(jwt_token);
async function generate_aws_token(jwt_token){
  const aws_sts_client = new STSClient({});
  const input = {
    RoleArn: "arn:aws:iam::1234567890:role/some_role_name",
    RoleSessionName: uuidv4(),
    WebIdentityToken: jwt_token
  };
  const command = new AssumeRoleWithWebIdentityCommand(input);
  const response = await aws_sts_client.send(command);
  const config = {
    region:'us-east-1',
    credentials:{
        accessKeyId:response.Credentials.AccessKeyId,
        secretAccessKey:response.Credentials.SecretAccessKey,
        sessionToken:response.Credentials.SessionToken
    }
  }
  return config;
};
async function s3_get_obj(bucket, key){
  const aws_s3_client = new S3Client(aws_config);
  const input = {
      Bucket: bucket,
      Key:key
  };
  const command = new GetObjectCommand(input);
  const response = await aws_s3_client.send(command);
  const data = response.Body;
  return data;
};
const bucket = "bucket_name";
const key = "some/object_key.txt";
const data = await s3_get_obj(bucket, key);
console.log(data);

Observed Behavior

Uncaught SyntaxError: The requested module '/npm/@smithy/hash-blob-browser@2.0.13/+esm' does not provide an export named 'blobHasher' (at jsdelivr-header.js:7:1)

Expected Behavior

Need to print s3 get object data of the body

Possible Solution

issue at the @smithy/hash-blob-browser package where it needs to be modified for es6 export or s3-client blobHasher import need to be correctly done

Additional Information/Context

NA

kuhe commented 6 months ago

Viewing the contents of https://cdn.jsdelivr.net/npm/@smithy/hash-blob-browser@2.0.13/+esm, it seems that they failed to build the package.

The artifacts that we publish are present at https://www.npmjs.com/package/@smithy/hash-blob-browser?activeTab=code.

This seems to be a problem with jsdelivr's build process, you may want to open an issue with them instead, since the page does not provide any clues as to why it is failing.

suryavaddiraju commented 6 months ago

Is there any alternative for importing @aws-sdk/client-SERVICE through any other cdn for browser ES6, what about this https://sdk.amazonaws.com where this serves only v2 or does it support v3. do aws distribute the prebuilt webpacks as recommended in https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/webpack.html, As I could not get the reference of using aws-sdk v3 in html through cdn link of sdk.amazon.com

Request: In aws documentation They are directly making import statements in javascript without referencing how they got the module in html importmap reference., We need the @aws-sdk/client-SERVICENAME@>3.0.0 es6 offical cdn from aws sdk team for use in browser environment as like how aws sdk javascript v2 was distributed

Raised Issue with jsdeliver, you can access the issue from the below link https://github.com/jsdelivr/jsdelivr/issues/18560#issue-2229069985

RanVaknin commented 6 months ago

Hi @suryavaddiraju ,

I discussed this with the JS SDK team and there is no plan at the moment to distribute the SDK via a CDN. Right now <1% of all the SDK consumers of v2 SDK use CDN therefore there is no plan to support it going forward.

if you wish, you can host your own SDK CDN by uploading the SDK artifacts to S3 and serving it from your own Cloudfront distribution.

Since the original action item for this issue was for jsdelivr and not the SDK team, I'm going to go ahead and close this ticket. Thanks again for taking the time and reaching out.

If you need anything else please feel free to open another issue.

All the best, Ran~

github-actions[bot] commented 5 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.