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

Serverless部署报错:IamRoleLambdaExecution创建失败,求解决

问题描述

我是AWS服务与Serverless应用开发新手,执行sls deploy命令时出现CREATE_FAILED: IamRoleLambdaExecution (AWS::IAM::Role)错误,我的serverless.yml配置如下:

provider:
  name: aws
  runtime: nodejs12.x
  memorySize: 256
  stage: ${opt:stage, 'dev'}
  region: eu-west-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb.PutItem
      Resource: 
        - arn:aws:dynamodb:#{AWS::Region}:#{AWS::AccountId}:table/AuctionsTable  
修复方案

问题出在IAM角色资源ARN里的变量语法错误:

  • Serverless框架中引用AWS区域和账号ID的正确变量是${aws:region}和${aws:accountId},而不是CloudFormation原生的#{AWS::Region}和#{AWS::AccountId}语法。

修改后的serverless.yml配置:

provider:
  name: aws
  runtime: nodejs12.x
  memorySize: 256
  stage: ${opt:stage, 'dev'}
  region: eu-west-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb.PutItem
      Resource: 
        - arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/AuctionsTable  

修改完成后,重新执行sls deploy命令即可完成部署。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 13:05:27