Search code examples
amazon-s3bucketaws-cloudformationserverless-framework

Unable to create S3Buckets through serverless.yml


I simply tried to add a new S3Bucket into the Resources section and the stack is not being built anymore:

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

and the error I'm getting is not helping too much: Template format error: Unresolved resource dependencies [] in the Resources block of the template (nothing between the [] that could indicate what to look for)

Any idea what's going on?

I'm running serverless 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

Solution

  • The Reference to an empty-string in your iamRoleStatements section, - "Ref" : "", is likely causing the Unresolved resource dependencies [] error. Remove this line from your template, since it seems to be unnecessary.