Skip to content

Commit d93aac1

Browse files
authored
Merge pull request #420 from serverless/aws-node-fullstack
add example for full stack application (front end and backend)
2 parents 9bb51b8 + cc5fa2e commit d93aac1

20 files changed

+35075
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
5454
| [Aws Auth0 Api Gateway](https://github.com/serverless/examples/tree/master/aws-node-auth0-custom-authorizers-api) <br/> Demonstration of protecting API gateway endpoints with auth0 | nodeJS |
5555
| [Aws Node Dynamic Image Resizer](https://github.com/serverless/examples/tree/master/aws-node-dynamic-image-resizer) | nodeJS |
5656
| [Aws Node Dynamodb Backup](https://github.com/serverless/examples/tree/master/aws-node-dynamodb-backup) <br/> Serverless DynamoDB changes backed up to S3 | nodeJS |
57+
| [Aws Node Fullstack](https://github.com/serverless/examples/tree/master/aws-node-fullstack) <br/> Demonstration using a front end deployed with serverless-finch and a backend. | nodeJS |
5758
| [Aws Env Variables Encrypted In A File](https://github.com/serverless/examples/tree/master/aws-node-env-variables-encrypted-in-a-file) <br/> Serverless example managing secrets in an encrypted file | nodeJS |
5859
| [Aws Env Variables](https://github.com/serverless/examples/tree/master/aws-node-env-variables) <br/> This example demonstrates how to use environment variables for AWS Lambdas. | nodeJS |
5960
| [Aws Fetch File And Store In S3](https://github.com/serverless/examples/tree/master/aws-node-fetch-file-and-store-in-s3) <br/> Fetch an image from remote source (URL) and then upload the image to a S3 bucket. | nodeJS |

aws-node-fullstack/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Example – Serverless Email Sign-Up Form
2+
3+
This demo application helps you test Serverless Framework Enterprise's main features:
4+
5+
* **Insights** - Monitoring, metrics and alerts for your functions.
6+
* **Safeguards** - Best practice policies that run before you perform a deployment.
7+
* **Secrets** - Store sensitive credentials in the Serverless Enterprise Dashboard and reference them in your Serverless Framework Project.
8+
9+
![Serverless Framework Enterprise Email Sign-Up Form Example](https://s3.amazonaws.com/assets.sales.serverless/github/enterprise-examples/email_form_preview.gif)
10+
11+
## Installation
12+
13+
#### Clone this repository
14+
15+
```shell
16+
$ git clone https://github.com/serverless/enterprise.git
17+
```
18+
19+
#### Install Front-End & Back-End Dependencies
20+
21+
Navigate into this example project and install dependencies on the frontend and backend.
22+
23+
```shell
24+
# location - enterprise/examples/email-signup-form/frontend
25+
$ npm i
26+
```
27+
28+
```shell
29+
# location - enterprise/examples/email-signup-form/backend
30+
$ npm i
31+
```
32+
33+
#### Create a Tenant and Application in Serverless Framework Enterprise
34+
35+
The Serverless Enterprise Plugin adds a `login` command to the Serverless Framework, use it like this to log you in:
36+
37+
```shell
38+
# location - enterprise/backend
39+
$ serverless login
40+
```
41+
42+
Make sure to follow the prompts and create your Tenant (it's like a Github Org) and Application.
43+
44+
#### Add the Tenant and Application to this project's `serverless.yml`
45+
46+
![App and Tenant](https://s3.amazonaws.com/assets.sales.serverless/github/enterprise-examples/email_form_appandtenant.png)
47+
48+
#### Deploy the back-end
49+
50+
```shell
51+
# location - enterprise/backend
52+
$ serverless deploy
53+
```
54+
55+
#### Run the front-end
56+
57+
```shell
58+
# location - enterprise/backend
59+
$ npm run start
60+
```
61+
62+
#### Add the back-end URL in the front-end
63+
64+
The front-end form is not directed at the API endpoint out of the box. You must copy the POST URL that is returned on `serverless deploy` of the `backend` into the front-end.
65+
66+
The URL should resemble this.
67+
68+
```
69+
https://bpcn36m16a.execute-api.us-east-1.amazonaws.com/dev/submit
70+
```
71+
72+
In the front-end, click "Demo Utilities" and paste this URL into the `FORM API` field. The form should now work, as well as the testing features in the Utilites panel.
73+
74+
75+
## Testing Serverless Insights
76+
77+
The user interface of this example application has a few utilities you can use to test out Serverless Framework Enterprise.
78+
79+
Click on "Demo Utilities" in the top right. A side panel will expand which you can use to invoke the example application's Function several times, to fill Serverless Framework Enterprise with invocation data.
80+
81+
You can also use the panel to generate a random Function code error that will appear in Serverless Framework Enterprise.
82+
83+
Read more about [Insights here](https://github.com/serverless/enterprise/blob/master/docs/insights.md).
84+
85+
## Testing Serverless Secrets
86+
87+
The goal of our Secrets feature is to support storing and using any generic secret as a [Serverless Variable](https://serverless.com/framework/docs/providers/aws/guide/variables/). This will be supported in upcoming weeks.
88+
89+
What Secrets supports now is creating a specific type of secret: AWS Access Keys.
90+
91+
You can use Secrets to reference temporary AWS Access Keys that last for 1 hour, used for the purpose of deploying your Serverless Framework project to the underlying AWS account.
92+
93+
Since these are temporary credentials, they mitigate the risk of developers leaving long-term credentials anywhere (e.g. Github) and are perfect for CI/CD.
94+
95+
Read more about [Secrets here](https://github.com/serverless/enterprise/blob/master/docs/secrets.md).
96+
97+
## Testing Serverless Safeguards
98+
99+
The goal of our Safeguards feature is to be alike a linter for serverless architectures. Safeguards are best practices and organizational policies that are enforced upon deployment. When a deployment happens, Framework Enterprise scans your `serverless.yml` and CloudFormation file before deployment and looks for issues.
100+
101+
Safeguards are immediately applied, out-of-the-box, when you add the Serverless Enterprise Plugin.
102+
103+
Read more about [Safeguards here](https://github.com/serverless/enterprise/blob/master/docs/safeguards.md).

aws-node-fullstack/backend/.gitignore

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

aws-node-fullstack/backend/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Form Submit
3+
*/
4+
5+
const submit = (event, context, callback) => {
6+
7+
if (event['queryStringParameters'] && event['queryStringParameters']['error']) {
8+
let r = Math.random().toString(36).substring(7);
9+
throw new Error(`Random error ${r}`)
10+
}
11+
12+
callback(null, {
13+
statusCode: 200,
14+
headers: {
15+
'Access-Control-Allow-Origin': '*',
16+
'Access-Control-Allow-Credentials': true,
17+
},
18+
body: JSON.stringify({ message: 'form submission received' }),
19+
})
20+
}
21+
22+
module.exports = { submit }

0 commit comments

Comments
 (0)