Sub topic 13
Enforcing limits with cluster policies
This chapter assumes you know how to create a cluster, set autoscaling bounds, and set auto-termination. Here you will learn how a cluster policy makes those settings binding for a group of users.
What a policy does
A cluster policy is a set of rules attached to cluster creation. Each rule targets one cluster attribute and says what values are allowed. Users who have access to a policy can only create clusters that satisfy it. Attributes the policy fixes or hides do not appear in the creation form, and values outside the allowed range are rejected.
Policies turn the guidance from earlier chapters into guardrails. Autoscaling limits cap spend, and auto-termination stops idle clusters. A policy makes sure nobody can raise one or switch off the other.
Writing a policy definition
A definition is a JSON object. Each key is an attribute path, such as autoscale.max_workers, and each value is a rule.
{
"autoscale.max_workers": {
"type": "range",
"maxValue": 8,
"defaultValue": 4
},
"autotermination_minutes": {
"type": "range",
"minValue": 10,
"maxValue": 120,
"defaultValue": 30
}
}With this policy, a user can choose up to 8 maximum workers, and the form starts at 4. Auto-termination must be between 10 and 120 minutes, and the form starts at 30. A request for 16 workers or a 240-minute timeout fails validation.
Common rule types:
| Type | Effect |
|---|---|
| `fixed` | Sets the value. The user cannot change it. |
| `range` | Allows numbers between `minValue` and `maxValue`. |
| `allowlist` | Allows only values from a list, such as approved node types. |
| `blocklist` | Rejects values from a list. |
| `unlimited` | Applies no limit, but can set a default or make the field required. |
Where policies fit
An administrator grants each user or group permission to use specific policies. Someone with only a policy's permission can create clusters through that policy. Make sure users do not also have unrestricted cluster creation permission, because that lets them bypass the policy.
Designing useful policies
- Cap the maximum, not the minimum. A range on
autoscale.max_workerslimits the worst-case bill and still lets users size down. - Allowlist node types. Offer a few families matched to the workload profiles, such as memory-optimized for ETL, instead of every instance type.
- Fix the spot setting where it is safe. For batch ETL, you can fix
aws_attributes.availabilitytoSPOT_WITH_FALLBACKandaws_attributes.first_on_demandto 1. - Keep one policy per workload class. A policy for interactive work and one for scheduled jobs are easier to reason about than one policy with many exceptions.
- Set sensible defaults. Most users accept the default, so the default effectively decides typical cost.
Common mistakes
- Setting
maxValueso low that legitimate jobs cannot finish, which leads users to ask for exceptions or work around the policy. - Fixing
num_workersin a policy while users expect autoscaling. Fixed and autoscale attributes are separate paths, so constrain the ones you intend to use. - Forgetting to remove unrestricted creation rights from users.
Exercise
You want scheduled ETL clusters to autoscale with at most 10 workers, terminate after 15 to 60 idle minutes, and use only i3.xlarge or i3.2xlarge. Which rule types do you use for each of the three attributes?
Show answer
Use range with maxValue 10 for autoscale.max_workers. Use range with minValue 15 and maxValue 60 for autotermination_minutes. Use allowlist with the two instance types for node_type_id.