如何使用 AWS Step 函数将路径参数传递给 AWS api 网关?
how to pass path parameter to AWS api gateway using AWS Step function?
在 aws step 函数中,我需要使用先前状态值的路径参数调用 api 网关端点。
步骤函数代码(Api网关调用)
"API Gateway Request": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "****.amazonaws.com",
"Method": "GET",
"Headers": {
"Accept": [
"application/json"
]
},
"Stage": "dev",
"Path": "/sample/$.id",
"AuthType": "IAM_ROLE"
},
"InputPath": "$.id",
"Next": "Lambda Invoke",
"ResultPath": "$.myStateInput"
}
输入到这个状态:
{ "id": "1231" }
不是将“$.id”替换为“1231”,而是像下面这样调用 url
Api 网关:
请告诉我哪里做错了?
根据评论,解决方案是使用 intrinsic function:
"Path.$": States.Format('/sample/{}', $.id)
州代码
"API Gateway Request": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "**.amazonaws.com",
"Method": "GET",
"Headers": {
"Accept": [
"application/json"
]
},
"Stage": "dev",
"Path.$": "States.Format('/sample/{}', $.id)",
"AuthType": "IAM_ROLE"
},
"Next": "Lambda Invoke",
"ResultPath": "$.myStateInput"
}
在 aws step 函数中,我需要使用先前状态值的路径参数调用 api 网关端点。
步骤函数代码(Api网关调用)
"API Gateway Request": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "****.amazonaws.com",
"Method": "GET",
"Headers": {
"Accept": [
"application/json"
]
},
"Stage": "dev",
"Path": "/sample/$.id",
"AuthType": "IAM_ROLE"
},
"InputPath": "$.id",
"Next": "Lambda Invoke",
"ResultPath": "$.myStateInput"
}
输入到这个状态:
{ "id": "1231" }
不是将“$.id”替换为“1231”,而是像下面这样调用 url
请告诉我哪里做错了?
根据评论,解决方案是使用 intrinsic function:
"Path.$": States.Format('/sample/{}', $.id)
州代码
"API Gateway Request": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "**.amazonaws.com",
"Method": "GET",
"Headers": {
"Accept": [
"application/json"
]
},
"Stage": "dev",
"Path.$": "States.Format('/sample/{}', $.id)",
"AuthType": "IAM_ROLE"
},
"Next": "Lambda Invoke",
"ResultPath": "$.myStateInput"
}