aws step function converting special characters to UTF-8 in URL (not able to pass correct URL with query parameter to API gateway)

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

aws step function converting special characters to UTF-8 in URL (not able to pass correct URL with query parameter to API gateway)

问题

以下是翻译好的内容:

我正在使用步函数中的api-gateway调用任务,但无法在路径中使用查询参数。

以下是我的步函数定义:

{
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "endpoint",
"AuthType": "IAM_ROLE",
"Headers": {
"Content-Type": [
"application/json"
]
},
"Method": "GET",
"Path": "path?a=1",
"RequestBody.$": "$"
},
"End": true
}

当我在查询参数中使用a=1时,它会将其转换为path%3F%7B%7D格式并引发错误。

我也了解apigateway调用任务中的查询参数,但问题是我有类似a=1的输入,如果我将其传递给查询参数,它也会失败,因为查询参数期望类似这样的内容:

"QueryParameters": {
"a": [
"1"
]
}

有没有办法在步函数中解决这个问题?

英文:

I am using api-gateway invoke task in step-function but not able to use query parameters in PATH

here is my step function defination

{
  "Type": "Task",
  "Resource": "arn:aws:states:::apigateway:invoke",
  "Parameters": {
    "ApiEndpoint": "endpoint",
    "AuthType": "IAM_ROLE",
    "Headers": {
      "Content-Type": [
        "application/json"
      ]
    },
    "Method": "GET",
    "Path": "path?a=1",
    "RequestBody.$": "$"
  },
  "End": true
}

when I use a=1 in query parameter it converts it to path%3F%7B%7D like format and give error.

I also know about queryparameter in apigateway invoke task but the problem is I have input like a=1 if I pass this to query parameter it will also fail. as query paramter expect something like this

 "QueryParameters": {
      "a": [
        "1"
      ]
    }

Any idea how to solve this problem within step function?

答案1

得分: 0

我已经通过从API网关分别传递查询参数作为键和值来解决了这个问题。

{
    "key": "a",
    "value": "1"
}

然后在状态机中使用内置函数来处理查询参数,如下所示:

"QueryParameters.$": "States.StringToJson(States.Format(' { \"{}\":[{}] }', $.key , $.value))"
英文:

I have solved problem by passing query parameter from api-gateway separately as key and value

{
    "key": "a",
    "value": "1"
}

then used Intrinsic functions in state machine to handle in QueryParameter like this:

"QueryParameters.$": "States.StringToJson(States.Format(' \\{  \"{}\":[\"{}\"]  \\}', $.key , $.value))"

huangapple
  • 本文由 发表于 2023年8月10日 23:10:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877075.html
匿名

发表评论

匿名网友

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

确定