Skip to content

Add vpcEndpointIds as an option on SpecRestApi #33295

@acwatson

Description

@acwatson

Describe the bug

The SpecRestApiProps interface (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.SpecRestApiProps.html) is missing the property called "endpointConfiguration". This property got added to the plain RestApi construct, but not the SpecRestApi construct. You can see the endpointConfiguration property is defined in the RestApiProps interface (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApiProps.html).

The endpointConfiguration property is needed so that the API GW can be configured to reference VPC endpoint IDs.

I think what happened is that when this issue was fixed for RestApi (#6038), the implementers did not realize they should also update the SpecRestApi.

I looked at the SpecRestApi code and I see that it actually does support the endpointConfiguration configuration, its just that this property is not defined in the SpecRestApiProps interface. I was able to get the SpecRestApi to use my VPC endpoint IDs by hacking the props input like so:

const endpointConfiguration: apigw.EndpointConfiguration = {
types: [apigw.EndpointType.PRIVATE],
vpcEndpoints: [props.apiGwVpcEndpoint]
};

// Add the missing "endpointConfiguration" property
const apiPropsExtensions = {
endpointConfiguration
};

const specApiProps: apigw.SpecRestApiProps = {
apiDefinition,
...
}

// Hacking type-safety and passing in the endpointConfiguration using the spread operator
const api = new apigw.SpecRestApi(this, "MyAPI", {...specApiProps, ...apiPropsExtensions});

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.177.0

Expected Behavior

The SpecRestApiProps interface should have a "endpointConfiguration" property just like the RestApiProps interface does. It is needed so that the API GW can be configured with VPC endpoint IDs.

Current Behavior

The SpecRestApiProps interface does not have a "endpointConfiguration" property, so it is necessary to use an "escape hatch" approach and set VPC endpoint IDS using the L1 construct or using the spread operator like I did in my bug description.

Reproduction Steps

//This will not compile due to the endpointConfiguration property not being in the interface

const specApiProps: apigw.SpecRestApiProps = {
apiDefinition,
restApiName: ${apiIdentifier},
deploy: true,
description: My API,
endpointConfiguration: {
types: [apigw.EndpointType.PRIVATE],
vpcEndpoints: [props.apiGwVpcEndpoint]
}
}

Possible Solution

Update the SpecRestApiProps to have an endpointConfiguration property, just like RestApiProps.

Additional Information/Context

No response

CDK CLI Version

2.177.0

Framework Version

No response

Node.js Version

v18.20.4

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions