是否可以从AWS步骤函数调用REST API?我想调用 Kubernetes 容器和第三方 API 中可用的 REST API。
我正在编写一个 AWS 步骤函数,对于其中一个步骤,我希望调用一个接受数组作为输入之一的 lambda。但是,如果我尝试将 JsonPath 传入数组,则会得到
The value for the field 'arrayField.$' must be a STRING that contains a JSONPath but was an ARRAY
Run Code Online (Sandbox Code Playgroud)
我的步骤函数定义:
{
"StartAt": "First",
"States": {
"First": {
"Type": "Pass",
"Parameters": {
"type": "person"
},
"ResultPath": "$.output",
"Next": "Second"
},
"Second": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:<aws_id>:function:MyFunction",
"Parameters": {
"regularParameter": "some string",
"arrayParameter.$": ["$.output.type"]
},
"Next": "Succeed"
},
"Succeed": {
"Type": "Succeed"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在数组中使用 jsonPath?
我们正在使用 AWS EMR 集群运行批处理 Spark 作业。这些作业定期运行,我们希望通过 AWS Step Functions 来编排这些作业。
截至 2019 年 11 月,Step Functions 已原生支持 EMR。向集群添加 Step 时,我们可以使用以下配置:
"Some Step": {
"Type": "Task",
"Resource": "arn:aws:states:::elasticmapreduce:addStep.sync",
"Parameters": {
"ClusterId.$": "$.cluster.ClusterId",
"Step": {
"Name": "FirstStep",
"ActionOnFailure": "CONTINUE",
"HadoopJarStep": {
"Jar": "command-runner.jar",
"Args": [
"spark-submit",
"--class",
"com.some.package.Class",
"JarUri",
"--startDate",
"$.time",
"--daysToLookBack",
"$.daysToLookBack"
]
}
}
},
"Retry" : [
{
"ErrorEquals": [ "States.ALL" ],
"IntervalSeconds": 1,
"MaxAttempts": 1,
"BackoffRate": 2.0
}
],
"ResultPath": "$.firstStep",
"End": true
}
Run Code Online (Sandbox Code Playgroud)
在 HadoopJarStep 的 Args …
我正在使用 aws Step Functions 来管理工作流程。我正在使用失败状态来处理工作流程中的错误。我想传播 Step Function 工作流程中的一些 json,以便用户可以轻松识别错误来源。例如,如果 Fail 状态的 json 输入如下所示:
{
"error": "some error text",
"other_stuff": {...}
}
Run Code Online (Sandbox Code Playgroud)
然后我想找出错误的根源。我已经设置了失败状态,如下所示:
FailState:
Type: Fail
Cause: States.Format($.error)
Error: Failure Here
Run Code Online (Sandbox Code Playgroud)
然而,这只是生成文字字符串States.Format($.error)作为失败状态的原因。如何使用 aws states 语言和失败状态将实际错误显示为失败状态输出的一部分?任何能够成功地将失败状态的错误文本从步骤输入传播到步骤输出的解决方案都足以解决此问题。
该设置是一个带有 Lambda 的 AWS Step Function,它会在 catch 子句中抛出错误,并应将它们添加到链末尾的错误处理程序 Lambda 的事件负载中。这是通过添加结果路径来完成的,例如
"Catch": [ {
"ErrorEquals": [ "States.ALL" ],
"ResultPath": "$.error-info",
"Next": "Error Handler"
}]
Run Code Online (Sandbox Code Playgroud)
如文档中所述: https: //docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html。
我现在需要创建包含新字段的自定义错误,比如说一个名为“lambdaName”的新字段。
为此,我将自定义一个错误类,如下所示:
class SFLambdaError extends Error {
constructor(message,lambdaName){
super(message)
this.lambdaName = lambdaName
}
}
Run Code Online (Sandbox Code Playgroud)
直接测试 Lambda,这会输出所需的新字段并且看起来不错:
Invoke Error {"errorType":"SFLambdaError","errorMessage":"someNumber.replace is not a function","lambdaName":"testLambdaName","stack": (...)}
Run Code Online (Sandbox Code Playgroud)
但是,当在 Step Function 的流程中实现并输出到事件的“错误信息”中时,新字段会被删除,如下所示:
"error-info": {
"Error": "SFLambdaError",
"Cause": "{\"errorType\":\"SFLambdaError\",\"errorMessage\":\"someNumber.replace is not a function\",\"trace\":[\"SFLambdaError: someNumber.replace is not a function\",\" at Runtime.exports.handler (/var/task/index.js:27:23)\",\" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)\"]}"
Run Code Online (Sandbox Code Playgroud)
因此,SF 错误结果路径似乎只允许给出标准错误类字段。
我测试的解决方法是通过错误处理程序另一端的字符串化和解析来传递 errorMessage …
我在 AWS 上使用步进函数。考虑由 lambda 组成的状态机:
"StartAt": "Metadata",
"States": {
"Metadata": {
"Type": "Task",
"Resource": "${metadataArn}",
"Next": "StoreMetadata",
"Retry" : [
{
"ErrorEquals": [ "States.All" ],
"IntervalSeconds": 2,
"MaxAttempts": 3
}
],
"Catch": [
{
"ErrorEquals": [ "States.All" ],
"Next": "ErrorHandler"
}
]
} ...
...
Run Code Online (Sandbox Code Playgroud)
如何将特定数据传递给“ErrorHandler”。比如失败的那一步,可能是一条数据。我正在使用 nodejs 但可以外推到任何运行时。
例如,在节点中,我们可能有一个 lambda,其中:
module.exports.handler = async input => {
const ids = JSON.parse(input).ids
// try to read in data for ids.
// read fails / throws exception
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让错误处理程序获取 id 数组,以便我可以将它们标记为失败?如果这个“ErrorHandler”是多个步骤的捕获,我怎么能知道哪些步骤失败了?
我有一个工作 StepFunction 状态机,有 4 个步骤触发 4 个 Lambda。
由于其中一个步骤将是一个运行时间较长的任务,因此我决定将其中一个 Lambda 转换为 Fargate 任务。
配置 ECS 和 Fargate 任务后,我尝试更新状态机定义,但收到错误:Failed to update state machine.没有任何其他消息。
我的状态机定义似乎是有效的,就是这样,只是没有实际的 ARN:
{
"Comment": "My Workflow",
"StartAt": "Step1",
"States": {
"Step1": {
"Type": "Task",
"Resource": "copy-pasted-arn-of-lambda",
"Next": "Step2"
},
"Step2": {
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"Parameters": {
"LaunchType": "FARGATE",
"Cluster": "copy-pasted-arn-of-cluster",
"TaskDefinition": "copy-paster-arn-of-task-definition",
"Overrides": {
"ContainerOverrides": [
{
"Name": "container-name",
"Command.$": "$.commands"
}
]
}
},
"Next": "Step3",
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": …Run Code Online (Sandbox Code Playgroud) 我正在编写用于为 AWS StepFunctions 创建 IAM 角色的 terraform。应该是什么价值主要 在assume_role_policy
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "stepfunctions.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
Run Code Online (Sandbox Code Playgroud)
我收到错误
错误:创建 IAM 角色 my_utility_sfn 时出错:MalformedPolicyDocument:策略中的委托人无效:“SERVICE”:“stepfunctions.amazonaws.com”
下面的步骤函数在 aws 中执行,当缺少必需参数时,它会取消流程并抛出 States.Runtime 错误。这是处于步骤函数的捕获阶段,但它没有捕获所述错误。
定义的Step函数如下,
{
"StartAt": "Log Start Step Function",
"Comment": "Executed with inputs",
"States": {
"Log Start Step Function": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:0000000:function:update",
"Parameters": {
"body": {
"itemID.$": "$.itemID",
"functionName.$": "$.stepFunctionName ",
"executionARN.$": "$$.Execution.Id",
"complete": false,
"inprogress": true,
"error": false
}
},
"Catch": [
{
"ErrorEquals": [
"States.Runtime"
],
"ResultPath": "$.taskresult",
"Next": "Log Failed Module"
},
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.taskresult",
"Next": "Log Failed Module"
}
],
"ResultPath": "$.taskresult",
"Next": "Evaluate Module PA1"
} …Run Code Online (Sandbox Code Playgroud) error-handling runtime-error amazon-web-services aws-step-functions aws-step-config