Section 11-15
Section 11: Cloud Integration 云端集成
11.1 Section Introduction
- Synchronous between applications can be problematic if there are sudden spikes of traffic
- What if you need to suddenly encode 1000 videos but usually it’s 10?
- In that case, it’s better to decouple your applications:
- using SQS: queue model
- using SNS: pub/sub model
- using Kinesis: real-time data streaming model
- These services can scale independently from our application!
11.2 Amazon SQS – Simple Queue Service 简单队列服务

- Oldest AWS offering (over 10 years old)
- Fully managed service (~serverless), use to decouple applications
- Scales from 1 message per second to 10,000s per second
- Default retention of messages: 4 days, maximum of 14 days
- No limit to how many messages can be in the queue
- Messages are deleted after they’re read by consumers. 消息在被消费者读取后被删除。
- Low latency (
<10 mson publish and receive) - Consumers share the work to read messages & scale horizontally. 消费者共享读取消息的工作并水平扩展。
11.3 Amazon Kinesis – Real-time Data Streaming

- For the exam: Kinesis = real-time big data streaming
- Managed service to collect, process, and analyze real-time streaming data at any scale. 用于在任何规模上收集,处理和分析实时流数据的托管服务。
- Too detailed for the Cloud Practitioner exam but good to know:
- Kinesis Data Streams: low latency streaming to ingest data at scale from hundreds of thousands of sources. 低延迟流,从数十万个来源中批量收集数据。
- Kinesis Data Firehose: load streams into S3, Redshift, ElasticSearch, etc…. 将流加载到 S3,Redshift,ElasticSearch 等。
- Kinesis Data Analytics: perform real-time analytics on streams using SQL. 使用 SQL 对流进行实时分析。
- Kinesis Video Streams: monitor real-time video streams for analytics or ML. 监控实时视频流以进行分析或机器学习。
11.4 Amazon SNS – Simple Notification Service 简单通知服务

- The “event publishers” only sends message to one SNS topic. 事件发布者只将消息发送到一个 SNS 主题。
- As many “event subscribers” as we want to listen to the SNS topic notifications
- Each subscriber to the topic will get all the messages. 每个订阅者都会收到所有消息。
- Up to 12,500,000 subscriptions per topic, 100,000 topics limit
11.5 Amazon MQ – Managed Message Broker 面向开源消息代理的完全托管式服务
- SQS, SNS are “cloud-native” services: proprietary protocols from AWS. SQS,SNS 是“云原生”服务:来自 AWS 的专有协议。
- Traditional applications running from on-premises may use open protocols such as: MQTT, AMQP, STOMP, Openwire, WSS
- When migrating to the cloud, instead of re-engineering the application to use SQS and SNS, we can use Amazon MQ. 当迁移到云时,我们可以使用 Amazon MQ 而不是重新设计应用程序以使用 SQS 和 SNS。
- Amazon MQ is a managed message broker service for
RabbitMQandActiveMQ - Amazon MQ doesn’t “scale” as much as SQS / SNS
- Amazon MQ runs on servers, can run in Multi-AZ with failover
- Amazon MQ has both queue feature (~SQS) and topic features (~SNS)
11.6 Integration Section – Summary
- SQS:
- Queue service in AWS. AWS 中的队列服务。
- Multiple Producers, messages are kept up to 14 days
- Multiple Consumers share the read and delete messages when done
- Used to decouple applications in AWS
- It uses a pull-based system.
- SNS:
- Notification service in AWS. AWS 中的通知服务。
- Subscribers: Email, Lambda, SQS, HTTP, Mobile…
- Multiple Subscribers, send all messages to all of them
- No message retention
- Kinesis: real-time data streaming, persistence and analysis. 实时数据流,持久化和分析。
- Amazon MQ: managed message broker for ActiveMQ and RabbitMQ in the cloud (MQTT, AMQP.. protocols). 在云中管理的消息代理,用于 ActiveMQ 和 RabbitMQ。
Section 12: Cloud Monitoring 云监控
12.1 Amazon CloudWatch – Monitoring Service
1. Amazon CloudWatch Metrics
- CloudWatch provides metrics for every services in AWS. CloudWatch 为 AWS 中的每个服务提供指标。
- Metric is a variable to monitor (CPUUtilization, NetworkIn…)
- Metrics have timestamps
- Can create CloudWatch dashboards of metrics
Important Metrics
- EC2 instances: CPU Utilization, Status Checks, Network (not RAM).
- Default metrics every 5 minutes
- Option for Detailed Monitoring ($$$): metrics every 1 minute
- EBS volumes: Disk Read/Writes
- S3 buckets: BucketSizeBytes, NumberOfObjects, AllRequests
- Billing: Total Estimated Charge (only in us-east-1)
- Service Limits: how much you’ve been using a service API
- Custom metrics: push your own metrics
2. Amazon CloudWatch Alarms
- Alarms are used to trigger notifications for any metric. 用于为任何指标触发通知的警报。
- Alarms actions…
- Auto Scaling: increase or decrease EC2 instances “desired” count
- EC2 Actions: stop, terminate, reboot or recover an EC2 instance
- SNS notifications: send a notification into an SNS topic
- Various options (sampling, %, max, min, etc…)
- Can choose the period on which to evaluate an alarm
- Example: create a billing alarm on the CloudWatch Billing metric
- Alarm States: OK. INSUFFICIENT_DATA, ALARM
3. Amazon CloudWatch Logs
- CloudWatch Logs can collect log from:
- Elastic Beanstalk: collection of logs from application
- ECS: collection from containers
- AWS Lambda: collection from function logs
- CloudTrail based on filter
- CloudWatch log agents: on EC2 machines or on-premises servers
- Route53: Log DNS queries
- Enables real-time monitoring of logs. 启用日志的实时监控。
- Adjustable CloudWatch Logs retention. 可调整的 CloudWatch 日志保留期。

- By default, no logs from your EC2 instance will go to CloudWatch. 默认情况下,您的 EC2 实例中不会有日志。
- You need to run a CloudWatch agent on EC2 to push the log files you want. 您需要在 EC2 上运行 CloudWatch 代理,以推送您想要的日志文件。
- Make sure IAM permissions are correct
- The CloudWatch log agent can be setup on-premises too EC2
12.2 Amazon EventBridge (formerly CloudWatch Events)

- Schedule: Cron jobs (scheduled scripts)
- Event Pattern: Event rules to react to a service doing something
- Trigger Lambda functions, send SQS/SNS messages…

- Schema Registry: model event schema
- You can archive events (all/filter) sent to an event bus (indefinitely or set period). 您可以存档发送到事件总线的事件(无限期或设置期限)。
- Ability to replay archived events. 能够重播存档事件。
12.3 AWS CloudTrail – Audit Service 审计服务

- Provides governance, compliance and audit for your AWS Account. 为您的 AWS 帐户提供治理,合规性和审计。
- CloudTrail is enabled by default!
- Get an history of events / API calls made within your AWS Account by: • Console • SDK • CLI • AWS Services
- Can put logs from CloudTrail into CloudWatch Logs or S3
- A trail can be applied to All Regions (default) or a single Region. 一条小径可以应用于所有区域(默认)或单个区域。
- If a resource is deleted in AWS, investigate CloudTrail first. 如果在 AWS 中删除了 资源,请首先调查 CloudTrail。
12.4 AWS X-Ray – Distributed Tracing 分析与调试分布式生产应用程序

- Debugging in Production, the good old way: • Test locally • Add log statements everywhere • Re-deploy in production
- Log formats differ across applications and log analysis is hard. 日志格式在应用程序之间有所不同,日志分析很困难。
- Debugging: one big monolith “easy”, distributed services “hard”
- No common views of your entire architecture
AWS X-Ray advantages
- Troubleshooting performance (bottlenecks)
- Understand dependencies in a microservice architecture. 在微服务架构中了解依赖关系。
- Pinpoint service issues. 确定服务问题。
- Review request behavior. 查看请求行为。
- Find errors and exceptions
- Are we meeting time SLA?
- Where I am throttled? 我在哪里受到限制?
- Identify users that are impacted. 确定影响的用户。