无法在 Step Function API 网关调用的查询参数上从上下文添加变量
Cannot add variable from context on QueryParameters on Step Function API Gateway call
我正在尝试从 Step Function 进行两次连续的 API 网关调用,使用第一个结果中的值对第二个结果进行调用。我已经在 POST 调用中尝试过并且它有效,但现在我无法在 GET 调用中执行此操作。这是我的步骤函数:
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Api Call",
"States": {
"Api Call": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "***************.us-east-1.amazonaws.com",
"Method": "GET",
"Path": "universities",
"RequestBody": {},
"AuthType": "NO_AUTH"
},
"ResultSelector": {
"logWord.$": "$.StatusText"
},
"Next": "Api Call 2"
},
"Api Call 2": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "***************.us-east-1.amazonaws.com",
"Method": "GET",
"Path": "logging",
"Headers": {
"Content-Type": ["application/json"]
},
"QueryParameters": {
"logWord.$": "$.logWord"
},
"AuthType": "NO_AUTH"
},
"End": true
}
}
}
我得到的错误如下:
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'Api Call 2' (entered at the event id #7). The Parameters '{\"ApiEndpoint\":\"***************.us-east-1.amazonaws.com\",\"Method\":\"GET\",\"Path\":\"logging\",\"Headers\":{\"Content-Type\":[\"application/json\"]},\"QueryParameters\":{\"logWord\":\"OK\"},\"AuthType\":\"NO_AUTH\"}' could not be used to start the Task: [The value of the field 'QueryParameters' has an invalid format]"
}
根据 documentation,查询参数应该放在方括号之间,但是如果我使用的是上下文变量,我就不能放在方括号中。控制台甚至不允许我保存 (The value for the field 'logWord.$' must be a STRING that contains a JSONPath but was an ARRAY
)。
如果有人知道如何使用上下文变量进行 GET 调用,我们将不胜感激。
看起来 QueryParameters
想要一个字符串列表。使用 States.Array
intrinsic function 将内插的 string
转换为 [string]
列表。
"QueryParameters": {
"logWord.$": "States.Array($.logWord)" // ["OK"]
},
我正在尝试从 Step Function 进行两次连续的 API 网关调用,使用第一个结果中的值对第二个结果进行调用。我已经在 POST 调用中尝试过并且它有效,但现在我无法在 GET 调用中执行此操作。这是我的步骤函数:
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Api Call",
"States": {
"Api Call": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "***************.us-east-1.amazonaws.com",
"Method": "GET",
"Path": "universities",
"RequestBody": {},
"AuthType": "NO_AUTH"
},
"ResultSelector": {
"logWord.$": "$.StatusText"
},
"Next": "Api Call 2"
},
"Api Call 2": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "***************.us-east-1.amazonaws.com",
"Method": "GET",
"Path": "logging",
"Headers": {
"Content-Type": ["application/json"]
},
"QueryParameters": {
"logWord.$": "$.logWord"
},
"AuthType": "NO_AUTH"
},
"End": true
}
}
}
我得到的错误如下:
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'Api Call 2' (entered at the event id #7). The Parameters '{\"ApiEndpoint\":\"***************.us-east-1.amazonaws.com\",\"Method\":\"GET\",\"Path\":\"logging\",\"Headers\":{\"Content-Type\":[\"application/json\"]},\"QueryParameters\":{\"logWord\":\"OK\"},\"AuthType\":\"NO_AUTH\"}' could not be used to start the Task: [The value of the field 'QueryParameters' has an invalid format]"
}
根据 documentation,查询参数应该放在方括号之间,但是如果我使用的是上下文变量,我就不能放在方括号中。控制台甚至不允许我保存 (The value for the field 'logWord.$' must be a STRING that contains a JSONPath but was an ARRAY
)。
如果有人知道如何使用上下文变量进行 GET 调用,我们将不胜感激。
看起来 QueryParameters
想要一个字符串列表。使用 States.Array
intrinsic function 将内插的 string
转换为 [string]
列表。
"QueryParameters": {
"logWord.$": "States.Array($.logWord)" // ["OK"]
},