davidgf / serverless-plugin-canary-deployments

Canary deployments for your Serverless application
ISC License
373 stars 80 forks source link

0.6.0 Circular dependency between resources when using canary deployment with alarms #127

Closed mehdiAhmed closed 3 years ago

mehdiAhmed commented 3 years ago

Please, when I'm trying to use alarms with canary deployment I got the following error:


Error: The CloudFormation template is invalid: Circular dependency between resources: [PreHookLambdaVersionyIkv4STnjANV1dwXjZgH1O6NfIACLsA7MiPxuFG5l0, HelloLambdaVersion3PlaAmVdlhn8mnizL8D5qOlGbrBUCtcTti8u3rNMH2U, HttpApiRouteGetHello, PreHookLambdaFunction, IamRoleLambdaExecution, HelloLambdaFunctionAliasLive, HelloLambdaFunction, HelloFooAlarm, PostHookLambdaVersion83cbah35Aq6m4ZifpPQdw4cxhCe5a1ySRGRE32ezC0, HelloLambdaFunctionDeploymentGroup, HttpApiIntegrationHello, HelloLambdaPermissionHttpApi, PostHookLambdaFunction]
      at C:\Users\m\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\lib\validateTemplate.js:20:13

Here my serverless.yml. I get this example from https://www.serverless.com/blog/manage-canary-deployments-lambda-functions-serverless-framework

service: sls-canary-example

frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs14.x
  lambdaHashingVersion: 20201221
  region: eu-west-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - codedeploy:*
      Resource:
        - "*"

plugins:
  - serverless-plugin-aws-alerts
  - serverless-plugin-canary-deployments

custom:
  alerts:
    dashboards: true

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          method: GET
          path: /hello
    alarms:
      - name: foo
        namespace: 'AWS/Lambda'
        metric: Errors
        threshold: 1
        statistic: Minimum
        period: 60
        evaluationPeriods: 1
        comparisonOperator: GreaterThanOrEqualToThreshold
    deploymentSettings:
      type: Linear10PercentEvery1Minute
      alias: Live
      preTrafficHook: preHook
      postTrafficHook: postHook
      alarms:
        - HelloFooAlarm
  preHook:
    handler: hooks.pre
  postHook:
    handler: hooks.post

resources:
  Description: 'Canary stack description'

This is my environment

Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              14.16.0
     Framework Version:         2.40.0
     Plugin Version:            4.5.3
     SDK Version:               4.2.2
     Components Version:        3.9.2

And this is the package.json that I use:

{
  "name": "sls-canary-deployments-example",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "dependencies": {
    "aws-sdk": "^2.336.0",
    "uuid": "^3.3.2"
  },
  "devDependencies": {
    "serverless-plugin-aws-alerts": "^1.7.3",
    "serverless-plugin-canary-deployments": "^0.6.0"
  },
  "author": "",
  "license": "ISC"
}

Why This error ? what I should use to have a correct deployment with alarms ?

Thanks

anton-makarov-photobox commented 3 years ago

The same issue. Have you resolved an issue?

mehdiAhmed commented 3 years ago

@anton-makarov-photobox No

DebarshiMondal-06 commented 3 years ago

Same from my side... Is the issue resolved?

mehdiAhmed commented 3 years ago

@LENO-DEV Not yet. Hope to be fixed quickly

srkiNZ84 commented 3 years ago

I'm also getting the same issue when following the guide from: https://www.serverless.com/blog/manage-canary-deployments-lambda-functions-serverless-framework

Circular dependency:

[
ApiGatewayDeployment1626931690024, 
HelloLambdaPermissionApiGateway,
PreHookLambdaFunction, 
HelloLambdaVersiontZg6XQzIjiC9UvMh3YryQRMuc3LFYK4mx06m85c, 
ApiGatewayMethodHelloGet, 
IamRoleLambdaExecution, 
HelloLambdaFunctionAliasLive, 
HelloLambdaFunction, 
HelloFooAlarm, 
PreHookLambdaVersionJMlooKzg4vkcRqk1CIn3am9pBTvXhzbaTYd7LRyWs, 
HelloLambdaFunctionDeploymentGroup
]

Goes away when I comment out the Alarm section from the "serverless.yml" file. Seems to be a case of you can either have the Alarm or the Hooks, but defining them both causes the above circular dependency. From the article here: https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-circular-dependency-sam/ it might be a case of replacing a direct reference in one of the resources above with like "string concatenation" to fix.

From reading the issues, it looks like this might have been introduced with this PR: https://github.com/davidgf/serverless-plugin-canary-deployments/pull/110 which attempted to automate adding in the CodeDeploy IAM Roles to the hook Lambda's?