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

Defining Resources on imported RestApi Error on LambdaIntegration #8679

Closed
zubairzahoor opened this issue Jun 22, 2020 · 4 comments · Fixed by #8785
Closed

Defining Resources on imported RestApi Error on LambdaIntegration #8679

zubairzahoor opened this issue Jun 22, 2020 · 4 comments · Fixed by #8785
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. p1

Comments

@zubairzahoor
Copy link

zubairzahoor commented Jun 22, 2020

When we try to use the imported RestApi Gateway to define resources across stacks, it is not allowing to add new LambdaIntegration on the imported Gateway. However it work with MockIntegration as expected.
The following error is thrown on synth or deployment:
RestApi is not available on Resource not connected to an instance of RestApi. Use api instead

This works:

 const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
      restApiId: props.restApiId,
      rootResourceId: props.rootResourceId
    });

    const method = api.root.addResource('pets').addMethod(
      'GET',
      new MockIntegration({
        integrationResponses: [
          {
            statusCode: '200'
          }
        ],
        passthroughBehavior: PassthroughBehavior.NEVER,
        requestTemplates: {
          'application/json': '{ "statusCode": 200 }'
        }
      }),
      {
        methodResponses: [{ statusCode: '200' }]
      }
    );

This doesn't:

const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
      restApiId: props.restApiId,
      rootResourceId: props.rootResourceId
    });

    const method = api.root.addResource('pets').addMethod(
      'GET',
      new LambdaIntegration(
        new lambda.Function(this, 'MyLambda', {
          code: new lambda.AssetCode('src'),

          handler: 'index.main',
          runtime: lambda.Runtime.PYTHON_3_6
        })
      ),
      {
        methodResponses: [{ statusCode: '200' }]
      }
    );

PS: From the repo code it is clear that "restApi throws an error on imported while api returns correctly".
When we use LambdaIntegration, it intrinsically calls ${method.restApi.node.uniqueId} which will throw an error for imported gateway. Workarounds?

@zubairzahoor zubairzahoor added the needs-triage This issue or PR still needs to be triaged. label Jun 22, 2020
@zubairzahoor
Copy link
Author

@nija-at Can you please take a look? ^

@SomayaB SomayaB added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Jun 22, 2020
@SomayaB SomayaB added bug This issue is a bug. guidance Question that needs advice or information. labels Jun 22, 2020
@zubairzahoor zubairzahoor changed the title Defining Resources on imported RestApi Error. Defining Resources on imported RestApi Error on LambdaIntegration Jun 23, 2020
@nija-at
Copy link
Contributor

nija-at commented Jun 25, 2020

Thanks for reporting this bug. I don't think there are any workarounds for this.
Marking this as a p1 bug since there are no workarounds.

@nija-at nija-at added p1 and removed guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Jun 25, 2020
@zubairzahoor
Copy link
Author

Thanks @nija-at . Counting on you for this one.

nija-at pushed a commit that referenced this issue Jun 29, 2020
Root cause here was that `LambdaIntegration` used the deprecated
`restApi` property on its binding Method. This property does not work
on imported RestApi and has been superceded by the property `api`.

A further bug that was discovered was that the API `methodArn()` on the
Method construct did not work on imported RestApi. This has been fixed
up such that if a `deploymentStage` is not defined for the imported
RestApi, the ARN will return '*' as its stage (shorthand for 'all
stages').

fixes #8679
nija-at pushed a commit that referenced this issue Jun 29, 2020
Root cause here was that `LambdaIntegration` used the deprecated
`restApi` property on its binding Method. This property does not work
on imported RestApi and has been superceded by the property `api`.

A further bug that was discovered was that the API `methodArn()` on the
Method construct did not work on imported RestApi. This has been fixed
up such that if a `deploymentStage` is not defined for the imported
RestApi, the ARN will return '*' as its stage (shorthand for 'all
stages').

fixes #8679
nija-at pushed a commit that referenced this issue Jun 29, 2020
Root cause here was that `LambdaIntegration` used the deprecated
`restApi` property on its binding Method. This property does not work
on imported RestApi and has been superceded by the property `api`.

A further bug that was discovered was that the API `methodArn()` on the
Method construct did not work on imported RestApi. This has been fixed
up such that if a `deploymentStage` is not defined for the imported
RestApi, the ARN will return '*' as its stage (shorthand for 'all
stages').

fixes #8679
@nija-at
Copy link
Contributor

nija-at commented Jun 29, 2020

I've posted a fix for this here - #8785

@mergify mergify bot closed this as completed in #8785 Jun 29, 2020
mergify bot pushed a commit that referenced this issue Jun 29, 2020
#8785)

Root cause here was that `LambdaIntegration` used the deprecated
`restApi` property on its binding Method. This property does not work
on imported RestApi and has been superceded by the property `api`.

A further bug that was discovered was that the API `methodArn()` on the
Method construct did not work on imported RestApi. This has been fixed
up such that if a `deploymentStage` is not defined for the imported
RestApi, the ARN will return '*' as its stage (shorthand for 'all
stages').

fixes #8679


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
whimzyLive pushed a commit to whimzyLive/aws-cdk that referenced this issue Jul 1, 2020
aws#8785)

Root cause here was that `LambdaIntegration` used the deprecated
`restApi` property on its binding Method. This property does not work
on imported RestApi and has been superceded by the property `api`.

A further bug that was discovered was that the API `methodArn()` on the
Method construct did not work on imported RestApi. This has been fixed
up such that if a `deploymentStage` is not defined for the imported
RestApi, the ARN will return '*' as its stage (shorthand for 'all
stages').

fixes aws#8679


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants