Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developing Serverless Application on AWS

362 views

Published on

Serverless computing allows developers to build and run applications and services without thinking about servers. In this session, we are going to discuss how to use AWS developer tools and services including AWS CodeStar, AWS SAM (Serverless Application Model), AWS Cloud9, Amazon Cognito and AWS AppSync to help developers developing secure and scalable serverless applications. It will cover key concepts, best practices, and developer's workflow.

  • Login to see the comments

Developing Serverless Application on AWS

  1. 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. 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What to expect from this session Serverless Overview Serverless Development Demo > > >
  3. 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Overview
  4. 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. 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. 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. 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Development
  8. 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. 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. 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. 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. 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. 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. 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. 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. 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  17. 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  18. 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. 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. 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. 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. 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cloud native IDE in AWS Cloud 9
  23. 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. 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. 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. 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. 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. 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Optimization & Enhancement
  29. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 39. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon API Gateway AWS AppSync & API Gateway + AppSync
  40. 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Demo
  41. 41. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Please complete the session survey in the summit mobile app.
  42. 42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you!

×