In Typescript, how do we differentiate between an object and a string?

As I develop an Infrastructure-as-Code for a Step Functions Machine, one of the states is a 'Task' type that executes a DynamoUpdateItem on a DynamoDB table.

The code snippet is as follows:

    const updateDDB = new tasks.DynamoUpdateItem(this, 'Update item into DynamoDB', {
      key: { ['Task'] : tasks.DynamoAttributeValue.fromString('Processing') },
      table: table,
      updateExpression: 'SET LastRun = :label',
      expressionAttributeValues: {
        ':label.$': DynamoAttributeValue.fromString(JsonPath.stringAt('$$.Execution.StartTime')), 
      },
      resultPath: JsonPath.DISCARD,
    });

Despite my efforts, I keep encountering an error related to schema validation. The error message indicates that

"The value for the field ':label.$' must be a STRING that contains a JSONPath but was an OBJECT at /States/Update item into DynamoDB/Parameters'"

It's puzzling why it's not recognizing it as a string!

I have attempted variations like [':label.$'] and adding a .toString() function after the JsonPath method

      expressionAttributeValues: {
        ':label.$': (DynamoAttributeValue.fromString(JsonPath.stringAt('$$.Execution.StartTime').toString())), 

      },

However, none of these solutions seem to resolve the issue. The same error persists, claiming it's not a string.

Even using JSON.stringify() doesn't provide a solution because expressionAttributeValues expects a key-value pair matching a DynamoAttributeValue.

Answer №1

Summary: Remove the .$ suffix from

':label.$': DynamoAttributeValue(...)
in the definition of the expression attribute value. The key should only be ':label'.


@TobiasS points out in the comments that the issue lies in the syntax of your State Machine task. Adding .$ after :label.$ instructs AWS to look for a JSONPath string that shows the path to a value, which is not valid syntax for the State Machine field. What you need here is a key-value pair, as shown correctly in the CDK documentation's example.

❌ How your CDK code translates:

{
    "ExpressionAttributeValues": {
      ":label.$": { "S.$": "$$.Execution.StartTime" }
    },
}

✅ AWS expects the proper State Machine definition to be:

{
    "ExpressionAttributeValues": {
      ":label": { "S.$": "$$.Execution.StartTime" }
    },
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular translation for datetimepicker

Looking to implement a datepicker that allows selecting the hours, so I decided to add an Angular component. After searching, I found the perfect component: https://www.npmjs.com/package/angular-bootstrap-datetimepicker Although this component is original ...

Subclass callback with parameters

Having some trouble with one of my TypeScript functions and I'm hoping it's not a silly question. I believe what I'm attempting should work in theory. Here's a simplified version of my issue to demonstrate where the problem lies (the o ...

Invoke a custom AWS CodeBuild project in CodePipeline using a variety of parameters

Imagine having a CodePipeline with 2 stages structured like this: new codepipeline.Pipeline(this, name + "Pipeline", { pipelineName: this.projectName + "-" + name, crossAccountKeys: false, stages: [{ stageName: &apos ...

point to a member of a JSON (Javascript) data structure

Can you show me how to access an element from a JSON object in Javascript? For example: alert(homes.Agents[1].name); <script> var homes = [ { "Agents" : { "name" : "Bob Barker", "name" : "Mona Mayflower" }, "Listi ...

I'm looking for a tag cloud widget that can handle JSON objects. Any suggestions?

Looking for recommendations on widgets that can generate a tag cloud using JSON objects. I have an array of JSON objects and would like to know the most effective method for creating a tag cloud with them. Thanks in advance! =) ...

Check to see if any of the statuses in the JSON file are either marked as failed or

My goal is to analyze the JSON output of CircleCI jobs and determine if all jobs are in a successful state. If they are, then I want to proceed with a specific action; otherwise, I will continue waiting. In my CircleCI job, I used the following shell comm ...

Tips for enhancing express.Request using tsserver and JSDoc

Recently, I have been utilizing tsserver with JSDoc in vim while working on a JavaScript project. Unfortunately, I've encountered an issue that needs resolving: /** @type {import('express').Handler} */ function requireUser(req, res, next) { ...

Angular Typescript Filter failing to connect with service injection

I am having trouble accessing the Constant app within a filter in Angular TypeScript. How can I successfully access a service inside a filter? Module App.Filter { import Shared = Core.Shared; export class MilestoneStatusFilter123 { static $inject = ...

Clicking on the toggle button will reveal a different ID each time, extracted from JSON links

I have a JSON file containing information about movies currently playing in theaters. I want to display specific details for each movie when its title is clicked, but my code isn't functioning properly. Currently, all the movies' information is d ...

Issue encountered when attempting to import Esri types: "Unable to utilize 'new' with an expression that does not have a call or construct signature."

There seems to be a simple solution that I am overlooking. I am currently working on a class that utilizes the Esri ArcGIS API, but I encounter a TypeScript error when importing type definitions from the arcgis-js-api's d.ts file. The error states "Ca ...

What is the process for executing a node script within a TypeScript React project?

In my React project, I have incorporated an API for communication. Within the project, there is a module that handles the api access in an abstract manner. This module contains methods like addFoo and getFoos. I need to use this module from a script that ...

Creating React Context Providers with Value props using Typescript

I'd prefer to sidestep the challenge of nesting numerous providers around my app component, leading to a hierarchy of provider components that resembles a sideways mountain. I aim to utilize composition for combining those providers. Typically, my pro ...

Showing Nested Numerical Objects Post RequestBeing Made

Currently, I am facing an issue with accessing nested objects referred to by numbers. After making a service call to retrieve a JSON object, I mapped each field to another object which will be used for displaying the fields in HTML. The problem arises whe ...

Are the DataTables rows functioning properly, or have they not been initialized?

After setting up my website with DataTables and retrieving data through its ajax service from a Java servlet backend, everything seemed to be working fine with the DOM. However, despite having all the data in place, I encountered issues with some of the fe ...

What is the process for extracting both the pose and 4x4 matrix from the log file and then storing them in a JSON file?

I have a sizeable log file that contains poses and 4x4 matrices. My goal is to split each matrix into a 3x3 rotation matrix and a 3x1 translation matrix. Each matrix is specified by a pose number (the first number on top of each matrix) and save them into ...

The expiration date is not considered in JWT authentication using passport-jwt

I have been working on implementing an authentication system using JWT token in Express, utilizing passport-jwt and jsonwebtoken. Everything is functioning correctly at the moment, however, I am facing an issue where the token remains valid even after its ...

What is the best way to transfer multiple images in array format from an MVC view to a controller using Ajax?

I've been facing a challenge with sending multiple images through Ajax without using form data, as my data is in an array format. My jQuery function looks like this: $("body").on("click", "#btnSave", function () { //Loop through the Tab ...

The overload functionality in Typescript interfaces is not functioning as intended

Here is a snippet of code I'm working with: class A { } class B { } class C { } interface Builder { build(paramOne: A): string; build(paramOne: B, paramTwo: C): number; } class Test implements Builder { build(a: A) { return &apo ...

Storing and fetching messages in languages other than English using Laravel 4

Developing can be a challenge when it comes to dealing with time and different languages. Currently, I have a 'message' field that is encrypted and saved in the database by sending a JSON Object via POST request. { "message": "Hello World" ...

Reacting to the dynamic removal of spaces

Is there a way to dynamically remove the space between removed chips and older chips in Material-UI when deleting one of them? <div className="row contactsContainer"> {contacts.map((contac ...