从DynamoDB读取步骤功能工作流程中的DynamoDB迭代数据

发布于 2025-02-04 03:27:49 字数 830 浏览 3 评论 0原文

我是编码和学习AWS服务的新手。我正在尝试从台阶功能工作流程中的dynamoDB表中迭代数据。例如,对于书ID,我想检查购买该书的客户的名字。我主要是在尝试使用MAP状态进行练习,并尝试与DDB集成。

我创建了一个带有id的DDB表作为分区密钥,并添加了cust_name1cust_name2作为书籍的多个客户的属性。现在,在我的步骤功能中,我想使用地图状态查询有多少人拥有该书ID。这可能吗?还是有更好的方法在此情况下使用地图状态?

我可以在任务状态下执行此操作,但要弄清楚如何在此情况下使用MAP状态。

{
  "Comment": "A description of my state machine",
  "StartAt": "DynamoDB Get Book Purchases",
  "States": {
    "DynamoDB Get Book Purchases": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "get-book-data",
        "Key": {
          "id": {
            "S": "121-11-2436"
          }
        }
      },
      "ResultPath": "$.DynamoDB",
      "End": true
    }
  }
}

I am new to coding and learning about AWS services. I am trying to fetch data iteratively from a DynamoDB table in a Step Functions workflow. For Example, say for a book ID I want to check the names of customers that purchased the book. I am primarily trying to do practice using Map state and try to integrate with DDB.

I created a DDB table with id as partition key and added cust_name1 and cust_name2 as attributes for multiple customers of a book. Now in my Step Functions, I want to use a Map state to query how many people have that book ID. Is this possible? Or is there a better way to use Map state for this scenario?

I am able to do this in a Task state, but trying to figure out how to use Map state for this scenario.

{
  "Comment": "A description of my state machine",
  "StartAt": "DynamoDB Get Book Purchases",
  "States": {
    "DynamoDB Get Book Purchases": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "get-book-data",
        "Key": {
          "id": {
            "S": "121-11-2436"
          }
        }
      },
      "ResultPath": "$.DynamoDB",
      "End": true
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反话 2025-02-11 03:27:49

MAP(在步骤功能中)旨在在数组或列表的每个元素上应用功能。 Count是一个聚合功能,因此,将其用作MAP的一部分没有用。

为了进行练习,您可以尝试允许用户购买多本书,其中地图功能将检查库存中每本书的可用性。

Map (in Step Functions) is designed to apply a function on each of the elements of an array or list. Count is an aggregation function and therefore, using it as part of Map is not that useful.

For your exercise, you can try to allow users to buy multiple books, where the Map functions will check the availability of each of the books in your inventory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文