'Items doesn't save correctly in dynamo db through the lambda function

In my react native application which has an AWS amplify backend I use a post confirmation lambda function to save the cognito users in my dynamo db data store. My post confirmation lambda function runs fine and I can see the newly created user in my dynamo db but I can't query that user inside my app and also I cannot see the user in admin UI interface. But after about several hours I can query that user and also see the user through admin UI. How to fix this ?

  /**
 * @type {import('@types/aws-lambda').APIGatewayProxyHandler}
 */

const aws = require("aws-sdk");
const ddb = new aws.DynamoDB();

const tableName = process.env.USERTABLE;

exports.handler = async (event) => {
  // insert code to be executed by your lambda trigger
  
  if(!event?.request?.userAttributes?.sub){
    console.log("no sub provided")
    return;
  }
  
  const now = new Date();
  const timestamp = now.getTime();

  const userItem = {

    __typename: { S: 'User' },
    _lastChangedAt: { N: timestamp.toString() },
    _version: { N: "1" },
    updatedAt: { S: now.toISOString() },
    createdAt: { S: now.toISOString() },
    id: { S: event.request.userAttributes.sub },
    Name: { S: event.request.userAttributes.name },
    Email: { S: event.request.userAttributes.email },
    Phonenumb: { S: event.request.userAttributes.phone_number },
    DeliveryAddress: { S: ''}
  }
  
  const params = {
    Item: userItem,
    TableName: tableName
  }

  try {
    await ddb.putItem(params).promise();
    console.log("Success");
 } catch (e) {
   console.log(e)
 }

  
  
};

this is my lambda function

This is how my query code look

const getUser = async () => {
 
    const userData = await Auth.currentAuthenticatedUser();
    const currentUserId = userData.attributes.sub
    
    await DataStore.query(User, currentUserId).then(setUser);
    console.log("getting user in home");
    
  };


 useEffect(() => {
     
  getUser();
    
  }, []);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source