如何筛选在调用 API 网关时返回给客户端的内容?

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

How to filter out what gets returned to client when invoking api gateway?

问题

{
"output": "{"details":{},"outputDetails":{"__type":"com.amazonaws.swf.base.model#CloudWatchEventsExecutionDataDetails","included":true},"startDate":1.686226844882E9,"stateMachineArn":"arn:aws:states:us-east-1:0935357777988:mystateMachine-stag","status":"SUCCEEDED","stopDate":1.686226845062E9}"
}

英文:

I have api gateway integration with step function. When I invoke it I get in a response more than I want to return to client. How do I filter out what gets returned to client? I only want values in "output" field. Currently, I get following

{
  "billingDetails": {
    "billedDurationInMilliseconds": 200,
    "billedMemoryUsedInMB": 64
  },
  "executionArn": "arn:aws:states:us-east-1:0935357777988:express:mystatemachine-stag:d12cb1cd-2094-4690-91f6-31af336e1d0f:42fd1794-c810-46d2-a60d-bb68ed5ad31c",
  "input": "{\"pzId\":\"01GQTJW20W5J99R0ZXD1T3W0Q6\"}",
  "inputDetails": {
    "__type": "com.amazonaws.swf.base.model#CloudWatchEventsExecutionDataDetails",
    "included": true
  },
  "name": "d12cb1cd-2094-4690-91f6-31af336e1d0f",
  "output": "{\"details\":{},
  "outputDetails": {
    "__type": "com.amazonaws.swf.base.model#CloudWatchEventsExecutionDataDetails",
    "included": true
  },
  "startDate": 1.686226844882E9,
  "stateMachineArn": "arn:aws:states:us-east-1:0935357777988:mystateMachine-stag",
  "status": "SUCCEEDED",
  "stopDate": 1.686226845062E9
}

答案1

得分: 0

如果您正在使用API网关HTTP API,据我目前的了解,您无法操纵Step Functions API的响应。但对于API网关REST API,您可以这样做。

对于REST API,您可以在响应配置中使用映射模板来返回。例如,您可以使用$input.path函数提供一个JSON路径表达式,以获取output键。

$input.path('$.output')

您还可以查看此文档页面,其中描述了如何使用StepFunctionsRestApi CDK构造来简化设置此集成的过程。

英文:

If you are using API Gateway HTTP APIs, you cannot (to the best of my current knowledge) manipulate the response from the Step Functions API. You can with API Gateway REST APIs.

With REST APIs, you can use a Mapping Template in your response configuration to return. For example, you can use the $input.path function to provide a JSON Path expression that will grab the output key.

$input.path('$.output')

You can also check out this documentation page that describes how to use the StepFunctionsRestApi CDK construct to simplify setting this integration up.

huangapple
  • 本文由 发表于 2023年6月8日 20:45:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431994.html
匿名

发表评论

匿名网友

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

确定