Application
Server-less Web Apps
www.seed.run
SEED is a fully-managed
CI/CD for Serverless.
Frank Jay
💎
@fanjiewang @jayair
www.seed.run
serverless-stack.com
Serverless Stack is an open source guide for
building full-stack production ready
Serverless applications on AWS.
★ 1.2K 30K 👤 7K ✉
🧐
3-Tier Architecture
🖥
CLIENT APP SERVER DB SERVER
Provides an API
Handles requests
Handles file uploads
Authenticates users
Secures the application
Runs scheduled jobs & tasks
APP SERVER
The App Server
does everything…
Everything except
storing data 😮
🖥
CLIENT APP SERVER
DB SERVER
S3 UPLOADS
SEARCH
App Server is the
“gatekeeper”
⚡
Serverless Architecture
🖥
SPA
COGNITO
DYNAMO
S3 UPLOADS
ELASTIC
🔑
IAM
🔐
LAMBDA
SERVERLESS
⚡
Client coordinates services
Fully-managed architecture
Glued together with Lambda
Use a separate auth provider
Secure all services with IAM
Services auto-scale to traffic
SERVERLESS
⚡
1. User authenticates client side
2. Make signed requests to a service
3. Service checks if user has access
4. Service responds over HTTPS
🔥
Code
Project files
handler.js
serverless.yml
package.json
serverless.yml
service: posts
provider:
name: aws
runtime: nodejs8.10
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: “arn:aws:dynamodb:us-east-1:*:*"
functions:
create:
handler: handler.create
- http:
path: posts/create
method: post
cors: true
authorizer: aws_iam
handler.js
module.create = function(evt, context, callback) {
// Federated user id
const userId = evt.requestContext.identity.cognitoIdentityId;
. . .
await dynamoDbLib.call("put", params);
callback(null, success(params.Item));
};
S3 Uploads
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
COGNITO
🔑
1. Create a User Pool
2. Configure user attributes
3. Create an app client
4. Done!
🔐
AWS IAM
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [ "s3:*" ],
"Resource": [
"arn:aws:s3:::S3_BUCKET/${cognito-identity.amazonaws.com:sub}/*"
]
},
{
"Effect": "Allow",
"Action": [ "execute-api:Invoke" ],
"Resource": [
"arn:aws:execute-api:us-east-1:*:API_GATEWAY_ID/*"
]
}
]
}
AWS Amplify
h"ps://aws-amplify.github.io/amplify-js/
Amplify.configure({
Auth: {
region: COGNITO_REGION,
userPoolId: COGNITO_USER_POOL,
identityPoolId: COGNITO_IDENTITY_POOL,
userPoolWebClientId: COGNITO_APP_CLIENT
},
Storage: {
region: S3_REGION,
bucket: S3_BUCKET
},
API: {
endpoints: [{
name: "posts",
endpoint: API_GATEWAY_URL,
region: API_GATEWAY_REGION
}]
}
});
Sign in a User
import { Auth } from “aws-amplify”;
. . .
// Sign up
await Auth.signUp({ username, password });
await Auth.confirmSignUp(username, confirmationCode);
. . .
// Login
await Auth.signIn(username, password);
Upload a File
import { Storage } from “aws-amplify";
. . .
await Storage.vault.put(
filename,
file,
{ contentType }
);
Call an API
import { API } from "aws-amplify";
. . .
await API.post("posts", "/posts", {
body: post
});
Static Hosting
HOSTING
1. Create a public S3 bucket
2. Link to a CloudFront distribution
3. Attach a domain on Route 53
4. Add SSL with Certificate Manager
$ npm run build
$ aws s3 sync build/ s3://S3_HOSTING_BUCKET
🎉
Recap
PARTY
Massively scalable web app
Fully-managed architecture
Extremely low-cost to run
And no application servers!
🎉
🙌
Closing
Learn to build Serverless apps
Serverless-Stack.com
Fully-managed Serverless CI/CD
SEED.run
Frank Jay
💎
@fanjiewang @jayair
Questions?

Application Server-less Web Applications - Serverless Toronto Meetup