如何在StepFunction中过滤DynamoDB扫描?

0

【以下的问题经过翻译处理】 尝试在Step Function中执行DynamoDB扫描和过滤,但过滤不匹配任何项。

我的任务是;

"Scan (2)": {
      "Type": "Task",
      "Parameters": {
        "TableName": "Users",
        "FilterExpression": "#Scope = :Global",
        "ExpressionAttributeValues": {
          ":Global": {
            "S": "Global"
          }
        },
        "ExpressionAttributeNames": {
          "#Scope": {
            "S": "Scope"
          }
        }
      },
      "Resource": "arn:aws:states:::aws-sdk:dynamodb:scan",
      "Next": "Pass"
    },

该任务成功运行并产生以下输出;

{
  "Count": 0,
  "Items": [],
  "ScannedCount": 4
}

而这个任务,运行一个扫描(不带过滤)相同的表;

{
  "Type": "Task",
  "Parameters": {
    "TableName": "Users"
  },
  "Resource": "arn:aws:states:::aws-sdk:dynamodb:scan",,
  "Next": "Scan (2)"
}

会产生这个输出;

{
  "Count": 4,
  "Items": [ 
      {
      "Scope": {
        "S": "Global"
      },
      "ServiceName": {
        "S": "Driver"
      },
      "lastVisitDateTime": {
        "N": "1680022000"
      }
    },
      {
      "Scope": {
        "S": "us-east-1"
      },
      "ServiceName": {
        "S": "Driver"
      },
      "lastVisitDateTime": {
        "N": "1680022106"
      }
    },
      {
      "Scope": {
        "S": "Global"
      },
      "ServiceName": {
        "S": "Rider"
      },
      "lastVisitDateTime": {
        "N": "1680022106"
      }
    },
      {
      "Scope": {
        "S": "Global"
      },
      "ServiceName": {
        "S": "Driver"
      },
      "lastVisitDateTime": {
        "N": "1680022200"
      }
    }
  ],
  "ScannedCount": 4
}
profile picture
EXPERT
asked 9 months ago17 views
1 Answer
0

【以下的回答经过翻译处理】 您可以采用以下表达式:

        "FilterExpression": "#Scope = :Global",
        "ExpressionAttributeValues": {
          ":Global": {
            "S": "Global"
          }
        },
        "ExpressionAttributeNames": {
          "#Scope": "Scope"
        }

但是请注意,您的“Scan”操作效率低下,不可扩展,并且随着时间的推移会变得更加昂贵和缓慢。创建“Scope”的全局二级索引会更加有效,这样可以使用更高效、性能更好、成本更低的查询操作。

profile picture
EXPERT
answered 9 months 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