SlideShare a Scribd company logo
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Xiang Shen
Sr. Solutions Architect, Amazon Web Services
SESSION #194306
Developing Serverless Application on
AWS
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What to expect from this session
Serverless Overview
Serverless Development
Demo
>
>
>
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless Overview
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
A serverless world…
Build and run
applications
without thinking about
servers
… pay per request not
for idle
“
Scales with usage High availability
built-in
Never pay for idle No servers
to provision
or manage
“
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Building blocks for serverless applications
AWS Lambda
Amazon DynamoDB
Amazon SNS
Amazon API Gateway Amazon SQS Amazon Kinesis
Amazon S3
Orchestration and State Management
API Proxy and GraphQL Messaging and Queues Analytics
Monitoring and Debugging
Compute Storage Database
AWS X-RayAWS Step Functions Amazon Cognito
User Management and IdP
AWS AppSync Amazon Athena
AWS Lambda@Edge
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
An expanding serverless community
Build and CI/CD
Logging and MonitoringApplications and Deployment
Chalice Framework Serverless Java Container
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless Development
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
A typical day for a developer…
Manager “We need an app to let our customers provide feedback – our
competitors just launched the same thing, so I need it fast. I don’t want to
pay a lot for it, especially when no one is using it. But remember that
we’re growing, so make sure it scales great and is easy to manage and
operate. And you’re on your own – sorry!”
Developer “Not a problem. I’ll make it serverless…”
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Joe promised his boss an app.
Now what?
Step 0: Requirement analysis, high level design…
Step 1: Design decisions - what to use?
Serverless web app with
…an API ???
…access to existing data stored in ???
…static content served by ???
…dynamic content/business logic encoded as ???
What we need
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Building an API with Amazon API Gateway
Internet
Mobile Apps
Websites
Services
AWS Lambda
functionsAPI Gateway
Cache
Endpoints on
Amazon EC2
All publicly
accessible
endpoints
Amazon
CloudWatch
Monitoring
Amazon
CloudFront
Any other
AWS service
Endpoints on
Amazon VPC
Cognito
Authorizer
Lambda
Authorizer
API Authorization
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Accessing stored data in Amazon DynamoDB
Dead Simple
• GetItem(primaryKey)
• PutItem(item)
Amazon DynamoDB
Accelerator
Amazon DynamoDB
Applications
Amazon DynamoDB - Streams
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serving static content with S3 and Cloudfront
Icon made by FlatIcon
Amazon CloudFront Amazon S3
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Business logic encoded in AWS Lambda
SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
EVENT SOURCE FUNCTION
Node.js
Python
Java
C#
Golang
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Bringing it all together…
Amazon S3
Amazon
CloudFront
Static
Content
Content
Delivery
API
Layer
Application
Layer
Persistency
Layer
API
Gateway
Amazon
DynamoDB
AWS
Lambda
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
A typical day for a Serverless developer…
Joe promised his boss an app.
Design decisions:
Serverless web app with
…an API hosted on Amazon API Gateway
…access to existing data stored in Amazon DynamoDB
…static content served by Amazon S3 and Amazon CloudFront
…dynamic content/business logic encoded as Lambda functions
What we need
What’s next?
Step 2: Find working examples and get started!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Next, Joe needs to make some changes.
Step 3: Customize and share
IDE for local dev/test/debug ???
Customize the app we deployed in step 1 ???
Set up a CI/CD pipeline for the team ???
Deploy ???
What we need
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Serverless Application Model (SAM)
CloudFormation extension optimized for
serverless
New serverless resource types:
functions, APIs, and tables
Supports anything CloudFormation
supports
Open specification (Apache 2.0)github.com/awslabs
serverless-application-model
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SAM template
AWSTemplateFormatVersion:"2010-09-09"
Transform:AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri:s3://sam-demo-bucket/todo_list.zip
Handler:index.gethtml
Runtime:nodejs6.10
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path:/{proxy+}
Method:ANY
ListTable:
Type: AWS::Serverless::SimpleTable
Tells CloudFormation this is a SAM
template it needs to “transform”
Creates a Lambda function with the
referenced managed IAM policy,
runtime, code at the referenced zip
location, and handler as defined.
Also creates an API Gateway and
takes care of all
mapping/permissions necessary
Creates a DynamoDB table with 5
Read & Write units
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Introducing SAM Local
CLI tool for local testing of serverless
apps
Works with Lambda functions and
“proxy-style” APIs
Response object and function logs
available on your local machine
Supports all native runtimes
github.com/awslabs
aws-sam-local
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Cloud native IDE in AWS Cloud 9
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Automated CI/CD process
‘git push’ your changes from Cloud9
when ready to share…
Set up an AWS CodePipeline to
build automatically on updates
Local Testing
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Next, Joe needs to make some changes.
Step 3: Customize and share
Need an IDE for local dev/test/debug – AWS Cloud 9 and AWS SAM Local
Customize the app we deployed in step 1 – AWS Cloud 9
Set up a CI/CD pipeline for the team – AWS CodeStar
Deploy (safely!) – SAM and CodeDeploy
What we need
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Now Joe needs to secure the application.
Step 4: Enforce AuthN and AuthZ
User management ???
User sign-up and sign-in ???
API access ???
Protect static assets ???
Other AWS resources ???
What we need
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon Cognito user pools
Internet
Mobile apps
Partner
Services
Amazon Cognito
Websites
User login
Well known
OIDC check
OIDC token
API Gateway
AWS Lambda
functions
Endpoints on
Amazon EC2
Any publicly
accessible endpoint
AWS cloud
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Now Joe needs to secure the application.
Step 3: Enforce AuthN and AuthZ
User management Amazon Cognito user pool
User sign-up and sign-in Amazon Cognito user pool hosted UI
API access Amazon API gateway authorizer
Protect static assets Amazon API gateway authorizer
Other AWS resources Amazon API gateway authorizer
What we need
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Optimization & Enhancement
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
REST API vs GraphQL
Traditional data-fetching GraphQL
/posts
/postInfo
/postJustTitle
/postsByAuthor
/postNameStartsWithX
/commentsOnPost
Open, declarative data-fetching specification
!= Graph database
Use NoSQL, Relational, HTTP, etc.
GraphQL
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How does GraphQL work?
{
"id":"1",
"name":"Get Milk",
"priority":"1"
},
{
"id":“2",
"name":“Go togym",
"priority":“5"
},…
typeQuery{
getTodos:[Todo]
}
typeTodo{
id:ID!
name:String
description:String
priority:Int
duedate:String
}
query{
getTodos{
id
name
priority
}
}
Model data with
application schema
Client requests what it
needs
Only that data is
returned
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL
Schema
typeEvent{
id:ID!
name:String
where:String
when:String
description:String
comments:[Comment]
}
typeComment{
commentId:String!
eventId:ID!
content:String!
createdAt:String!
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL
Schema
Mutation
typeMutation{
createEvent(
name:String!,
when:String!,
where:String!,
description:String!
):Event
deleteEvent(id:ID!): Event
commentOnEvent(
eventId:ID!,
content:String!,
createdAt:String!
):Comment
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL
Schema
Mutation
Query
typeQuery{
getEvent(id:ID!): Event
listEvents(
limit:Int,
nextToken:String
):EventConnection
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL
Schema
Mutation
Query
Subscription
typeSubscription{
subscribeToEventComments(eventId:String!):Comment
@aws_subscribe(mutations:["commentOnEvent"])
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL
Schema
Mutation
Query
Subscription
Realtime? YES
Batching? YES
Pagination? YES
Relations? YES
Aggregations? YES
Search? YES
Offline? YES
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Introducing AWS AppSync
Managed service for application data using GraphQL with
real-time capabilities and an offline programming model
- Connect to resources in your account
- Make your data services in real time or offline
- Use AWS services with GraphQL
- Automatic sync, conflict resolution in the cloud
- Enterprise-level security features
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync
DynamoDB
Table
Lambda
Function Elasticsearch
Service
GraphQL
Schema
Upload
Schema
GraphQL
Query
Mutation
Subscription
Real-time
Online/Offline
AppSync
API
Cognito
User Pool
Legacy
Application
RDS
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync
DynamoDB
Table
Lambda
Function Elasticsearch
Service
GraphQL
Schema
GraphQL
Query
Mutation
Subscription
Real-time
Offline
AppSync
API
Cognito
User Pool
Legacy
Application
RDS
Autogenerate
Schema
Real-time
Online/Offline
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon API Gateway AWS AppSync
&
API Gateway + AppSync
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Please complete the session survey in
the summit mobile app.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!

More Related Content

Developing Serverless Application on AWS

  • 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Xiang Shen Sr. Solutions Architect, Amazon Web Services SESSION #194306 Developing Serverless Application on AWS
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What to expect from this session Serverless Overview Serverless Development Demo > > >
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Overview
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. A serverless world… Build and run applications without thinking about servers … pay per request not for idle “ Scales with usage High availability built-in Never pay for idle No servers to provision or manage “
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Building blocks for serverless applications AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon Kinesis Amazon S3 Orchestration and State Management API Proxy and GraphQL Messaging and Queues Analytics Monitoring and Debugging Compute Storage Database AWS X-RayAWS Step Functions Amazon Cognito User Management and IdP AWS AppSync Amazon Athena AWS Lambda@Edge
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. An expanding serverless community Build and CI/CD Logging and MonitoringApplications and Deployment Chalice Framework Serverless Java Container
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Development
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. A typical day for a developer… Manager “We need an app to let our customers provide feedback – our competitors just launched the same thing, so I need it fast. I don’t want to pay a lot for it, especially when no one is using it. But remember that we’re growing, so make sure it scales great and is easy to manage and operate. And you’re on your own – sorry!” Developer “Not a problem. I’ll make it serverless…”
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Joe promised his boss an app. Now what? Step 0: Requirement analysis, high level design… Step 1: Design decisions - what to use? Serverless web app with …an API ??? …access to existing data stored in ??? …static content served by ??? …dynamic content/business logic encoded as ??? What we need
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Building an API with Amazon API Gateway Internet Mobile Apps Websites Services AWS Lambda functionsAPI Gateway Cache Endpoints on Amazon EC2 All publicly accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Any other AWS service Endpoints on Amazon VPC Cognito Authorizer Lambda Authorizer API Authorization
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Accessing stored data in Amazon DynamoDB Dead Simple • GetItem(primaryKey) • PutItem(item) Amazon DynamoDB Accelerator Amazon DynamoDB Applications Amazon DynamoDB - Streams
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serving static content with S3 and Cloudfront Icon made by FlatIcon Amazon CloudFront Amazon S3
  • 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Business logic encoded in AWS Lambda SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state EVENT SOURCE FUNCTION Node.js Python Java C# Golang
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Bringing it all together… Amazon S3 Amazon CloudFront Static Content Content Delivery API Layer Application Layer Persistency Layer API Gateway Amazon DynamoDB AWS Lambda
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. A typical day for a Serverless developer… Joe promised his boss an app. Design decisions: Serverless web app with …an API hosted on Amazon API Gateway …access to existing data stored in Amazon DynamoDB …static content served by Amazon S3 and Amazon CloudFront …dynamic content/business logic encoded as Lambda functions What we need What’s next? Step 2: Find working examples and get started!
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Next, Joe needs to make some changes. Step 3: Customize and share IDE for local dev/test/debug ??? Customize the app we deployed in step 1 ??? Set up a CI/CD pipeline for the team ??? Deploy ??? What we need
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Serverless Application Model (SAM) CloudFormation extension optimized for serverless New serverless resource types: functions, APIs, and tables Supports anything CloudFormation supports Open specification (Apache 2.0)github.com/awslabs serverless-application-model
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. SAM template AWSTemplateFormatVersion:"2010-09-09" Transform:AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri:s3://sam-demo-bucket/todo_list.zip Handler:index.gethtml Runtime:nodejs6.10 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path:/{proxy+} Method:ANY ListTable: Type: AWS::Serverless::SimpleTable Tells CloudFormation this is a SAM template it needs to “transform” Creates a Lambda function with the referenced managed IAM policy, runtime, code at the referenced zip location, and handler as defined. Also creates an API Gateway and takes care of all mapping/permissions necessary Creates a DynamoDB table with 5 Read & Write units
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Introducing SAM Local CLI tool for local testing of serverless apps Works with Lambda functions and “proxy-style” APIs Response object and function logs available on your local machine Supports all native runtimes github.com/awslabs aws-sam-local
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cloud native IDE in AWS Cloud 9
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Automated CI/CD process ‘git push’ your changes from Cloud9 when ready to share… Set up an AWS CodePipeline to build automatically on updates Local Testing
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Next, Joe needs to make some changes. Step 3: Customize and share Need an IDE for local dev/test/debug – AWS Cloud 9 and AWS SAM Local Customize the app we deployed in step 1 – AWS Cloud 9 Set up a CI/CD pipeline for the team – AWS CodeStar Deploy (safely!) – SAM and CodeDeploy What we need
  • 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Now Joe needs to secure the application. Step 4: Enforce AuthN and AuthZ User management ??? User sign-up and sign-in ??? API access ??? Protect static assets ??? Other AWS resources ??? What we need
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Cognito user pools Internet Mobile apps Partner Services Amazon Cognito Websites User login Well known OIDC check OIDC token API Gateway AWS Lambda functions Endpoints on Amazon EC2 Any publicly accessible endpoint AWS cloud
  • 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Now Joe needs to secure the application. Step 3: Enforce AuthN and AuthZ User management Amazon Cognito user pool User sign-up and sign-in Amazon Cognito user pool hosted UI API access Amazon API gateway authorizer Protect static assets Amazon API gateway authorizer Other AWS resources Amazon API gateway authorizer What we need
  • 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Optimization & Enhancement
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. REST API vs GraphQL Traditional data-fetching GraphQL /posts /postInfo /postJustTitle /postsByAuthor /postNameStartsWithX /commentsOnPost Open, declarative data-fetching specification != Graph database Use NoSQL, Relational, HTTP, etc. GraphQL
  • 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How does GraphQL work? { "id":"1", "name":"Get Milk", "priority":"1" }, { "id":“2", "name":“Go togym", "priority":“5" },… typeQuery{ getTodos:[Todo] } typeTodo{ id:ID! name:String description:String priority:Int duedate:String } query{ getTodos{ id name priority } } Model data with application schema Client requests what it needs Only that data is returned
  • 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Schema typeEvent{ id:ID! name:String where:String when:String description:String comments:[Comment] } typeComment{ commentId:String! eventId:ID! content:String! createdAt:String! }
  • 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Schema Mutation typeMutation{ createEvent( name:String!, when:String!, where:String!, description:String! ):Event deleteEvent(id:ID!): Event commentOnEvent( eventId:ID!, content:String!, createdAt:String! ):Comment }
  • 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Schema Mutation Query typeQuery{ getEvent(id:ID!): Event listEvents( limit:Int, nextToken:String ):EventConnection }
  • 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Schema Mutation Query Subscription typeSubscription{ subscribeToEventComments(eventId:String!):Comment @aws_subscribe(mutations:["commentOnEvent"]) }
  • 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Schema Mutation Query Subscription Realtime? YES Batching? YES Pagination? YES Relations? YES Aggregations? YES Search? YES Offline? YES
  • 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Introducing AWS AppSync Managed service for application data using GraphQL with real-time capabilities and an offline programming model - Connect to resources in your account - Make your data services in real time or offline - Use AWS services with GraphQL - Automatic sync, conflict resolution in the cloud - Enterprise-level security features
  • 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync DynamoDB Table Lambda Function Elasticsearch Service GraphQL Schema Upload Schema GraphQL Query Mutation Subscription Real-time Online/Offline AppSync API Cognito User Pool Legacy Application RDS
  • 38. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync DynamoDB Table Lambda Function Elasticsearch Service GraphQL Schema GraphQL Query Mutation Subscription Real-time Offline AppSync API Cognito User Pool Legacy Application RDS Autogenerate Schema Real-time Online/Offline
  • 39. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon API Gateway AWS AppSync & API Gateway + AppSync
  • 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Demo
  • 41. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Please complete the session survey in the summit mobile app.
  • 42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you!