aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.39k stars 2.11k forks source link

How we can get callback from AWSKinesis after send record like AWSPinpoint? #11991

Closed auiii24 closed 8 months ago

auiii24 commented 9 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Analytics

Environment information

``` System: OS: macOS 13.4.1 CPU: (8) arm64 Apple M1 Memory: 67.52 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.19.4 - ~/.nvm/versions/node/v16.20.1/bin/npm Watchman: 2023.07.17.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 116.0.5845.179 Safari: 16.5.1 npmPackages: @aws-amplify/analytics: ^6.5.2 => 5.1.10 @babel/core: ^7.12.9 => 7.16.7 @babel/runtime: ^7.12.5 => 7.16.7 @bugsnag/plugin-react-navigation: ^7.14.1 => 7.14.1 @bugsnag/react-native: ^7.20.2 => 7.14.2 @bugsnag/source-maps: ^2.3.0 => 2.3.0 @miblanchard/react-native-slider: 1.5.0 => 1.5.0 @nartc/react-native-barcode-mask: ^1.2.0 => 1.2.0 @react-hook/debounce: ^4.0.0 => 4.0.0 @react-native-async-storage/async-storage: ^1.19.2 => 1.15.14 @react-native-clipboard/clipboard: ^1.9.0 => 1.9.0 @react-native-community/eslint-config: ^2.0.0 => 2.0.0 @react-native-community/geolocation: ^2.0.2 => 2.0.2 @react-native-community/image-editor: ^2.3.0 => 2.3.0 @react-native-community/masked-view: ^0.1.10 => 0.1.11 @react-native-community/netinfo: ^6.2.1 => 6.2.1 @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3) @react-native/normalize-color: ^2.0.0 => 1.0.0 @react-navigation/bottom-tabs: ^5.11.2 => 5.11.15 @react-navigation/material-top-tabs: ^5.3.10 => 5.3.19 @react-navigation/native: ^5.8.10 => 5.9.8 (3.8.4) @react-navigation/stack: ^5.12.8 => 5.14.9 @testing-library/react-native: ^7.1.0 => 7.2.0 @types/color: ^3.0.1 => 3.0.2 @types/i18n-js: ^3.8.0 => 3.8.2 @types/jest: ^25.2.3 => 25.2.3 @types/lodash: ^4.14.168 => 4.14.178 @types/numeral: ^2.0.1 => 2.0.2 @types/react-native: ^0.63.2 => 0.63.59 @types/react-native-indicators: ^0.16.0 => 0.16.2 @types/react-native-keep-awake: ^2.0.3 => 2.0.3 @types/react-native-push-notification: ^7.3.2 => 7.3.3 @types/react-native-snap-carousel: ^3.8.2 => 3.8.5 @types/react-native-vector-icons: ^6.4.6 => 6.4.10 @types/react-redux: ^7.1.15 => 7.1.21 @types/react-test-renderer: ^16.9.2 => 16.9.5 @types/redux-actions: ^2.6.1 => 2.6.2 @types/styled-components: ^5.1.7 => 5.1.19 @types/styled-system: ^5.1.10 => 5.1.14 @types/uuid: ^8.3.1 => 8.3.4 @zxing/library: ^0.18.6 => 0.18.6 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^5.2.14 => 5.2.4 aws-amplify: ^5.3.10 => 4.3.12 axios: ^0.21.1 => 0.21.4 babel-jest: ^26.6.3 => 26.6.3 babel-plugin-module-resolver: ^4.1.0 => 4.1.0 babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4 color: ^3.1.3 => 3.2.1 crypto-js: 3.3.0 => 3.3.0 (4.1.1) dayjs: ^1.10.3 => 1.10.7 eslint: ^7.32.0 => 7.14.0 eslint-plugin-react-hooks: ^3.0.0 => 3.0.0 (4.3.0) fbjs: ^3.0.0 => 3.0.2 (0.8.18) fp-ts: ^2.11.5 => 2.11.7 glob: ^7.1.6 => 7.2.0 hermes-inspector-msggen: 1.0.0 i18n-js: ^3.8.0 => 3.8.0 io-ts: ^2.2.16 => 2.2.16 jail-monkey: ^2.4.0 => 2.6.0 jest: ^26.6.3 => 26.6.3 jest-transform-stub: ^2.0.0 => 2.0.0 jetifier: ^2.0.0 => 2.0.0 (1.6.8) json-concat: 0.0.1 => 0.0.1 json-server: ^0.16.3 => 0.16.3 lodash: ^4.17.20 => 4.17.21 lottie-react-native: ^5.1.3 => 4.1.3 lowdb: ^1.0.0 => 1.0.0 metro-react-native-babel-preset: 0.72.4 => 0.66.2 numeral: ^2.0.6 => 2.0.6 patch-package: ^8.0.0 => 6.4.7 quagga: ^0.12.1 => 0.12.1 react: 18.1.0 => 17.0.2 react-native: 0.70.12 => 0.66.4 react-native-android-open-settings: ^1.3.0 => 1.3.0 react-native-app-signature-helper: ^1.4.0 => 1.4.0 react-native-biometrics: ^2.1.4 => 2.1.4 react-native-camera: ^4.2.1 => 4.2.1 react-native-confirmation-code-field: ^6.5.1 => 6.7.0 react-native-device-info: ^8.0.2 => 8.4.8 react-native-drag-sort: ^2.4.2 => 2.4.4 react-native-event-listeners: ^1.0.7 => 1.0.7 react-native-exit-app: ^1.1.0 => 1.1.0 react-native-fast-image: ^8.5.11 => 8.5.11 react-native-fast-toast: ^2.2.0 => 2.3.1 react-native-flipper: ^0.163.0 => 0.96.1 react-native-fs: ^2.18.0 => 2.18.0 react-native-gesture-handler: ^1.9.0 => 1.10.3 react-native-get-random-values: ^1.9.0 => 1.7.2 react-native-image-picker: ^5.6.1 => 3.8.1 react-native-image-resizer: ^1.4.5 => 1.4.5 react-native-keep-awake: ^4.0.0 => 4.0.0 react-native-keychain: ^7.0.0 => 7.0.0 react-native-keys: ^0.0.12 => 0.0.12 react-native-linear-gradient: ^2.5.6 => 2.5.6 react-native-local-barcode-recognizer: ^0.0.2 => 0.0.2 react-native-localize: ^2.0.1 => 2.1.7 react-native-lottie-splash-screen: ^1.1.2 => 0.1.14 react-native-maps: ^1.3.2 => 1.3.2 react-native-mmkv: ^2.5.1 => 2.5.1 react-native-permissions: ^3.0.3 => 3.2.0 react-native-pull-to-refresh-custom: ^1.0.3 => 1.0.3 react-native-push-notification: ^8.1.0 => 8.1.1 react-native-qrcode-svg: ^6.1.1 => undefined (6.1.2, ) react-native-reanimated: ^2.17.0 => 2.8.0 react-native-render-html: ^6.3.4 => 6.3.4 react-native-safe-area-context: ^3.1.9 => 3.3.2 react-native-screens: ^2.16.1 => 2.18.1 react-native-select-contact: ^1.6.3 => 1.6.3 react-native-share: 7.8.0 => 7.8.0 react-native-sms-retriever: ^1.1.1 => 1.1.1 react-native-snap-carousel: ^3.9.1 => 3.9.1 react-native-svg: ^12.1.1 => 12.1.1 react-native-tab-view: ^2.15.2 => 2.16.0 react-native-text-input-mask: ^3.1.4 => 3.1.4 react-native-user-inactivity: ^1.2.0 => 1.2.0 react-native-vector-icons: ^7.1.0 => 7.1.0 react-native-view-shot: ^3.1.2 => 3.1.2 react-native-vision-camera: ^2.15.4 => 2.15.4 react-navigation: ^4.4.3 => 4.4.4 react-navigation-stack: ^2.10.2 => 2.10.4 react-redux: ^7.2.2 => 7.2.6 react-test-renderer: 18.1.0 => 17.0.2 redux: ^4.0.5 => 4.1.2 redux-actions: ^2.6.5 => 2.6.5 redux-flipper: ^1.4.2 => 1.4.2 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () redux-saga: ^1.1.3 => 1.1.3 redux-saga/effects: undefined () rn-qr-generator: ^1.1.6 => 1.2.0 styled-components: ^5.2.1 => 5.3.3 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () styled-system: ^5.1.5 => 5.1.5 typesafe-actions: ^5.1.0 => 5.1.0 typescript: ^3.8.3 => 3.9.10 use-immer: ^0.9.0 => 0.9.0 usetimeout-react-hook: ^0.1.2 => 0.1.2 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2) vision-camera-base64: ^1.1.0 => 1.1.0 vision-camera-code-scanner: ^0.2.0 => 0.2.0 vision-camera-face-detector: ^0.1.8 => 0.1.8 npmGlobalPackages: corepack: 0.17.0 npm: 8.19.4 ```

Describe the bug

We are working on @aws-amplify/analytics with the AWSKinesis provider, and I would like to know how we can handle callback after analytic sends record success or failure. We need to know the process before entering the next step, such as sending log security to AWS after that, we will process the new step to show some UI to the user.

Expected behavior

We would like to handle callback after sending records to analytic by AWSKinesis.

Reproduction steps

N/A

Code Snippet

Analytics.addPluggable(new AWSKinesisFirehoseProvider())
Analytics.configure({
  AWSKinesisFirehose: {
    region: 'ap-southeast-1',
  },
})

return new Promise((resolve, reject) => {
    Analytics.record(
              {
                streamName: <streamName>,
                immediate: true,
                data: {
                  partnerCode: <partnerCode>,
                  payload: <payload>,
                },
              },
              'AWSKinesisFirehose'
            ).then(() => resolve())
              .catch(e => reject(e))
})
cwomack commented 9 months ago

Hello, @auiii24 and thanks for opening this issue. Are you looking to confirm if that code snippet you provided will work as a way to get callback confirmations/errors from Kinesis? And are you only looking to have some type of customer logic implemented depending on success/error (rather than just the resolve/reject in the existing promise)?

auiii24 commented 9 months ago

Hello, @cwomack

Are you looking to confirm if that code snippet you provided will work as a way to get callback confirmations/errors from Kinesis?

And are you only looking to have some type of customer logic implemented depending on success/error (rather than just the resolve/reject in the existing promise)?

nadetastic commented 8 months ago

Related #12221

cwomack commented 8 months ago

@auiii24, we've created a docs issue to provide clarity about the synchronous nature of Analytics.record() API that's the subject both this issue and the related #12221.

While the documentation does not specify that you should await this function, we consider the Analytics.record() API to be one that should be synchronous and not "block" our customer's applications. Since you're on v5.X at this time, please follow the recommendations within the documentation (which we'll improve) and treat the function as synchronous. It should work as a "fire and forget" model.

With the docs issue opened to track this, I'll close this issue. Thank you for creating this issue to help us make a needed improvement in our documentation!