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

如何在Serverless YAML中配置Lambda调用Step Functions状态机的权限

报错示意图

配置方案

该报错的核心原因是Lambda执行角色缺少调用Step Functions状态机的对应操作权限,可通过以下两种方式在serverless.yml中配置:

全局权限配置(所有Lambda生效)

在provider字段下添加IAM角色声明,示例如下:

provider:
  name: aws
  runtime: python3.9 # 替换为你的实际运行时
  iamRoleStatements:
    - Effect: Allow
      Action:
        # 根据实际需要的操作添加权限,常用权限如下
        - states:StartExecution
        - states:DescribeExecution
        - states:StopExecution
      Resource: "arn:aws:states:${aws:region}:${aws:accountId}:stateMachine:你的状态机名称"
      # 测试环境可临时写Resource: "*"放开所有状态机权限,生产环境必须指定精确ARN

单函数权限配置(最小权限推荐)

Serverless Framework 2.26.0及以上版本支持为单个Lambda配置独立权限,避免权限溢出:

functions:
  需要调用Step Functions的函数名:
    handler: index.handler # 替换为你的实际handler路径
    iamRoleStatementsInherit: true # 继承全局默认基础权限
    iamRoleStatements:
      - Effect: Allow
        Action:
          - states:StartExecution
        Resource: "arn:aws:states:${aws:region}:${aws:accountId}:stateMachine:你的状态机名称"
  • 配置完成后执行sls deploy重新部署即可生效
  • 权限中的Action可根据实际业务需求增减,非必要权限不要添加

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 06:36:03