Skip to content

DynamoDB Service Integration, UpdateItem with Numeric parameter problem

0

Situation:

  • DynamoDB Service Integration
  • UpdateItem Task
  • Table Column is numeric
  • Parameter value is numeric
  • Parameter is passed in using the numeric output of the previous state

Fails with Error Message:
An error occurred while executing the state 'TaskName' (entered at the event id #1). The Parameters '{"TableName":"SampleTable","Key":{"HashKey":{"S":"TestKey"}},"UpdateExpression":"SET NumericColumn=:numericValue","ExpressionAttributeValues":{":numericValue":{"N":100}}}' could not be used to start the Task: The value for the field 'N' must be a STRING

Notes

  • it has substituted 100 for the :numericValue expression attribute value.
  • if I hard-code in "100" for the :numericValue expression attribute value, I do not receive an error.

Questions
My workaround is to update the output from my previous step lambda function to return a string rather than numeric result. Is there a better way for me to accomplish this?

Sample Input

{
    "number": 100
}

Sample Task

{
    "Type": "Task",
    "Resource": "arn:aws:states:::dynamodb:updateItem",
    "Parameters": {
        "TableName": "SampleTable",
        "Key": {
            "HashKey": {
                "S.$": "$.hashKey"
            }
        },
        "UpdateExpression": "set NumericColumn = :numericValue",
        "ExpressionAttributeValues": {
            ":numericValue": {
                "N.$": "$.number"
            }
        }
    },
    "Next": "NextTask"
}
asked 7 years ago842 views
2 Answers
1

Thank you for the response. FYI, I've determined that this is also a problem in step-functions when feeding the numeric results of a dynamodb getItem task into a Choice state: I cannot utilize any of the numeric comparison functions successfully; however, the string comparison operators do function as expected.

The root cause appears to be that the results for the numeric fields from dynamodb are being output from the getItem task as strings. Maybe this is something that can be addressed in an upcoming release? (Hopefully before too many people build convoluted work-arounds)

answered 7 years ago
  • I have to agree with @brad00, where are the very basic intrinsic functions like marshall and unmarshall. Or perhaps ParseInt etc. Additionally, having to use a Map State just to marshall a single "L" field we're trying to put into DDB is way too much work for what it is.

    We took a very honest try with Step Functions to handle typical Lambda functions in native States but as with the above, it just feels like way too much convoluted work-arounds to very fundamental tasks.

    Another simple example we're struggling with. Needing something like String.padStart() to prep a string like "10" into the field version of "Episode0010".

0

Hello,

Thank you for your post.

I am sharing the answer provided by my colleague on your question. Please review it below:

The "AttributeUpdates" API of DynamoDB accept only string value types for the N parameter[1] This will explain justify the error message observed.

Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and libraries. However, DynamoDB treats them as number type attributes for mathematical operations[2]. With this in mind I think your implemented workaround sounds good. Hope this explains your observation, meanwhile do not hesitate to contact us if you have any additional questions or concerns.

References:

[1] https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
[2] https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html#DDB-Type-AttributeValue-N

AWS
answered 7 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.