如何从步骤函数内部获取调用的步骤函数的别名?

huangapple go评论69阅读模式
英文:

How to obtain the Alias of an invoked StepFunction (from within the step function)?

问题

我有一个有别名的 Step Function(非常高兴最近添加了这个支持),其中步骤函数逻辑需要知道别名,例如 Prod 或 Dev。我可以通过别名调用步骤函数,但上下文对象显示的 arn 不包含别名。
具体来说,我调用的 arn 是 "arn:aws:states:us-west-2:************:stateMachine:UpdateLocation:Development",上下文对象包含以下内容:

{
      "Execution": {
        "Id": "arn:aws:states:us-west-2:**********:express:UpdateLocation:57154f70-22c4-440a-9b3a-cf8445bea4ff:33e2e32e-db05-48f1-abe5-ff2d7b6a5d44",
        "Input": {
          "here": "there"
        },
        "Name": "57154f70-22c4-440a-9b3a-cf8445bea4ff",
        "RoleArn": "arn:aws:iam::**********:role/stepfunction-function-role",
        "StartTime": "2023-08-10T18:19:36.028Z"
      },
      "StateMachine": {
        "Id": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation",
        "Name": "UpdateLocation"
      },
      "State": {
        "Name": "Pass (1)",
        "EnteredTime": "2023-08-10T18:19:36.033Z"
      }
}

最终,我是通过 API Gateway 从中调用 Step Function(通过 POST),我使用以下 VTL 来调用步骤函数。

{
    "input": "$util.escapeJavaScript($input.json('$'))",
    "stateMachineArn": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation:Development"
}

我曾考虑将 API Gateway 的阶段添加到输入负载中,但似乎无法使其工作。我尝试了以下方式:

{
    #set ($newInput=$input.json('$'))
    #set($newInput.Environment='Development')
    "input": "$util.escapeJavaScript($newInput)",
    "stateMachineArn": "arn:aws:states:us-west-2:*:stateMachine:UpdateLocation:Development"
}

但我在这里肯定有什么地方出错了,因为当我通过 API Gateway 进行测试时,似乎忽略了我更新输入选项的尝试。它记录了以下日志:

Thu Aug 10 18:28:47 UTC 2023 : Endpoint request body after transformations: {
        "input": "{\"here\":\"there\"}",
    "stateMachineArn": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation:Development"
}

有没有人有关于如何获取别名或如何向输入对象添加新键/值的建议?

谢谢!

英文:

I have an aliased Step Function (so happy that that support was recently added) where the step function logic needs to know the alias, eg Prod or Dev. I can invoke the step function via an alias but the context object shows the arn without the alias.
Specifically I invoke an arn of "arn:aws:states:us-west-2:************:stateMachine:UpdateLocation:Development" and the context object contains;

{
      "Execution": {
        "Id": "arn:aws:states:us-west-2:**********:express:UpdateLocation:57154f70-22c4-440a-9b3a-cf8445bea4ff:33e2e32e-db05-48f1-abe5-ff2d7b6a5d44",
        "Input": {
          "here": "there"
        },
        "Name": "57154f70-22c4-440a-9b3a-cf8445bea4ff",
        "RoleArn": "arn:aws:iam::**********:role/stepfunction-function-role",
        "StartTime": "2023-08-10T18:19:36.028Z"
      },
      "StateMachine": {
        "Id": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation",
        "Name": "UpdateLocation"
      },
      "State": {
        "Name": "Pass (1)",
        "EnteredTime": "2023-08-10T18:19:36.033Z"
      }
}

Ultimately I'm invoking a Step Function from API Gateway (via a POST) and I'm using the following VTL to invoke the step function.

    "input": "$util.escapeJavaScript($input.json('$'))",
    "stateMachineArn": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation:Development"
}

I was thinking I could add the API Gateway stage to the input payload but I can't that to work. I'm trying the following

    #set ($newInput=$input.json('$'))
    #set($newInput.Environment='Development')
    "input": "$util.escapeJavaScript($newInput)",
    "stateMachineArn": "arn:aws:states:us-west-2:*:stateMachine:UpdateLocation:Development"
}

But I have something wrong here because when I test it via API Gateway it seems to ignore my attempts to update the input option. It logs;

Thu Aug 10 18:28:47 UTC 2023 : Endpoint request body after transformations: {
        "input": "{\"here\":\"there\"}",
    "stateMachineArn": "arn:aws:states:us-west-2:**********:stateMachine:UpdateLocation:Development"
}

Does anyone have any suggestions on how to get the alias or on how to add a new key/value to the input object?

Thanks!

答案1

得分: 1

以下是已翻译的内容:

状态机版本和别名名称当前不包含在上下文对象中。所以,我能想到的唯一选项是:

  1. 在执行内部调用DescribeExecution以获取版本和/或别名ARN
  2. 将版本和/或别名ARN作为输入传递给执行
英文:

The state machine version and alias name aren't currently available in the context object. So, your only options that I can think of are:

  1. Call DescribeExecution within the execution on itself to get the version and/or alias ARN
  2. Pass the version and/or alias ARN to the execution as input

huangapple
  • 本文由 发表于 2023年8月11日 02:39:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定