Skip to content

DataStore doesn't trigger update on item updated in a lambda trigger #14247

Open
@rossicler-hostalky

Description

@rossicler-hostalky

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api, function

Backend

Amplify CLI

Environment information

# Put output below this line

System:
    OS: macOS 15.3.1
    CPU: (8) arm64 Apple M1
    Memory: 111.84 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.4/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 18.3
  npmPackages:
    @aws-amplify/datastore-storage-adapter: 2.0.40 => 2.0.40 
    @aws-amplify/react-native: ^1.1.7 => 1.1.7 
    @azure/core-asynciterator-polyfill: ^1.0.2 => 1.0.2 
    @babel/core: ^7.25.2 => 7.26.9 
    @expo/vector-icons: ^14.0.2 => 14.0.4 
    @react-native-async-storage/async-storage: 1.23.1 => 1.23.1 
    @react-native-community/netinfo: 11.4.1 => 11.4.1 
    @react-navigation/bottom-tabs: ^7.2.0 => 7.2.0 
    @react-navigation/native: ^7.0.14 => 7.0.14 
    @types/jest: ^29.5.12 => 29.5.14 
    @types/lodash: ^4.17.15 => 4.17.15 
    @types/react: ~18.3.12 => 18.3.18 
    @types/react-test-renderer: ^18.3.0 => 18.3.1 
    aws-amplify: ^6.12.3 => 6.13.1 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/adapter-core/internals:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/internals:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    expo: ~52.0.28 => 52.0.36 
    expo-blur: ~14.0.3 => 14.0.3 
    expo-constants: ~17.0.5 => 17.0.7 
    expo-font: ~13.0.3 => 13.0.4 
    expo-haptics: ~14.0.1 => 14.0.1 
    expo-linking: ~7.0.5 => 7.0.5 
    expo-router: ~4.0.17 => 4.0.17 
    expo-splash-screen: ~0.29.21 => 0.29.22 
    expo-sqlite: ~15.1.2 => 15.1.2 
    expo-status-bar: ~2.0.1 => 2.0.1 
    expo-symbols: ~0.2.1 => 0.2.2 
    expo-system-ui: ~4.0.7 => 4.0.8 
    expo-web-browser: ~14.0.2 => 14.0.2 
    jest: ^29.2.1 => 29.7.0 
    jest-expo: ~52.0.3 => 52.0.4 
    lodash: ^4.17.21 => 4.17.21 
    nativewind: ^4.1.23 => 4.1.23 
    react: 18.3.1 => 18.3.1 
    react-dom: 18.3.1 => 18.3.1 
    react-native: 0.76.6 => 0.76.6 
    react-native-gesture-handler: ~2.20.2 => 2.20.2 
    react-native-get-random-values: ~1.11.0 => 1.11.0 
    react-native-reanimated: ~3.16.1 => 3.16.7 
    react-native-safe-area-context: 4.12.0 => 4.12.0 
    react-native-screens: ~4.4.0 => 4.4.0 
    react-native-sqlite-storage: ^6.0.1 => 6.0.1 
    react-native-web: ~0.19.13 => 0.19.13 
    react-native-webview: 13.12.5 => 13.12.5 
    react-test-renderer: 18.3.1 => 18.3.1 
    tailwindcss: ^3.4.17 => 3.4.17 
    typescript: ^5.3.3 => 5.7.3 
  npmGlobalPackages:
    @aws-amplify/cli: 12.14.1
    atlas-app-services-cli: 1.6.1
    corepack: 0.28.0
    eas-cli: 14.4.1
    ios-deploy: 1.12.2
    npm: 10.7.0
    pod-install: 0.3.4
    prettier: 3.3.3
    yarn: 1.22.22

Describe the bug

I have a DynamoDB trigger that updates an item, but DataStore is not properly triggering the update on the item.

I'm updating an attribute value along with _lastChangedAt, updatedAt and _version, and even tho I have n observer setup, it doesn't trigger. This is what I have for the observer:

const subscription = DataStore.observe<T>(
  modelConstructor,
  identifier
).subscribe((msg) => {
  console.log("Received a message", msg);
});

If I restart the app, after a second or so DataStore updates correctly.

Follow-up question: Is manually updating these DataStore metadata (_lastChangedAt, etc) recommended? If not, what is the right way?

Expected behavior

Print the log "Received a message " whenever the trigger updates the item on DynamoDB.

Reproduction steps

  1. Initiate the observer on the client
  2. Run a DynamoDB trigger or function that updates an item on DynamoDB.
  3. Expect observer to get the updated item.

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DataStoreRelated to DataStore categorypending-maintainer-responseIssue is pending a response from the Amplify team.pending-triageIssue is pending triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions