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"
}
brad00
asked 5 years ago556 views
2 Answers
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 5 years ago
0

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)

brad00
answered 5 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.

Guidelines for Answering Questions