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: Use existing RestAPI to create CloudFront distribution #32332

Open
1 of 2 tasks
cyberworkz opened this issue Nov 29, 2024 · 4 comments
Open
1 of 2 tasks

apigateway: Use existing RestAPI to create CloudFront distribution #32332

cyberworkz opened this issue Nov 29, 2024 · 4 comments
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway breaking-change This issue requires a breaking change to remediate. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@cyberworkz
Copy link

cyberworkz commented Nov 29, 2024

Describe the feature

Current AWS CDK does not give the possibility to use an existing RestAPI (RestApiBase) to create a stack for Cloudfront distributions. Add a static method to RestApiBase to refer to an existing RestApi and a certain stage.

Use Case

I have some existing RestApi's in the API Gateway. I want to use a Cloudfront distribution for them and use AWS CDK to create these distributions.

Proposed Solution

The current code is missing fields to properly determine all necessary info. Include stage-name for creating a RestApiBase will probably help.

This code fails:

let restApi: apigateway.RestApiBase = apigateway.RestApi.fromRestApiId(this, props.name, props.restApiId) as apigateway.RestApiBase;
        
        new cloudfront.Distribution(this, props.name, {
            defaultBehavior: {
                origin: new cdk.aws_cloudfront_origins.RestApiOrigin(restApi,
                    {
                        originPath: '/home',
                    },
                ),
                allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,

Other Information

I am trying to use a proxy-lambda with apigateway integration to connect to a cloudfront distribution.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.171.0

Environment details (OS name and version, etc.)

Apple M1 Max Macos Sequoia 15.1.1 (24B91)

@cyberworkz cyberworkz added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 29, 2024
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Nov 29, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 5, 2024
@khushail khushail self-assigned this Dec 5, 2024
@khushail
Copy link
Contributor

khushail commented Dec 5, 2024

Hi @cyberworkz , thanks for reaching out. I see this property for defining s deploymentStage name, are you referring to this-
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html#deploymentstage

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Dec 5, 2024
@khushail
Copy link
Contributor

khushail commented Dec 5, 2024

I also tried an alternate approach to see if that works but it also fails -

        # importing existing  RESTAPI

        rest_api = apigateway.RestApi.from_rest_api_id(self, "MyExistingApi", "54rrn5bns0")
        api_stage = rest_api.deployment_stage("prod")

        # create CloudFrontDistribution with APIGateway as origin

        cloudfront_dist = cloudfront.Distribution(self, "MyCloudFrontDist", 
            default_behavior=cloudfront.BehaviorOptions(
                origin=origins.HttpOrigin(api_stage.invoke_url)
            )
        )

Error received-


    raise RuntimeError(resp.error) from JavaScriptError(resp.stack)
RuntimeError: Of property aws-cdk-lib.aws_apigateway.RestApiBase.deploymentStage: Unable to serialize value as aws-cdk-lib.aws_apigateway.Stage

Since your suggestion of this FR might be breaking change, I would reach out to core team for getting their thoughts on implementation perspective and share their insights as well.

@khushail khushail removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 5, 2024
@khushail khushail removed their assignment Dec 5, 2024
@khushail khushail added effort/medium Medium work item – several days of effort breaking-change This issue requires a breaking change to remediate. labels Dec 5, 2024
@cyberworkz
Copy link
Author

Thanks @khushail for looking into this. How can I reach out to core team with this issue?

@khushail
Copy link
Contributor

@cyberworkz , I have already added this issue to the Project board and requesting inputs from the On-call. Should be able to get feedback soon.

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 breaking-change This issue requires a breaking change to remediate. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants