Repository: serverless/serverless (JavaScript)
Date: 2018-06-27 09:28:40+00:00
Task type: Feature

Issue:
Support for new Endpoint type " PRIVATE"
<!--
1. If you have a question and not a bug/feature request please ask it at http://forum.serverless.com
2. Please check if an issue already exists so there are no duplicates
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a  Feature Proposal

## Description

For feature proposals:
Using Amazon API Gateway, we can now create private REST APIs that can only be accessed from your Amazon Virtual Private Cloud (VPC) using an interface VPC endpoint. 

To do that we have to set up "Endpoint Type": PRIVATE. But Serverless framework does not allow to use this Endpoint Type (Only allow "REGIONAL" or "EDGE" ). Can you Include support for this new Endpoint type via Serverless framwork. 

For more details please refer this: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html

Similar or dependent issues:

## Additional Data

* ***Serverless Framework Version ***: 1.27.3
* ***Operating System***: linux
* ***Stack Trace***:
* ***Provider Error messages***:   endpointType must be one of "REGIONAL" or "EDGE". You provided PRIVATE.



Issue discussion:
Is this feature relevant? If so I like to contribute  
@chamathsilva 

>Is this feature relevant?

Yes! However, a status of this issue may be wait-for-cloudformation. To start implementation, CloudFormation will be supported for this feature.

Solution patch:
diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md
index 60d3b3d7b16..26de011f911 100644
--- a/docs/providers/aws/events/apigateway.md
+++ b/docs/providers/aws/events/apigateway.md
@@ -472,7 +472,7 @@ Clients connecting to this Rest API will then need to set any of these API keys
 
 API Gateway [supports regional endpoints](https://aws.amazon.com/about-aws/whats-new/2017/11/amazon-api-gateway-supports-regional-api-endpoints/) for associating your API Gateway REST APIs with a particular region. This can reduce latency if your requests originate from the same region as your REST API and can be helpful in building multi-region applications.
 
-By default, the Serverless Framework deploys your REST API using the EDGE endpoint configuration. If you would like to use the REGIONAL configuration, set the `endpointType` parameter in your `provider` block.
+By default, the Serverless Framework deploys your REST API using the EDGE endpoint configuration. If you would like to use the REGIONAL or PRIVATE configuration, set the `endpointType` parameter in your `provider` block.
 
 Here's an example configuration for setting the endpoint configuration for your service Rest API:
 
diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.js
index 2b6dc4f2bcb..02f07c91295 100644
--- a/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.js
+++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.js
@@ -15,7 +15,7 @@ module.exports = {
     let endpointType = 'EDGE';
 
     if (this.serverless.service.provider.endpointType) {
-      const validEndpointTypes = ['REGIONAL', 'EDGE'];
+      const validEndpointTypes = ['REGIONAL', 'EDGE', 'PRIVATE'];
       endpointType = this.serverless.service.provider.endpointType;
 
       if (typeof endpointType !== 'string') {
@@ -24,7 +24,7 @@ module.exports = {
 
 
       if (!_.includes(validEndpointTypes, endpointType.toUpperCase())) {
-        const message = 'endpointType must be one of "REGIONAL" or "EDGE". ' +
+        const message = 'endpointType must be one of "REGIONAL" or "EDGE" or "PRIVATE". ' +
                         `You provided ${endpointType}.`;
         throw new this.serverless.classes.Error(message);
       }


Test patch:
diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.test.js
index bca554cd1e6..7e65341d777 100644
--- a/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.test.js
+++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.test.js
@@ -81,6 +81,16 @@ describe('#compileRestApi()', () => {
     expect(() => awsCompileApigEvents.compileRestApi()).to.throw(Error);
   });
 
+  it('should compile if endpointType property is REGIONAL', () => {
+    awsCompileApigEvents.serverless.service.provider.endpointType = 'REGIONAL';
+    expect(() => awsCompileApigEvents.compileRestApi()).to.not.throw(Error);
+  });
+
+  it('should compile if endpointType property is PRIVATE', () => {
+    awsCompileApigEvents.serverless.service.provider.endpointType = 'PRIVATE';
+    expect(() => awsCompileApigEvents.compileRestApi()).to.not.throw(Error);
+  });
+
   it('throw error if endpointType property is not EDGE or REGIONAL', () => {
     awsCompileApigEvents.serverless.service.provider.endpointType = 'Testing';
     expect(() => awsCompileApigEvents.compileRestApi()).to.throw('endpointType must be one of');