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

apigateway: deployment is not invalidated when using a different lambda handler #4551

Closed
eladb opened this issue Oct 17, 2019 · 0 comments · Fixed by #4552
Closed

apigateway: deployment is not invalidated when using a different lambda handler #4551

eladb opened this issue Oct 17, 2019 · 0 comments · Fixed by #4552
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. in-progress This issue is being actively worked on.

Comments

@eladb
Copy link
Contributor

eladb commented Oct 17, 2019

As described in aws-samples/aws-cdk-intro-workshop#83, when changing a Lambda integration to point to a different handler, the APIGW is not invalidated as it should be.

Reproduction Steps

    // GIVEN
    const stack1 = new Stack();
    const stack2 = new Stack();
    const handler1 = new lambda.Function(stack1, 'handler1', {
      code: lambda.Code.fromAsset(path.join(__dirname, 'integ.cors.handler')),
      runtime: lambda.Runtime.NODEJS_10_X,
      handler: 'index.handler'
    });
    const handler2 = new lambda.Function(stack2, 'handler2', {
      code: lambda.Code.fromAsset(path.join(__dirname, 'integ.cors.handler')),
      runtime: lambda.Runtime.NODEJS_10_X,
      handler: 'index.handler'
    });

    // WHEN
    const api1 = new apigateway.RestApi(stack1, 'myapi', {
      defaultIntegration: new apigateway.LambdaIntegration(handler1)
    });
    const api2 = new apigateway.RestApi(stack2, 'myapi', {
      defaultIntegration: new apigateway.LambdaIntegration(handler2)
    });
    api1.root.addMethod('GET');
    api2.root.addMethod('GET');

    // THEN
    expect(stack1).to(haveResource('AWS::ApiGateway::Stage', {
      DeploymentId: { Ref: 'myapiDeploymentB7EF8EB7e0b8372768854261d2d1218739e0a307' }
    }));
    expect(stack2).to(haveResource('AWS::ApiGateway::Stage', {
      DeploymentId: { Ref: 'myapiDeploymentB7EF8EB77c517352b0f7ab73c333e36585c8f1f3' }
    }));
    test.done();

Error Log

Environment

  • CLI Version :
  • Framework Version:
  • OS :
  • Language :

Other


This is 🐛 Bug Report

@eladb eladb added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-apigateway Related to Amazon API Gateway and removed needs-triage This issue or PR still needs to be triaged. labels Oct 17, 2019
eladb pushed a commit that referenced this issue Oct 17, 2019
The calculation of the deployment logical id is based on a hash of the apigateway model, which includes components such as the resource and method configurations. method integrations, which are part of the method configuration are also included, and could possible include references to other resources such as lambda functions.

When the hash was calculated, tokens have been resolved using `StringConcat` which basically converted all tokens to `[Object object]`. This means, for example, that if we changed the reference of an integration lambda to a different handler, the hash would remain the same.

There is no apparent reason why we can't simply resolve tokens using the CloudFormation concatenation function during "prepare", which means that if we now reference a different resource, the token will resolve to a different value and deployment will be invalidated.

Fixes #4551
Fixes aws-samples/aws-cdk-intro-workshop#83
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Oct 17, 2019
@mergify mergify bot closed this as completed in #4552 Oct 17, 2019
mergify bot pushed a commit that referenced this issue Oct 17, 2019
…ed (#4552)

* fix(apigateway): deployment not invalidated when integration is changed

The calculation of the deployment logical id is based on a hash of the apigateway model, which includes components such as the resource and method configurations. method integrations, which are part of the method configuration are also included, and could possible include references to other resources such as lambda functions.

When the hash was calculated, tokens have been resolved using `StringConcat` which basically converted all tokens to `[Object object]`. This means, for example, that if we changed the reference of an integration lambda to a different handler, the hash would remain the same.

There is no apparent reason why we can't simply resolve tokens using the CloudFormation concatenation function during "prepare", which means that if we now reference a different resource, the token will resolve to a different value and deployment will be invalidated.

Fixes #4551
Fixes aws-samples/aws-cdk-intro-workshop#83

* fix lint errors

* update expectations

* add lambda asset

* update expectation

* update expectations

* update decdk tests
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. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants