One of the great things about using the cloud is how easy it is to spin up resources and use them. The downside is it is really easy to spin up resources and forget about them. Sprawl becomes a real problem. You waste money if you fail to shut them down when you finish with them or even overnight. A...
One of the great things about using the cloud is how easy it is to spin up resources and use them. The downside is it is really easy to spin up resources and forget about them. Sprawl becomes a real problem. You waste money if you fail to shut them down when you finish with them or even overnight. And it isn’t just costs. Managing a cloud infrastructure can be a real pain. Who spun this up? What project is it for? Does it need to be shut down? When? Shouldn’t it be encrypted? Cloud Custodian is an easy-to-use framework that allows simple YAML files to specify how to gather, filter, and act on cloud resources across accounts and providers. Generate reports, automatically tag items, shut down non-compliant resources, or even reconfigure them to be compliant. Join Gene as he shows you how to manage your cloud resources.
Size: 2.33 MB
Language: en
Added: Oct 16, 2024
Slides: 42 pages
Slide Content
Clean Your Cloud
with Cloud Custodian
Gene Gotimer
Principal DevOps Engineer at Praeses, LLC
@OtherDevOpsGene
Why?
•Real-time compliance
•Cost control
•Governance-as-Code
@OtherDevOpsGene @techwell #agiledevopscon 2
What?
•Simple domain-specific language (DSL)
•Abstracts the API for each cloud provider
•Modify resources
•Enforce policy
•Control resources
•Generate reports
•Control account
•Across accounts
@OtherDevOpsGene @techwell #agiledevopscon 3
Where?
•Amazon Web Services (AWS)
•Microsoft Azure
•Google Cloud Platform (GCP)
•Others in beta
@OtherDevOpsGene @techwell #agiledevopscon 4
How?
•YAML files
•Cloud-specific actions, resources, and filters
•Similar syntax, but not cloud agnostic
@OtherDevOpsGene @techwell #agiledevopscon 5
Scenario: Add project tags
•We’ve been using our AWS account to stand up instances and
storage for our only project
•Another project is starting up
•We want to add tags so we know which resource belongs to which
project
@OtherDevOpsGene @techwell #agiledevopscon 8
Policy to add tags
policies:
-name: add-project-tag-to-ec2
resource: aws.ec2
actions:
-type: tag
key: project
value: cloud-custodian-demo
@OtherDevOpsGene @techwell #agiledevopscon 9
Applying a policy
$custodian validate 01-add-tags.yml
$custodian run --dry-run --output-dir=output 01-add-tags.yml
$custodian run --output-dir=output 01-add-tags.yml
@OtherDevOpsGene @techwell #agiledevopscon 10
Scenario: Add more project tags
•We’ve been using our AWS account to stand up instances and
storage for our only project
•Another project is starting up
•We want to add tags so we know which resource belongs to which
project
•We want a contact email and which group to bill for each resource
@OtherDevOpsGene @techwell #agiledevopscon 13
Scenario: Required tags
•We’ve decided on three tags all team members should use:
•project
•owner
•bill-to
•We want to stop EC2 instances from running if they are missing
those tags
@OtherDevOpsGene @techwell #agiledevopscon 17
Policy to stop if tags are missing
policies:
-name: stop-ec2-with-missing-tags
resource: aws.ec2
comment: |
Stop all EC2 instances missing any of our
required tags.
filters:
-or:
-"tag:project": absent
-"tag:owner": absent
-"tag:bill-to": absent
actions:
-stop
@OtherDevOpsGene @techwell #agiledevopscon 18
Delayed actions
•To take action in the future, use:
•action mark-for-op
•filter marked-for-op
•Apply the condition to a new tag with the op and days in the future
•Every day:
•mark-for-op if the condition isn’t met and it isn’t already marked
•remove-tag if the condition has been remedied
•act if the tag is marked-for-op
@OtherDevOpsGene @techwell #agiledevopscon 21
Scenario: Required tags, or else
•We’ve decided on three tags all team members should use:
•project
•owner
•bill-to
•We want to stop EC2 instances from running if they are missing
those tags
•We want to terminate those instances after a week
@OtherDevOpsGene @techwell #agiledevopscon 22
Control resources
@OtherDevOpsGene @techwell #agiledevopscon 30
Scenario: Shut down after hours
•We want to stop unused instances at night and on weekends
•We want them started before business hours on weekdays
•We want this opt-in
•We want the schedules to be customizable per-instance
@OtherDevOpsGene @techwell #agiledevopscon 31
Control account
@OtherDevOpsGene @techwell #agiledevopscon 33
Across accounts
@OtherDevOpsGene @techwell #agiledevopscon 34
Policies across multiple accounts
•Run with c7n-org
•Need a role to run Custodian
•Same named role in each account
•Create an accounts configuration file
•In policies, {account_id} will be automatically replaced
@OtherDevOpsGene @techwell #agiledevopscon 35
Key takeaways
•Use Cloud Custodian to manage resources.
•Tag your resources to make filtering easy.
•Use schedules to automate policies and cost controls.
@OtherDevOpsGene @techwell #agiledevopscon 39
Resources
•Cloud Custodian: https://cloudcustodian.io/
•Reference documentation
•Example policies
•Demos: https://github.com/OtherDevOpsGene/cloud-custodian
•Infrastructure-as-code for the workspace and demos
•Policies
@OtherDevOpsGene @techwell #agiledevopscon 40
Please rate
the sessions
Wednesday
Concurrent sessions
(W2) Gene Gotimer -Clean Your Cloud with Cloud Custodian
@OtherDevOpsGene @techwell #agiledevopscon 41
Questions?
Gene Gotimer
Principal DevOps Engineer at Praeses, LLC
@OtherDevOpsGene
@OtherDevOpsGene @techwell #agiledevopscon 42