AWS Stepfunctions dynamodb States.Runtime catch fails

Viewed 375

My Stepfunction is supposed to check whether an item exist in the dynamo. if it does, it needs to generate the presigned url, otherwise it has to update the dynamodb item.

When it matches the item, it works as expected where as it fails when dynamo getitem output is null fails with states.runtime error. It does not going through catch statement. appreciate any help.

Here is my code.

{   "Comment": "A Hello World example of the Amazon States Language using Pass states",   "StartAt": "Hello",   "States": {
    "Hello": {
      "Type": "Pass",
      "Next": "Verify item from DynamoDB"
    },
    "s3_url": {
      "Type": "Pass",
      "Result": "Hello",
      "End": true
    },

    "Verify item from DynamoDB": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "s3_table",
        "Key": {
          "etag": {
            "S.$": "$.Records[0].s3.object.eTag"
          }
        }
      },
      "ResultPath": "$.DynamoDB",
      "OutputPath": "$.DynamoDB.Item",
      "Next": "s3_url",
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
        
          "Next": "DynamoDB Update"
        }
      ]
    },
    "DynamoDB Update": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName": "s3_table",
        "Item": {
          "etag": {
            "S.$": "$.eTag"
          },
          "filekey": {
            "S": "mp3Files"
          }
        }
      },
      "End": true
    }   } }
1 Answers

solved this using choice state. Open to hear any suggestions on Catch state.

Here is the code.

{
  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Hello",
  "States": {
    "Hello": {
      "Type": "Pass",
      "Next": "Verify item from DynamoDB"
    },
    "s3_url": {
      "Type": "Pass",
      "Result": "Hello",
      "End": true
    },
    "Verify item from DynamoDB": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
       
        "TableName": "s3_table",
        "Key": {
          "etag": {
            "S.$": "$.Records[0].s3.object.eTag"
          }
        }
      },
      "ResultPath": "$.Records[0].DynamoDB",
      "OutputPath": "$",
      "Next": "Choice State",
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
          "Next": "DynamoDB Update"
        }
      ]
    },
     "Choice State": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.Records[0].DynamoDB.Item.etag.S",
          "IsPresent": true,
          "Next": "s3_url"
        }
      ],
      "Default": "DynamoDB Update"
    },
    "DynamoDB Update": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName": "s3_table",
        "Item": {
          "etag": {
            "S.$": "$.Records[0].s3.object.eTag"
          },
          "filekey": {
            "S.$": "$.Records[0].s3.object.key"
          }
        }
      },
      "End": true
    }
  }
}
Related