aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Same code works in nodejs but not in react-native

Open coryisbest0728 opened this issue 9 months ago • 3 comments

Checkboxes for prior research

Describe the bug

I was running DescribeLogStreamsCommand to verify if the log stream is existed in the React-Native. I got the response is undefined. But when I run the same code by node command, it worked, it could get the correct response. And then I tried to verify my account, then same issue. Got an error {"$metadata":{"attempts":1,"totalRetryDelay":0}}. It worked by node, got the correct response structure.

Regression Issue

  • [x] Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

[email protected] [email protected]

Reproduction Steps

const client = new CloudWatchLogsClient({
  credentials: {
    accessKeyId: "XXXXXXXXXXXXXXX",
    secretAccessKey: "YYYYYYYYYYYYYYYYYY",
  },
  region: "us-west-2",
  maxAttempts: 3
});

const verifyLogStream = async (aa) => {
  try {
    const response = await client.send(new DescribeLogStreamsCommand({
      logGroupName: "XXXXXX",
      logStreamNamePrefix: `YYYY_${ aa }_Logs`,
    }));
    console.log('DescribeLogStreamsCommand response:', response.logStreams);
    return true;
  } catch (error) {
    console.error('Error describing log streams:', error);
    return false;
  }
};

verifyLogStream(13);


export const verifyAcount = async (region) => {
  const stsClient = new STSClient({
    credentials: {
      accessKeyId: "XXXXXXXXXX",
      secretAccessKey: "YYYYYYYYYYYYYYYYY",
      accountId: "ZZZZZZZZZZZZ"
    },
    region: region,
    maxAttempts: 3
  });
  try {
    const whoAmI = await stsClient.send(new GetCallerIdentityCommand({}));
    console.log(region, ': Caller identity:', whoAmI);
  } catch (error) {
    console.error(region, ": Caller identity error:", JSON.stringify(error));
  }
}

verifyAcount("us-west-2");`

Observed Behavior

Under the React-Native: For verifyLogStream, it got DescribeLogStreamsCommand response: undefined For verifyAcount, it got an Error us-west-2 : Caller identity error: {"$metadata":{"attempts":1,"totalRetryDelay":0}}

Expected Behavior

Under the React-Native: For verifyLogStream, it should get the correct response structure: [ { arn: 'arn:aws:logs:us-west-2:XXXXXXXXXXXX:log-group:rotender-native:log-stream:YYYY_13_Logs', creationTime: 1716831570343, firstEventTimestamp: 1716831570449, lastEventTimestamp: 1739839755726, lastIngestionTime: 1739839755777, logStreamName: 'YYYY_13_Logs', storedBytes: 0, uploadSequenceToken: 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' } ]

For verifyAcount, it should get the correct response structure { '$metadata': { httpStatusCode: 200, requestId: '7277b8ee-9488-476f-93ee-89e1f17b534b', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, UserId: 'XXXXXXXXXXXXXXXX', Account: 'XXXXXXXXXXXXXXX', Arn: 'arn:aws:iam::XXXXXXXXXXX:user/YYYYYYYYY' }

Possible Solution

No response

Additional Information/Context

No response

coryisbest0728 avatar Apr 15 '25 19:04 coryisbest0728

Hey @coryisbest0728 ,

If you use tree shaking to reduce bundle size, using non-modular interface will increase the bundle size as compared to using modular interface.

If you are consuming modular AWS SDK for JavaScript on react-native environments, you will need to add and import following polyfills in your react-native application:

react-native-get-random-values react-native-url-polyfill web-streams-polyfill import "react-native-get-random-values"; import "react-native-url-polyfill/auto"; import "web-streams-polyfill/dist/polyfill";

import { DynamoDB } from "@aws-sdk/client-dynamodb"; Specifically Metro bundler used by react-native, enable Package Exports Support:

https://metrobundler.dev/docs/package-exports/ https://reactnative.dev/blog/2023/06/21/package-exports-support

Could you please confirm that you added them?

Thanks!

zshzbh avatar Apr 17 '25 01:04 zshzbh

If you use tree shaking to reduce bundle size, using non-modular interface will increase the bundle size as compared to using modular interface.

Hi @zshzbh. Yes, I did. I followed https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started-react-native.html#getting-started-react-write-native-code. It‘s still got the error.

coryisbest0728 avatar Apr 17 '25 06:04 coryisbest0728

Thanks for the response. I will try to reproduce it and get back to you.

zshzbh avatar May 01 '25 19:05 zshzbh

Is this still ongoing issue? I wasn't able to reproduce this on my end. Based on what you described, it sounds like configuration/setup issue rather than SDK or env specific. Feel free to try to spin up this test repo which supports different environments and see if you see the same behavior: https://github.com/aws-samples/aws-sdk-js-tests

If issue persists, please share the response or logs for further support.

aBurmeseDev avatar Aug 06 '25 23:08 aBurmeseDev

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Aug 17 '25 00:08 github-actions[bot]

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.

github-actions[bot] avatar Sep 05 '25 00:09 github-actions[bot]