You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将初始输入数据传入AWS Step Functions的Map状态

解决方案:在AWS Step Functions Map状态中传递原始输入字段

要将初始输入中的指定字段传递到Process Each Contact的每个Map项中,并最终整合到contactDetails里,按以下步骤修改代码:

1. 修改Process Each Contact的Map配置,添加上下文参数

在Map状态中使用parameters属性,将每个联系人项与原始输入的指定字段合并,确保每个Map项处理器能获取到这些字段:

const processContacts = new Map(scope, 'Process Each Contact', {
  itemsPath: JsonPath.stringAt('$.contactsForDeal.results'),
  resultPath: JsonPath.DISCARD,
  parameters: {
    // 保留当前联系人项的原有字段
    'toObjectId.$': '$$.Map.Item.Value.toObjectId',
    'associationTypes.$': '$$.Map.Item.Value.associationTypes',
    // 注入原始输入中的指定字段
    'occurredAt.$': '$.occurredAt',
    'subscriptionType.$': '$.subscriptionType',
    'attemptNumber.$': '$.attemptNumber',
    'objectId.$': '$.objectId',
    'propertyName.$': '$.propertyName',
    'propertyValue.$': '$.propertyValue',
    'changeSource.$': '$.changeSource',
  },
});
  • $$.Map.Item.Value指向当前Map循环中的单个联系人项
  • $.xxx指向进入Map状态前的根输入中的原始字段(这些字段未被之前的任务覆盖)

2. 更新Get Contact Details的ResultSelector,整合原始字段

修改任务的ResultSelector,将原始字段添加到最终的contactDetails对象中:

const getContactDetails = new CustomState(scope, 'Get Contact Details', {
  stateJson: {
    Type: 'Task',
    Resource: 'arn:aws:states:::http:invoke',
    Parameters: {
      'ApiEndpoint.$': JsonPath.format(
        'https://api.hubapi.com/crm/v3/objects/contacts/{}',
        JsonPath.stringAt('$.toObjectId')
      ),
      Method: 'GET',
      Authentication: {
        ConnectionArn: connectionArn,
      },
    },
    Retry: [
      {
        ErrorEquals: ['States.Http.StatusCode.400'],
        MaxAttempts: 0,
      },
      {
        ErrorEquals: ['States.ALL'],
        IntervalSeconds: 5,
        MaxAttempts: 3,
        BackoffRate: 2,
      },
    ],
    ResultSelector: {
      'id.$': '$.ResponseBody.properties.hs_object_id',
      'firstname.$': '$.ResponseBody.properties.firstname',
      'lastname.$': '$.ResponseBody.properties.lastname',
      'email.$': '$.ResponseBody.properties.email',
      // 加入原始输入的指定字段
      'occurredAt.$': '$.occurredAt',
      'subscriptionType.$': '$.subscriptionType',
      'attemptNumber.$': '$.attemptNumber',
      'dealObjectId.$': '$.objectId', // 重命名避免和联系人ID混淆
      'propertyName.$': '$.propertyName',
      'propertyValue.$': '$.propertyValue',
      'changeSource.$': '$.changeSource',
    },
    ResultPath: '$.contactDetails',
  },
});

3. 验证最终输出

修改后,Send Contact Event to Bus发送的事件详情中,contactDetails将包含联系人信息以及所有原始输入的指定字段。

内容的提问来源于stack exchange,提问作者khinester

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:13:10