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

fix(apigateway): LambdaRestApi fails when a user defined Stage is attached #5838

Merged
merged 3 commits into from
Jan 17, 2020

Conversation

nija-at
Copy link
Contributor

@nija-at nija-at commented Jan 16, 2020

LambdaRestApi, by default, sets up a proxy integration as part of its
construction which in turn binds the specified lambda function handler
to the proxy using the LambdaIntegration class.

The LambdaIntegration class needs to set up the right IAM permissions
so API Gateway is able to invoke the Lambda function. The policy for
this permission requires the ARN of the 'ANY' Method that is set up by
the Proxy.

When the 'deploy' option is set, it indicates to the RestApi construct
and its sub-constructs (of which LambdaRestApi is one) to create a
default deployment and stage as part of its construction. The user can
also unset the 'deploy' option and specify their own Stage by setting
the 'deploymentStage' on the RestApi construct.

However, when the 'deploy' option is unset, the LambdaIntegration class
cannot compute the ARN for the 'ANY' Method since there's no Stage and
Deployment associated. This produces an error when LambdaRestApi is
constructed, even though the user may configure a Stage later on.

The fix here is straightforward. Computation of the Method ARN should
occur at the time of synthesis rather than at the time of construction.

fixes #5744


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…ached

LambdaRestApi, by default, sets up a proxy integration as part of its
construction which in turn binds the specified lambda function handler
to the proxy using the LambdaIntegration class.

The LambdaIntegration class needs to set up the right IAM permissions
so API Gateway is able to invoke the Lambda function. The policy for
this permission requires the ARN of the 'ANY' Method that is set up by
the Proxy.

When the 'deploy' option is set, it indicates to the RestApi construct
and its sub-constructs (of which LambdaRestApi is one) to create a
default deployment and stage as part of its construction. The user can
also unset the 'deploy' option and specify their own Stage by setting
the 'deploymentStage' on the RestApi construct.

However, when the 'deploy' option is unset, the LambdaIntegration class
cannot compute the ARN for the 'ANY' Method since there's no Stage and
Deployment created. This generates at synthesis, even though there may
be a Stage that the user has configured against the RestApi later on.

The fix here is straightforward. Computation of the Method ARN should
occur at the time of synthesis rather than at the time of construction.

fixes #5744
@nija-at nija-at added the contribution/core This is a PR that came from AWS. label Jan 16, 2020
@nija-at nija-at requested a review from eladb January 16, 2020 17:59
@nija-at nija-at self-assigned this Jan 16, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at nija-at requested a review from a team January 17, 2020 09:38
@mergify
Copy link
Contributor

mergify bot commented Jan 17, 2020

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Jan 17, 2020

Thank you for contributing! Your pull request is now being automatically merged.

@mergify mergify bot merged commit 05719d7 into master Jan 17, 2020
@mergify mergify bot deleted the nija-at/apigateway-deployunset branch January 17, 2020 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[apigateway] LambdaRestApi fails when the deploy option is unset
4 participants