基于无服务器的架构落地与实践

微风

2019/03/24 发布于 技术 分类

文字内容
1. 基于无服务器的架构落地与实践 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3. 日程 • • • 什么是无服务器架构 无服务器的设计模式和使用案例 无服务器的缺陷和未来 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
4. 无服务器 = 不用服务器的黑科技? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
5. 无服务器 = 不用管理服务器? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
6. 无服务器架构是为了最大化创新 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
7. 什么时候一个服务是无服务器化的? 不用管理服务器 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 弹性 高可用和容错 不为闲置付费
8. AWS Lambda © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
9. Lambda的代码 { “Records”:[ “s3”: { “object”:” { … } } ] } AWS Context exports.handler = function (event, context, callback) { console.log(‘Event: ‘ + JSON.stringify (event)) callback(null, ‘Hello World!’) } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
10. 弹性 增加您的并 发执行函数 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
11. 有没有其他的无服务器组件? Compute Storage AWS Lambda API Proxy Database Amazon S3 Messaging and Queues Amazon DynamoDB Analytics Amazon SQS Amazon API Gateway Amazon Kinesis Amazon SNS Orchestration and State Management AWS Step Functions © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Monitoring and Debugging AWS X-Ray
12. 回顾一下 不用管理服务器 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 弹性 高可用和容错 不为闲置付费
13. 设计模式和使用案例 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
14. 模式1: 微服务化 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
15. Web后端框架 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
16. 相应的serverless工具 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
17. 这些工具是如何工作的 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
18. 在lambda中做代理 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
19. 单体应用后台 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
20. Lambda的生命周期 解冻 执行 需要增加 并发函数 等待 启动Lambda容器 冷冻 回收 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
21. Lambda的初始化 下载 代码 启动 容器 初始化 运行环境 热启动 冷启动 AWS 负责优化 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 运行 代码 您负责优化
22. 多个 功能1 vs. API Gateway 功能2 … • • Lambda中不用管理Routing 解耦 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. API Gateway • • • 所有功能 维护更少的lambda 部署影响所有功能 一个lambda可能变得很大
23. 微服务化 单体 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 微服务化
24. 模式2: 事件驱动 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
25. 同步(推送) Amazon API Gateway /order AWS Lambda function © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
26. 异步 (拉取) Amazon SNS queue Amazon S3 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Lambda function
27. 流处理 Amazon DynamoDB Record reader changes Amazon Kinesis © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. function
28. 举个例子 • • • • 用户上传文件 通知文件/关注话题更新 搜索文件 短信唤醒用户 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
29. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
31. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
32. 模式3: 组件重用 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
33. 一个表单修改的事件流 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
34. 如果再多一点。。 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
35. 代码重用 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
36. 创建APP App App App App © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
37. SAM © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
38. APP例子:数据库拷贝 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
39. 配置文件 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
40. 模式4: 状态机 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
41. Queue λ λ λ λ λ λ λλ λ λ λ λ © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DBMS
42. Step Function JSON定义 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 可视化 监控运行情况
43. 举个例子 Vendor A Vendor B Vendor C © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
44. 状态机的状态 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
45. 模式 微服务化 事件驱动 组件重用 状态机 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
46. 常见应用场景 网站应用 后台 数据处理 • 静态网站 • 应用和服务 • 实时 • 复杂网站 • 移动端 • MapReduce • Flask and Express • IoT • 批处理 • 二进制文件处 理 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • 处理聊天逻辑 IT自动化 Alexa 聊天机器人 • Alexa 技能 • 策略引擎 • 延伸AWS服务 功能 • 管理Infra
47. 无服务器现存的缺点 • 冷启动 • 运行时间限制 • 更丰富的无服务器服务 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
48. 再看一下 不用管理服务器 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 弹性 高可用和容错 不为闲置付费
49. 无服务器架构是为了最大化创新 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
50. 可见的成本 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
51. Lambda性能优化 优化前:200秒 11.2美分 优化后:95秒 2.8美分 # Download and process all keys for key in src_keys:'>keys: response = s3_client.get_object(Bucket=src_bucket, Key=key) # Select IP Address and Keys for key in src_keys:'>keys: response = s3_client.select_object_content (Bucket=src_bucket, Key=key, expression = SELECT SUBSTR(obj._1, 1, 8), obj._2 FROM s3object as obj) contents = response['Body'].read() for line in contents: line_count +=1 try:'>try: …. contents = response['Body'].read() for line in contents.split('\n')[:-1]: line_count +=1 try:'>try: data = line.split(',') srcIp = data[0][:8] …. © AmazonWeb WebServices, Services, or Affiliates. its Affiliates. rights reserved. © 2018, 2017, Amazon Inc.Inc. or its All All rights reserved.
52. © AmazonWeb WebServices, Services, or Affiliates. its Affiliates. rights reserved. © 2018, 2017, Amazon Inc.Inc. or its All All rights reserved.
53. © AmazonWeb WebServices, Services, or Affiliates. its Affiliates. rights reserved. © 2018, 2017, Amazon Inc.Inc. or its All All rights reserved.
54. 总结 无服务器架构的 设计模式 什么是无服务器 • 不用管理服务 器 • 可靠 • 弹性 • 不用为闲置付 费 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • • • • 微服务 事件驱动 组件重用 状态机 无服务器未来 • 弹性 • 成本优化 • 敏捷创新