【问题标题】:Unable to create S3Buckets through serverless.yml无法通过 serverless.yml 创建 S3Bucket
【发布时间】:2023-09-22 10:38:01
【问题描述】:

我只是尝试将一个新的 S3Bucket 添加到资源部分,并且不再构建堆栈:

resources:
  Resources:
    myBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: prefix-${self:custom.env.myvar}-myBucket

我得到的错误并没有太大帮助: 模板格式错误:未解决的资源依赖关系 [] 在模板的 Resources 块中(在 [] 之间没有可以指示要查找的内容)

知道发生了什么吗?

我正在运行无服务器 v1.5.0

serverless.yml

service: myService
frameworkVersion: "=1.5.0"

custom:
  env: ${file(./.variables.yml)}

provider:
  name: aws
  runtime: nodejs4.3
  stage: ${opt:stage, self:custom.env.stage}
  region: ${self:custom.env.region}
  profile: myProfile-${opt:stage, self:custom.env.stage}
  memorySize: 128

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "lambda:InvokeFunction"
      Resource: "*"
    - Effect: "Allow"
      Action:
    - "s3:ListBucket"
      Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ]  }
    - Effect: "Allow"
      Action:
        - "s3:PutObject"
      Resource:
        Fn::Join:
          - ""
          - - "arn:aws:s3:::"
            - "Ref" : "ServerlessDeploymentBucket"
            - "Ref" : ""

functions:
  myFunction:
    handler: functions/myFunction.handler
    name: ${opt:stage, self:custom.env.stage}-myFunction

resources:
  Resources:
    myBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: myService-${opt:stage, self:custom.env.myVar}-myBucket

【问题讨论】:

  • 请提供完整的serverless.yml,错误很可能出现在配置文件的其他地方。另外,在原始错误中,[] 之间是否有任何文字?
  • 我也有过这样的想法,但如果我删除那个块,一切都会好的。这是唯一的新增内容并导致错误。无论如何我都会用 serverless.yml 更新问题

标签: amazon-s3 bucket amazon-cloudformation serverless-framework


【解决方案1】:

iamRoleStatements 部分 - "Ref" : "" 中对空字符串的引用可能会导致 Unresolved resource dependencies [] 错误。从模板中删除这一行,因为它似乎没有必要。

【讨论】: