英文:
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
以下是已翻译的内容:
状态机版本和别名名称当前不包含在上下文对象中。所以,我能想到的唯一选项是:
- 在执行内部调用DescribeExecution以获取版本和/或别名ARN
- 将版本和/或别名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:
- Call DescribeExecution within the execution on itself to get the version and/or alias ARN
- Pass the version and/or alias ARN to the execution as input
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论