You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置API Gateway集成调用Step Functions:输入参数解析报错解决

问题

调用Step Functions时尝试从请求路径传递id参数,收到如下报错:

"errorMessage": "Unable to resolve property Input from source {"id":"$request.path.id"}. Please make sure that the request to API Gateway contains all the necessary fields specified in request parameters."

当前使用的AWS CloudFormation配置:

Type: AWS::ApiGatewayV2::Integration
DependsOn:
  - ApiGatewayHTTP
  - MyStateMachine
Properties:
  ApiId: !Ref 'ApiGatewayHTTP'
  IntegrationType: AWS_PROXY
  IntegrationSubtype: StepFunctions-StartSyncExecution
  CredentialsArn: !GetAtt MyStateMachineExecutionRole.Arn 
  RequestParameters:
    StateMachineArn: !GetAtt 'MyStateMachine.Arn'
    Input: '{\"id\":\"$request.path.id\"}'
  ConnectionType: INTERNET
  PayloadFormatVersion: 1.0
  TimeoutInMillis: 3000
解决方案

错误根源是RequestParameters中Input的写法不符合API Gateway V2集成Step Functions的参数解析规则:你用了转义的JSON字符串包裹参数引用,导致API Gateway无法正确识别$request.path.id这个变量。

正确配置方式:

  • 若要将id包装为JSON对象,直接使用'{"id": "$request.path.id"}'作为Input的值(YAML格式下无需转义双引号);如果只需要传递id的原始值,直接写$request.path.id即可。

修改后的CloudFormation配置:

Type: AWS::ApiGatewayV2::Integration
DependsOn:
  - ApiGatewayHTTP
  - MyStateMachine
Properties:
  ApiId: !Ref 'ApiGatewayHTTP'
  IntegrationType: AWS_PROXY
  IntegrationSubtype: StepFunctions-StartSyncExecution
  CredentialsArn: !GetAtt MyStateMachineExecutionRole.Arn 
  RequestParameters:
    StateMachineArn: !GetAtt 'MyStateMachine.Arn'
    Input: '{"id": "$request.path.id"}'
  ConnectionType: INTERNET
  PayloadFormatVersion: 1.0
  TimeoutInMillis: 3000

额外注意事项:

  • 确认API Gateway路由已定义路径参数id(例如路由路径设置为/resources/{id}),否则$request.path.id会因找不到参数再次报错。
  • 确保集成使用的IAM角色MyStateMachineExecutionRole具备states:StartSyncExecution权限,且信任API Gateway作为身份提供者。

内容的提问来源于stack exchange,提问作者epitka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 01:35:25