Skip to content

Commit 3b2e1ea

Browse files
committed
-Created a sample reference for shared API gateway.
1 parent afe9732 commit 3b2e1ea

File tree

15 files changed

+247
-0
lines changed

15 files changed

+247
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
6060
| [Aws Function Compiled With Babel](https://github.com/serverless/examples/tree/master/aws-node-function-compiled-with-babel) <br/> Demonstrating how to compile all your code with Babel | nodeJS |
6161
| [Serverless Github Check](https://github.com/serverless/examples/tree/master/aws-node-github-check) | nodeJS |
6262
| [Aws Github Webhook Listener](https://github.com/serverless/examples/tree/master/aws-node-github-webhook-listener) <br/> Extend your github repositories with this github webhook listener | nodeJS |
63+
| [Aws Node Shared API Gateway](https://github.com/serverless/examples/tree/master/aws-node-shared-gateway) <br/> Demonstration of a shared API Gateway between multiple Lambdas. | nodeJS |
6364
| [Aws Node Graphql Api With Dynamodb](https://github.com/serverless/examples/tree/master/aws-node-graphql-api-with-dynamodb) <br/> A single-module GraphQL endpoint with query and mutation functionality. | nodeJS |
6465
| [Aws Lambda And Heroku Postgres](https://github.com/serverless/examples/tree/master/aws-node-heroku-postgres) <br/> Shows how to connect AWS Lambda to Heroku Postgres. Uses an api:release Heroku webhook and the Heroku API to handle automatic Heroku Postgres credential rotation. | nodeJS |
6566
| [Aws Iot Event](https://github.com/serverless/examples/tree/master/aws-node-iot-event) <br/> Example on how to setup a AWS IoT Rule to send events to a Lambda function | nodeJS |

aws-node-shared-gateway/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Shared AWS API Gateway
2+
3+
Working on production projects would often require the usage of a shared API gateway between multiple Lambda functions. This repository showcases how to deploy multiple Lambda functions that are attached on a single API gateway.
4+
5+
## Add execution permission to CI deploy + decomission scripts.
6+
7+
```sh
8+
chmod +x .\ci-deploy.sh
9+
chmod +x .\ci-decomission.sh
10+
```
11+
12+
### Configure your AWS Deployment Account
13+
14+
Provide an AWS account that have sufficient access so that serverless can deploy the stack.
15+
16+
```sh
17+
serverless config credentials --provider aws --key YOUR_AWS_ACCESS_KEY --secret YOUR_AWS_SECRET_KEY
18+
```
19+
20+
# Deploying the API Gateway + Lambda Stack
21+
22+
To deploy the
23+
24+
```sh
25+
.\ci-deploy
26+
```
27+
28+
# Decomission all resources
29+
30+
```sh
31+
.\ci-decomission
32+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
echo "Demolishing your awesome stacks..."
4+
cd products
5+
serverless remove
6+
7+
cd ..
8+
cd transactions
9+
serverless remove
10+
11+
cd ..
12+
cd users
13+
serverless remove
14+
15+
cd ..
16+
cd gateway
17+
serverless remove
18+
19+
echo "Demolishing complete :)"
20+
read

aws-node-shared-gateway/ci-deploy.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
cd gateway
4+
serverless deploy
5+
sleep 5s
6+
7+
cd ..
8+
cd products
9+
serverless deploy
10+
sleep 5s
11+
12+
cd ..
13+
cd transactions
14+
serverless deploy
15+
sleep 5s
16+
17+
cd ..
18+
cd users
19+
serverless deploy
20+
sleep 5s
21+
22+
echo "Press any key to continue"
23+
read
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
service: shared-gateway
2+
provider:
3+
name: aws
4+
runtime: nodejs8.10
5+
region: ap-southeast-1
6+
resources:
7+
Resources:
8+
SharedGW:
9+
Type: AWS::ApiGateway::RestApi
10+
Properties:
11+
Name: SharedGW
12+
Outputs:
13+
apiGatewayRestApiId:
14+
Value:
15+
Ref: SharedGW
16+
Export:
17+
Name: SharedGW-restApiId
18+
apiGatewayRestApiRootResourceId:
19+
Value:
20+
Fn::GetAtt:
21+
- SharedGW
22+
- RootResourceId
23+
Export:
24+
Name: SharedGW-rootResourceId
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
3+
module.exports.getProducts = async event => {
4+
return {
5+
statusCode: 200,
6+
body: JSON.stringify([
7+
{
8+
id: "20379435-7c7b-4bdd-8d0c-3f3136979c29",
9+
name: "Foo 1",
10+
price: 22
11+
},
12+
{
13+
id: "f7c26612-63ff-4064-89c8-9a316ba043a3",
14+
name: "Foo 2",
15+
price: 23
16+
},
17+
{
18+
id: "c04f63f0-b2ad-4526-a187-b6ac8adcc648",
19+
name: "Foo 3",
20+
price: 24
21+
}
22+
])
23+
};
24+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
service: eshop-products
2+
provider:
3+
name: aws
4+
runtime: nodejs8.10
5+
region: ap-southeast-1
6+
apiGateway:
7+
restApiId:
8+
"Fn::ImportValue": SharedGW-restApiId
9+
restApiRootResourceId:
10+
"Fn::ImportValue": SharedGW-rootResourceId
11+
functions:
12+
get-products:
13+
handler: handler.getProducts
14+
events:
15+
- http:
16+
path: products/list
17+
method: get
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless

0 commit comments

Comments
 (0)