如何在 DynamoDB Step Function 任务的 ExpressionAttributeNames 部分使用输入值?

How can I use an input value in the ExpressionAttributeNames section of a DynamoDB Step Function task?

我正在尝试在 Step Function 中使用 DynamoDB 资源,但我无法在 ExpressionAttributeValues.

中使用来自步骤输入的值

这是我在 运行 步进函数之前的记录:

{
  "groupId": "5c9e4c4e-088c-48bb-9e41-8d7b6227f117",
  "invitationStatus": {
    "johndoe@example.com": "unsent"
  }
}

这是步骤的输入:

{
  "email": "johndoe@example.com",
  "groupId": "5c9e4c4e-088c-48bb-9e41-8d7b6227f117"
}

这是我的步骤定义:

"Mark Invitation Sent": {
  "Comment": "Marks an invitation as having been sent",
  "Type": "Task",
  "Resource": "arn:aws:states:::dynamodb:updateItem",
  "Parameters": {
    "TableName": "[my-table-name]",
    "Key": {
      "groupId": {
        "S.$": "$.groupId"
      }
    },
    "UpdateExpression": "SET invitationStatus.#email = :sent",
    "ExpressionAttributeNames": {
      "#email": "$.email"
    },
    "ExpressionAttributeValues": {
      ":sent": {
        "S": "sent"
      }
    }
  },
  "End": true
}

这是 运行 步骤后的记录:

{
  "groupId": "5c9e4c4e-088c-48bb-9e41-8d7b6227f117",
  "invitationStatus": {
    "$.email": "sent",
    "johndoe@example.com": "unsent"
  }
}

如您所见,它使用的是“$.email”的字面值而不是实际值 (johndoe@example.com)。我做错了什么?

https://states-language.net/spec.html#parameters 找到了我的答案:

When a field name ends with “.$” and its value can be used to generate an Extracted Value as described above, the field is replaced within the Parameters value by another field whose name is the original name minus the “.$” suffix, and whose value is the Extracted Value.

这基本上意味着我需要将 "#email" 更改为 "#email.$"。像这样对我的步骤定义进行更改解决了我的问题:

"Mark Invitation Sent": {
  "Comment": "Marks an invitation as having been sent",
  "Type": "Task",
  "Resource": "arn:aws:states:::dynamodb:updateItem",
  "Parameters": {
    "TableName": "[my-table-name]",
    "Key": {
      "groupId": {
        "S.$": "$.groupId" //This is where I should have realized I already had an example of something that works
      }
    },
    "UpdateExpression": "SET invitationStatus.#email = :sent",
    "ExpressionAttributeNames": {
      "#email.$": "$.email" //This is the only changed line
    },
    "ExpressionAttributeValues": {
      ":sent": {
        "S": "sent"
      }
    }
  },
  "End": true
}