

# REL01-BP01 了解服务配额和约束
<a name="rel_manage_service_limits_aware_quotas_and_constraints"></a>

 了解工作负载架构的默认配额并管理配额提高请求。了解哪些云资源约束（如磁盘或网络）可能会对您产生影响。

 **期望结果：**客户可以通过实施适当的指导方针来监控关键指标、基础设施审查和自动化修复步骤，验证是否未达到可能导致服务性能下降或中断的服务配额和约束，从而防止其 AWS 账户 中的服务性能下降或中断。

 **常见反模式：**
+ 在不了解所用服务的硬配额或软配额及其限制的情况下部署工作负载。
+ 在未分析和重新配置必要配额或未事先联系支持部门的情况下，部署替代工作负载。
+ 假设云服务没有限制，并且认为可以在不考虑费率、限制、计数、数量的情况下使用服务。
+  假设配额会自动增加。
+  不了解配额请求的流程和时间表。
+  假设每个服务的默认云服务配额在不同区域都是相同的。
+  假设可以突破服务约束，并且系统会自动扩展或提高限制以超出资源约束。
+  没有在流量高峰期测试应用程序，以便对资源的利用率进行压力测试。
+  在没有分析所需资源规模的情况下配置资源。
+  通过选择远远超出实际需求或预期峰值的资源类型来过量配置容量。
+  在新的客户事件或部署新技术之前，不评测新流量水平的容量要求。

 **建立此最佳实践的好处：**对服务配额及资源约束的监视和自动化管理可以主动减少故障。如果不遵循最佳实践，客户服务的流量模式变化可能会导致中断或性能下降。通过监视和管理所有区域和所有账户的这些值，应用程序可以在出现不利或意外事件时具有更好的韧性。

 **在未建立这种最佳实践的情况下暴露的风险等级：**高 

## 实施指导
<a name="implementation-guidance"></a>

 服务配额是一项 AWS 服务，可帮助您从一个位置管理超过 250 项 AWS 服务的配额。除了查找配额值，您还可以通过服务配额控制台或 AWS SDK 请求提高配额并跟踪配额。AWS Trusted Advisor 提供的服务配额检查功能会显示服务使用情况，以及某些服务在某些方面的配额。有关每项服务的默认服务配额，请查看相应服务的 AWS 文档（例如参阅 [Amazon VPC 配额](https://docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html)）。

 通过配置使用计划，可在 Amazon API Gateway 内设置某些服务限制，例如节流 API 的速率限制。可通过配置相应服务进行设置的部分限制包括预调配 IOPS、已分配的 Amazon RDS 存储，以及 Amazon EBS 卷分配。Amazon Elastic Compute Cloud 有自己的服务限制控制面板，可帮助您管理实例、Amazon Elastic Block Store 和弹性 IP 地址限制。如果在某应用场景中，服务配额会对应用程序的性能造成影响，而且无法按需求进行调整，请联系 支持 了解是否有解决的办法。

 服务配额可以是区域性的，也可以是全局性的。使用达到配额的 AWS 服务不会具有正常使用中预期的行为，并且可能会导致服务中断或性能下降。例如，服务配额限制了一个区域中使用的 DL Amazon EC2 实例的数量。在使用自动扩缩组（ASG）的流量扩缩事件期间，可能会达到该限制。

 应定期评测每个账户服务配额的使用情况，确定适合该账户的适当服务限制。这些服务配额作为操作防护机制存在，可防止意外地配置超出所需数量的资源；也用于限制 API 操作的请求率，保护服务不被滥用。

 服务约束与服务配额不同。服务约束代表由特定资源类型定义的该资源的限制，这些可能是存储容量（例如，gp2 的大小限制为 1 GB - 16 TB）或磁盘吞吐量。必须对资源类型的约束进行设计，并不断评测可能达到其限制的使用量。如果意外地达到约束条件，账户的应用程序或服务可能会降级或中断。

 如果在某应用场景中，服务配额对应用程序的性能造成影响，而且无法根据必要需求进行调整，请联系 支持 了解是否有解决办法。有关调整固定配额的更多详细信息，请参阅 [REL01-BP03 通过架构适应固定服务配额和约束](rel_manage_service_limits_aware_fixed_limits.md)。

 有一些 AWS 服务和工具可以帮助监视和管理服务配额。应该利用这些服务和工具来自动或手动检查配额水平。
+  AWS Trusted Advisor 提供的服务配额检查功能会显示服务使用情况，以及某些服务在某些方面的配额。该工具可以帮助识别接近配额的服务。
+  AWS 管理控制台 提供了显示服务配额值，管理、请求新配额，监视配额请求状态以及显示配额历史记录的方法。
+  AWS CLI 和 CDK 提供了通过编程方式自动管理和监视服务配额水平和使用情况的方法。

 **实施步骤** 

 服务配额：
+ 请查看 [AWS Service Quotas](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)。
+  要了解现有的服务配额，请先确定使用的服务（如 IAM Access Analyzer）。大约有 250 项 AWS 服务由服务配额控制。然后，确定每个账户和区域内可能使用的具体服务配额名称。每个区域大约有 3000 个服务配额名称。
+  使用 AWS Config 来增强此配额分析，找出 AWS 账户 中使用的所有 [AWS 资源](https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html)。
+  使用 [AWS CloudFormation 数据](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-view-stack-data-resources.html)来确定使用的 AWS 资源。查看通过 AWS 管理控制台 或 [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-stack-resources.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-stack-resources.html) AWS CLI 命令创建的资源。您还可以查看配置为要在模板自身部署的资源。
+  通过查看部署代码来确定工作负载所需的所有服务。
+  确定适用的服务配额。通过 Trusted Advisor 和服务配额使用能够以编程方式访问的信息。
+  建立自动化的监控方法（参见 [REL01-BP02 跨多个账户和区域管理服务配额](rel_manage_service_limits_limits_considered.md)和 [REL01-BP04 监控和管理配额](rel_manage_service_limits_monitor_manage_limits.md)），以便在服务配额接近或已达到限制时发出提醒和通知。
+  建立自动化的程序化方法，用于检查同一账户内某项服务配额是否在某一区域发生变更，但在其他地区未发生变更（参见 [REL01-BP02 跨多个账户和区域管理服务配额](rel_manage_service_limits_limits_considered.md)和 [REL01-BP04 监控和管理配额](rel_manage_service_limits_monitor_manage_limits.md)）。
+  自动扫描应用程序日志和指标，确定是否存在任何配额或服务约束错误。如果存在这些错误，则向监控系统发送警报。
+  确定特定服务需要更高的配额后，制定工程设计步骤来计算所需的配额变动（参见 [REL01-BP05 自动管理配额](rel_manage_service_limits_automated_monitor_limits.md)）。
+  创建一个配置和批准工作流，以请求更改服务配额。这应该包括在请求被拒绝或部分批准情况下的例外工作流。
+  创建一个工程设计方法，在配置和使用新的 AWS 服务之前，以及在推出到生产环境或加载的环境之前（例如，负载测试账户），审查服务配额。

 服务约束：
+  建立监视和度量方法，用于提醒资源接近其资源约束。适当地利用 CloudWatch 进行指标或日志监视。
+  为每个具有对应用程序或系统有意义的约束的资源建立警报阈值。
+  创建工作流和基础设施管理程序，可在约束条件接近利用率时更改资源类型。该工作流应包括负载测试作为最佳实践，可验证新类型是否为新约束条件下的正确资源类型。
+  使用现有的程序和流程，将确定的资源迁移到推荐的新资源类型。

## 资源
<a name="resources"></a>

 **相关最佳实践：**
+  [REL01-BP02 跨多个账户和区域管理服务配额](rel_manage_service_limits_limits_considered.md) 
+  [REL01-BP03 通过架构适应固定服务配额和约束](rel_manage_service_limits_aware_fixed_limits.md) 
+  [REL01-BP04 监控和管理配额](rel_manage_service_limits_monitor_manage_limits.md) 
+  [REL01-BP05 自动管理配额](rel_manage_service_limits_automated_monitor_limits.md) 
+  [REL01-BP06 确保当前配额与最大使用量之间存在足够的差距来应对失效转移](rel_manage_service_limits_suff_buffer_limits.md) 
+  [REL03-BP01 选择如何划分工作负载](rel_service_architecture_monolith_soa_microservice.md) 
+  [REL10-BP01 将工作负载部署到多个位置](rel_fault_isolation_multiaz_region_system.md) 
+  [REL11-BP01 监控工作负载的所有组件以检测故障](rel_withstand_component_failures_monitoring_health.md) 
+  [REL11-BP03 自动修复所有层](rel_withstand_component_failures_auto_healing_system.md) 
+  [REL12-BP04 使用混沌工程测试韧性](rel_testing_resiliency_failure_injection_resiliency.md) 

 **相关文档：**
+ [AWS Well-Archited Framework 的可靠性支柱：可用性](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/availability.html)
+  [AWS Service Quotas (formerly referred to as service limits)](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html) 
+  [AWS Trusted Advisor Best Practice Checks](https://aws.amazon.com/premiumsupport/technology/trusted-advisor/best-practice-checklist/)（参见“Service limits”小节） 
+  [AWS Answers 上的 AWS Limit Monitor](https://aws.amazon.com/answers/account-management/limit-monitor/) 
+  [Amazon EC2 Service Limits](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html) 
+  [What is Service Quotas?](https://docs.aws.amazon.com/servicequotas/latest/userguide/intro.html)
+ [How to Request Quota Increase](https://docs.aws.amazon.com/servicequotas/latest/userguide/request-quota-increase.html)
+ [Service endpoints and quotas](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)
+  [Service Quotas User Guide](https://docs.aws.amazon.com/servicequotas/latest/userguide/intro.html) 
+ [适用于 AWS 的配额监控程序](https://aws.amazon.com/solutions/implementations/quota-monitor/)
+ [AWS Fault Isolation Boundaries](https://docs.aws.amazon.com/whitepapers/latest/aws-fault-isolation-boundaries/abstract-and-introduction.html)
+ [Availability with redundancy](https://docs.aws.amazon.com/whitepapers/latest/availability-and-beyond-improving-resilience/availability-with-redundancy.html)
+ [AWS 数据解决方案](https://aws.amazon.com/data/)
+ [什么是持续集成？](https://aws.amazon.com/devops/continuous-integration/)
+ [什么是持续交付？](https://aws.amazon.com/devops/continuous-delivery/)
+ [APN 合作伙伴：可帮助进行配置管理的合作伙伴](https://partners.amazonaws.com/search/partners?keyword=Configuration+Management&ref=wellarchitected)
+ [Managing the account lifecycle in account-per-tenant SaaS environments on AWS](https://aws.amazon.com/blogs/mt/managing-the-account-lifecycle-in-account-per-tenant-saas-environments-on-aws/)
+ [Managing and monitoring API throttling in your workloads](https://aws.amazon.com/blogs/mt/managing-monitoring-api-throttling-in-workloads/)
+ [View AWS Trusted Advisor recommendations at scale with AWS Organizations](https://aws.amazon.com/blogs/mt/organizational-view-for-trusted-advisor/)
+ [Automating Service Limit Increases and Enterprise Support with AWS Control Tower](https://aws.amazon.com/blogs/mt/automating-service-limit-increases-enterprise-support-aws-control-tower/)

 **相关视频：**
+  [AWS Live re:Inforce 2019 - Service Quotas](https://youtu.be/O9R5dWgtrVo) 
+ [View and Manage Quotas for AWS Services Using Service Quotas](https://www.youtube.com/watch?v=ZTwfIIf35Wc)
+ [AWS IAM Quotas Demo](https://www.youtube.com/watch?v=srJ4jr6M9YQ)

 **相关工具：**
+ [Amazon CodeGuru Reviewer](https://aws.amazon.com/codeguru/)
+ [AWS CodeDeploy](https://aws.amazon.com/codedeploy/)
+ [AWS CloudTrail](https://aws.amazon.com/cloudtrail/)
+ [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/)
+ [Amazon EventBridge](https://aws.amazon.com/eventbridge/)
+ [Amazon DevOps Guru](https://aws.amazon.com/devops-guru/)
+ [AWS Config](https://aws.amazon.com/config/)
+ [AWS Trusted Advisor](https://aws.amazon.com/premiumsupport/technology/trusted-advisor/)
+ [AWS CDK](https://aws.amazon.com/cdk/)
+ [AWS Systems Manager](https://aws.amazon.com/systems-manager/)
+ [AWS Marketplace](https://aws.amazon.com/marketplace/search/results?searchTerms=CMDB)