@@ -13,6 +13,7 @@ module.exports = {
1313 this . apiGatewayRestApiLogicalId = this . provider . naming . getRestApiLogicalId ( ) ;
1414
1515 let endpointType = 'EDGE' ;
16+ let vpcEndpointIds ;
1617
1718 if ( this . serverless . service . provider . endpointType ) {
1819 const validEndpointTypes = [ 'REGIONAL' , 'EDGE' , 'PRIVATE' ] ;
@@ -22,6 +23,16 @@ module.exports = {
2223 throw new this . serverless . classes . Error ( 'endpointType must be a string' ) ;
2324 }
2425
26+ if ( this . serverless . service . provider . vpcEndpointIds ) {
27+ vpcEndpointIds = this . serverless . service . provider . vpcEndpointIds ;
28+
29+ if ( endpointType !== 'PRIVATE' ) {
30+ throw new Error (
31+ 'VPC endpoint IDs are only available for private APIs' ,
32+ 'API_GATEWAY_INVALID_VPC_ENDPOINT_IDS_CONFIG' ,
33+ ) ;
34+ }
35+ }
2536
2637 if ( ! _ . includes ( validEndpointTypes , endpointType . toUpperCase ( ) ) ) {
2738 const message = 'endpointType must be one of "REGIONAL" or "EDGE" or "PRIVATE". '
@@ -31,14 +42,20 @@ module.exports = {
3142 endpointType = endpointType . toUpperCase ( ) ;
3243 }
3344
45+ const EndpointConfiguration = {
46+ Types : [ endpointType ] ,
47+ } ;
48+
49+ if ( vpcEndpointIds ) {
50+ EndpointConfiguration . VpcEndpointIds = vpcEndpointIds ;
51+ }
52+
3453 _ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources , {
3554 [ this . apiGatewayRestApiLogicalId ] : {
3655 Type : 'AWS::ApiGateway::RestApi' ,
3756 Properties : {
3857 Name : this . provider . naming . getApiGatewayName ( ) ,
39- EndpointConfiguration : {
40- Types : [ endpointType ] ,
41- } ,
58+ EndpointConfiguration,
4259 } ,
4360 } ,
4461 } ) ;
0 commit comments