8

When I am adding the following code in serverless.yml file

provider:
  name: aws
  runtime: python3.6
  stage: dev
  region: [REGION]
  iamRoleStatements:
    - Effect: "Allow"
      Action:
       - "s3:GetObject"
      Resource: { "Fn::Join": ["", ["arn:aws:s3:::", { "Ref": [BUCKET NAME] }, "/*" ] ] }

On deployment, I am getting “The CloudFormation template is invalid: Circular dependency between resources:”

I am using boto3 with python3 to get the private file that is uploaded to the S3 bucket after the trigger event so like to give the permission to Lambda function for that bucket.

8
  • I think this is really just a CloudFormation question, not specifically a serverless framework question. Have you looked at the answer to this question? stackoverflow.com/questions/25680599/…
    – Mark B
    Sep 7, 2017 at 15:02
  • No, mainly I am doing something wrong in the serverless.yml file that's why included serverless framework. Sep 7, 2017 at 15:08
  • But it's a CloudFormation error. Isn't serverless.yml just a CloudFormation template file? I would search for how to solve that error in CloudFormation and not narrow down your search unnecessarily to serverless framework.
    – Mark B
    Sep 7, 2017 at 15:10
  • But the code that I shared is in the serverless.yml file and serverless framework is converting that to CloudFormation template. Sep 7, 2017 at 15:24
  • I don't think serverless framework is converting that to a CloudFormation template. It already is a CloudFormation template. That's all it is.
    – Mark B
    Sep 7, 2017 at 15:27

1 Answer 1

14

I have encountered the same issue and I spent hours on it. Finally I found a solution: do NOT ref the bucket.

Change

provider:
  name: aws
  runtime: python3.6
  stage: dev
  region: [REGION]
  iamRoleStatements:
    - Effect: "Allow"
      Action:
       - "s3:GetObject"
      Resource: { "Fn::Join": ["", ["arn:aws:s3:::", { "Ref": [BUCKET NAME] }, "/*" ] ] }

to

provider:
  name: aws
  runtime: python3.6
  stage: dev
  region: [REGION]
  iamRoleStatements:
    - Effect: "Allow"
      Action:
       - "s3:GetObject"
      Resource: { "Fn::Join": ["", ["arn:aws:s3:::<s3-bucket-name>", "/*" ] ] }

Or even simpler:

provider:
  name: aws
  runtime: python3.6
  stage: dev
  region: [REGION]
  iamRoleStatements:
    - Effect: "Allow"
      Action:
       - "s3:GetObject"
      Resource: "arn:aws:s3:::<s3-bucket-name>/*"
4
  • 1
    You saved me thousands of hours! So sad that the main documentation is missing so basic stuff..
    – BartusZak
    Dec 3, 2020 at 8:37
  • What if BucketName is dynamic and changes depending on stage? Feb 13, 2021 at 1:02
  • Tyler Long what does that * star means? Feb 15, 2021 at 14:03
  • @RahulAhire it means all the resources under that bucket.
    – Tyler Liu
    Feb 17, 2021 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.