apigateway: Use existing RestAPI to create CloudFront distribution
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApiBase.html) 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:
```TypeScript
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
- [X] 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)
Contributor guide
Research direction
Start by reading the RestApiBase and RestApi.fromRestApiId entry points, then inspect CloudFront's RestApiOrigin integration. Trace which API Gateway identifier and stage data the origin currently requires, and compare the existing import patterns and tests. Done means an existing RestApi and selected stage can be referenced for a CloudFront distribution with coverage for the requested use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100