Skip to content

Commit 1cba2f7

Browse files
author
Declan Carroll
committed
Adding example for deployment of a Private API gateway to AWS.
1 parent 0379c51 commit 1cba2f7

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
An example of a private API gateway configured to work on an AWS VPC:
2+
3+
1. run `npm install` to grab the dependencies
4+
2. run `npm start` to set up the lambda project under the default name on AWS
5+
3. load the URL that the create command prints out -- you should see `Hello from your Private API`
6+
7+
8+
Check out [package.json](package.json) to see the configuration for the security groups and VPCEs.
9+
10+
`Troubleshooting:`
11+
If after deploying your gateway you can't appear to access or resolve it, ensure that you are able to resolve URL's on the private DNS.
12+
13+
**[Private API Considerations](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html#apigateway-private-api-design-considerations)**
14+
15+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "web-api-private-gateway",
3+
"description": "An example of how to create a private API gateway deployment",
4+
"version": "1.0.0",
5+
"private": true,
6+
"scripts": {
7+
"start": "claudia create --region eu-west-1 --api-module web --vpce $npm_package_security_vpce --account $npm_package_security_account --security-group-ids $npm_package_security_group --subnet-ids $npm_package_security_subnets"
8+
},
9+
"security": {
10+
"account": "Your account number goes here",
11+
"group": "Your security group ID goes here",
12+
"vpce": "Your VPCE ID goes here",
13+
"subnets": "Your subnet ID's go here"
14+
15+
},
16+
"devDependencies": {
17+
"claudia": "^4"
18+
},
19+
"dependencies": {
20+
"claudia-api-builder": "^4"
21+
}
22+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*global require, module*/
2+
var ApiBuilder = require('claudia-api-builder'),
3+
api = new ApiBuilder();
4+
5+
module.exports = api;
6+
7+
api.get('/', function () {
8+
'use strict';
9+
return 'Hello from your Private API';
10+
});
11+
12+
api.addPostDeployStep('Update to Private', async function (options, lambdaDetails, utils) {
13+
'use strict';
14+
15+
let policy = '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"execute-api:Invoke","Resource":"arn:aws:execute-api:REGIONTEMPLATE:ACCOUNTTEMPLATE:APITEMPLATE/*","Condition":{"StringEquals":{"aws:sourceVpce":"VPCETEMPLATE"}}}]}';
16+
policy = policy.replace("ACCOUNTTEMPLATE",options.account);
17+
policy = policy.replace("APITEMPLATE",lambdaDetails.apiId);
18+
policy = policy.replace("REGIONTEMPLATE",lambdaDetails.region);
19+
policy = policy.replace("VPCETEMPLATE",options.vpce);
20+
21+
let params = {
22+
restApiId: lambdaDetails.apiId,
23+
patchOperations: [
24+
//This patch will replace the existing policy with your policy above
25+
{
26+
op: 'replace',
27+
path: '/policy',
28+
value: policy
29+
},
30+
//This patch will update the API endpoint type from EDGE -> PRIVATE
31+
{
32+
op: 'replace',
33+
path: '/endpointConfiguration/types/EDGE',
34+
value :'PRIVATE'
35+
}
36+
]
37+
};
38+
await utils.apiGatewayPromise.updateRestApiPromise(params);
39+
40+
41+
await utils.apiGatewayPromise.createDeploymentPromise({restApiId: lambdaDetails.apiId, stageName: lambdaDetails.alias});
42+
});
43+

0 commit comments

Comments
 (0)