Same code works in nodejs but not in react-native
Checkboxes for prior research
- [x] I've gone through Developer Guide and API reference
- [x] I've checked AWS Forums and StackOverflow.
- [x] I've searched for previous similar issues and didn't find any solution.
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
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!
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.
Thanks for the response. I will try to reproduce it and get back to you.
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.
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.
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.