如何在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
专家
已提问 8 个月前13 查看次数
1 回答
0

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

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

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

profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则