Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addDependency not working as documented #7033

Closed
rigsbyt opened this issue Mar 26, 2020 · 3 comments
Closed

addDependency not working as documented #7033

rigsbyt opened this issue Mar 26, 2020 · 3 comments
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug.

Comments

@rigsbyt
Copy link

rigsbyt commented Mar 26, 2020

Per the Cloudformation documentation, APIGateway deployments must depend on any methods: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-deployment.html#aws-resource-apigateway-deployment--examples

Per the CDK documentation here, it sounds like all you should need to do to express this in CDK is deployment.node.addDependency(method): https://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html#construct-dependencies

But that call does nothing (silently; it seems to be a complete no-op). In order to express the dependency, we had to do the following: (this.restApi.latestDeployment?.node.defaultChild as apiGateway.CfnDeployment).addDependsOn(method.node)

I'm not sure whether this is a product bug or a documentation bug, but it was pretty challenging to square the behavior I was seeing with the documentation.

Reproduction Steps

const restApi = new RestApi(...)
const resource = restApi.root.addResource('resource')
const method = resources.addMethod('POST', (integration), ...)

restApi.latestDeployment?.node.addDependency(method)

Error Log

Silently, nothing happens.

Environment

  • 1.31.0
  • 1.31.0
  • Mac
  • Typescript

This is 🐛 Bug Report

@rigsbyt rigsbyt added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 26, 2020
@NetaNir
Copy link
Contributor

NetaNir commented Mar 27, 2020

Hi @rigsbyt,

The CDK will add the DependsOn to the deployment resource implicitly when adding the method:

(properties removed for clarity)

    const restApi = new apigateway.RestApi(this, 'myapi')
    const resource = restApi.root.addResource('resource')
    const method = resource.addMethod('POST')

The synthesized cloudformation template will include the bellow snippet:
(removed properties for clarity)

    "myapiGET9B7CD29E": {
      "Type": "AWS::ApiGateway::Method",
     
    },
    "myapiDeploymentB7EF8EB75c091a668064a3f3a1f6d68a3fb22cf9": {
      "Type": "AWS::ApiGateway::Deployment",
      "Properties": {
       
      "DependsOn": [
        "myapiGET9B7CD29E"
      ],
    }

What do you mean by does nothing?

@NetaNir NetaNir added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Mar 27, 2020
@rigsbyt
Copy link
Author

rigsbyt commented Mar 29, 2020

I've tracked down the source of the issue. My setup involves a CDK library imported as a separate package. The resource dependency is added during the prepare phase. The constructs library uses instanceof cdk.Construct to determine whether to call .prepare(). Because my dependency manager has installed two separate instances of CDK 1.31.0, the instanceof evaluates to false, because they are not the exact same object.

This seems to be the same issue addressed in #1245, but in a different place.

I am working to try and get my dependency manager to dedupe these in a nice way, but it's a little tricky given our setup. Avoiding the instanceof call would be nice.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Mar 30, 2020
@nija-at
Copy link
Contributor

nija-at commented Apr 1, 2020

@rigsbyt - using different versions of the CDK packages will cause this. This has been a source of issues for many customers and it's not easy to root cause that this is the problem.

We have a new packaging model in the works -https://github.com/aws/aws-cdk-rfcs/pull/122/files - which should address a lot of these issues.

I'm closing this issue for now.

@nija-at nija-at closed this as completed Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants