AWS Learning
Monitoring & Management

AWS OpsWorks

Configuration Management, Chef/Puppet, Stacks, Layers

Tổng quan

AWS OpsWorks là dịch vụ configuration management cho phép quản lý servers bằng Chef hoặc Puppet.

┌──────────────────────────────────────────────────────────────────────────────┐
│                         AWS OpsWorks là gì?                                  │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   Configuration Management = Tự động hóa việc cấu hình servers               │
│                                                                              │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │  MANUAL (Không có OpsWorks)                                         │    │
│   │  ─────────────────────────                                          │    │
│   │  • SSH vào từng server                                              │    │
│   │  • Cài đặt packages thủ công                                        │    │
│   │  • Cấu hình app thủ công                                            │    │
│   │  • Repeat cho mỗi server mới                                        │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                              ▼                                               │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │  AUTOMATED (Với OpsWorks)                                           │    │
│   │  ─────────────────────────                                          │    │
│   │  • Viết recipes/manifests một lần                                   │    │
│   │  • OpsWorks tự động apply lên tất cả servers                        │    │
│   │  • Consistent configuration                                         │    │
│   │  • Version controlled                                               │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Chef vs Puppet

ToolLanguageFiles
ChefRuby DSLRecipes, Cookbooks
PuppetPuppet DSLManifests, Modules

Cả hai đều làm cùng việc: Định nghĩa infrastructure as code để tự động configure servers.


3 Loại OpsWorks

┌──────────────────────────────────────────────────────────────────────────────┐
│                         3 Flavors của OpsWorks                               │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   1. OpsWorks STACKS                                                         │
│      ─────────────────                                                       │
│      • AWS-managed Chef (embedded)                                           │
│      • Dùng Chef recipes                                                     │
│      • Organize apps into layers                                             │
│      • Legacy - ít dùng cho projects mới                                     │
│                                                                              │
│   2. OpsWorks for CHEF AUTOMATE                                              │
│      ────────────────────────────                                            │
│      • Fully managed Chef server                                             │
│      • Full Chef ecosystem                                                   │
│      • Chef Automate features                                                │
│                                                                              │
│   3. OpsWorks for PUPPET ENTERPRISE                                          │
│      ──────────────────────────────                                          │
│      • Fully managed Puppet master                                           │
│      • Full Puppet Enterprise features                                       │
│      • Puppet manifests & modules                                            │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
LoạiChef/PuppetManaged byBest for
StacksChef (embedded)AWSLegacy apps, simple use cases
Chef AutomateFull ChefAWSTeams đã dùng Chef
Puppet EnterpriseFull PuppetAWSTeams đã dùng Puppet

OpsWorks Stacks

Kiến trúc

┌──────────────────────────────────────────────────────────────────────────────┐
│                         OpsWorks Stacks Architecture                         │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   STACK (= Your Application)                                                 │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │                                                                     │    │
│   │   LAYER: Load Balancer                                              │    │
│   │   ┌──────────────────────────────────────────────────────────┐       │   │
│   │   │  ELB (auto-configured)                                   │       │   │
│   │   └──────────────────────────────────────────────────────────┘       │   │
│   │                              │                                       │   │
│   │   LAYER: Application Servers ▼                                      │    │
│   │   ┌──────────────────────────────────────────────────────────┐       │   │
│   │   │  ┌──────┐  ┌──────┐  ┌──────┐                            │       │   │
│   │   │  │ EC2  │  │ EC2  │  │ EC2  │   ← Chef recipes applied  │        │   │
│   │   │  └──────┘  └──────┘  └──────┘                            │       │   │
│   │   └──────────────────────────────────────────────────────────┘       │   │
│   │                              │                                       │   │
│   │   LAYER: Database            ▼                                      │    │
│   │   ┌──────────────────────────────────────────────────────────┐       │   │
│   │   │  RDS MySQL                                               │       │   │
│   │   └──────────────────────────────────────────────────────────┘       │   │
│   │                                                                     │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Các thành phần

ComponentMô tả
StackContainer cho toàn bộ application
LayerNhóm instances có cùng purpose (web, app, db)
InstanceEC2 instances trong layer
AppCode được deploy lên instances
RecipesChef scripts định nghĩa configuration

Lifecycle Events

OpsWorks Stacks tự động chạy recipes tại các events:

EventKhi nàoVí dụ
SetupInstance khởi động lần đầuInstall packages
ConfigureInstance join/leave stackUpdate config files
DeployDeploy appPull code, restart service
UndeployRemove appClean up files
ShutdownInstance stoppingGraceful shutdown

OpsWorks for Chef Automate

┌──────────────────────────────────────────────────────────────────────────────┐
│                    OpsWorks for Chef Automate                                │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   AWS-managed Chef Server                                                    │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │                                                                     │    │
│   │   Chef Automate Server (Managed by AWS)                             │    │
│   │   ┌─────────────────────────────────────────────────────────────┐    │   │
│   │   │  • Chef Infra Server                                        │    │   │
│   │   │  • Chef Automate (compliance, visibility)                   │    │   │
│   │   │  • Automatic backups                                        │    │   │
│   │   │  • Patching handled by AWS                                  │    │   │
│   │   └─────────────────────────────────────────────────────────────┘    │   │
│   │                              │                                       │   │
│   │              ┌───────────────┼───────────────┐                       │   │
│   │              ▼               ▼               ▼                      │    │
│   │         ┌────────┐      ┌────────┐      ┌────────┐                   │   │
│   │         │ Node 1 │      │ Node 2 │      │ Node 3 │                   │   │
│   │         │ (EC2)  │      │ (EC2)  │      │On-prem │                   │   │
│   │         │chef-cli│      │chef-cli│      │chef-cli│                   │   │
│   │         └────────┘      └────────┘      └────────┘                   │   │
│   │                                                                     │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                                                                              │
│   ✅ Supports EC2 và On-premises servers                                     │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

OpsWorks for Puppet Enterprise

┌──────────────────────────────────────────────────────────────────────────────┐
│                    OpsWorks for Puppet Enterprise                            │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   AWS-managed Puppet Master                                                  │
│   ┌─────────────────────────────────────────────────────────────────────┐    │
│   │                                                                     │    │
│   │   Puppet Enterprise Master (Managed by AWS)                         │    │
│   │   ┌─────────────────────────────────────────────────────────────┐    │   │
│   │   │  • Puppet Master                                            │    │   │
│   │   │  • Puppet Console (GUI)                                     │    │   │
│   │   │  • Automatic backups                                        │    │   │
│   │   │  • Patching handled by AWS                                  │    │   │
│   │   └─────────────────────────────────────────────────────────────┘    │   │
│   │                              │                                       │   │
│   │         Puppet Agents connect to Master                             │    │
│   │              ┌───────────────┼───────────────┐                       │   │
│   │              ▼               ▼               ▼                      │    │
│   │         ┌────────┐      ┌────────┐      ┌────────┐                   │   │
│   │         │ Agent  │      │ Agent  │      │ Agent  │                   │   │
│   │         │ (EC2)  │      │ (EC2)  │      │On-prem │                   │   │
│   │         └────────┘      └────────┘      └────────┘                   │   │
│   │                                                                     │    │
│   └─────────────────────────────────────────────────────────────────────┘    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

So sánh các Configuration Management Tools

ToolLanguageModelAWS Service
ChefRubyPull (agent)OpsWorks Stacks, OpsWorks for Chef
PuppetPuppet DSLPull (agent)OpsWorks for Puppet
AnsibleYAMLPush (agentless)❌ Không có managed service
SSMJSON/YAMLPushAWS Systems Manager
┌──────────────────────────────────────────────────────────────────────────────┐
│                      Push vs Pull Model                                      │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   PULL MODEL (Chef, Puppet):                                                 │
│   ─────────────────────────                                                  │
│   ┌──────────┐         ┌────────┐                                            │
│   │  Master  │◄────────│ Agent  │  Agent chủ động "pull" config từ master    │
│   │  Server  │         │ (Node) │  Mỗi 30 phút (configurable)                │
│   └──────────┘         └────────┘                                            │
│                                                                              │
│   PUSH MODEL (Ansible, SSM):                                                 │
│   ──────────────────────────                                                 │
│   ┌──────────┐         ┌────────┐                                            │
│   │ Control  │────────►│  Node  │  Control node "push" config khi run        │
│   │  Node    │ SSH/WinRM│        │  Không cần agent                          │
│   └──────────┘         └────────┘                                            │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

OpsWorks vs Các AWS Services khác

ServicePurposeUse When
OpsWorksConfiguration management (Chef/Puppet)Đã có Chef/Puppet code
Elastic BeanstalkDeploy apps (managed platform)Muốn đơn giản, không cần Chef/Puppet
CloudFormationProvision infrastructureInfrastructure as Code
Systems ManagerManage & patch serversNative AWS, không cần Chef/Puppet
CodeDeployDeploy applicationsCI/CD pipelines

Khi nào dùng OpsWorks?

ScenarioService
Đã có Chef cookbooks sẵnOpsWorks
Đã có Puppet manifests sẵnOpsWorks
Muốn migrate từ on-prem Chef/PuppetOpsWorks
Mới bắt đầu, muốn đơn giảnElastic Beanstalk hoặc SSM
Muốn AWS nativeSystems Manager

Use Cases

Use CaseMô tả
Migrate Chef/PuppetMove existing Chef/Puppet to AWS
Hybrid infrastructureManage EC2 + on-premises
ComplianceEnforce consistent configs
Application deploymentDeploy multi-tier apps

Exam Tips

[!IMPORTANT] Các điểm quan trọng cho AWS Certification:

1. Nhớ keywords

KeywordService
Chef, Recipes, CookbooksOpsWorks
Puppet, ManifestsOpsWorks
Configuration managementOpsWorks

2. 3 Flavors

TypeQuick description
StacksLegacy, embedded Chef
Chef AutomateFull managed Chef server
Puppet EnterpriseFull managed Puppet master

3. So sánh nhanh

Câu hỏiĐáp án
Có sẵn Chef cookbooks?OpsWorks
Có sẵn Puppet manifests?OpsWorks
Muốn managed Chef server?OpsWorks for Chef Automate
Chưa có Chef/Puppet, muốn đơn giản?Elastic Beanstalk hoặc SSM
Provision infrastructure?CloudFormation

4. Important notes

  • OpsWorks supports on-premises servers (hybrid)
  • OpsWorks Stacks is legacy - AWS recommends newer services
  • OpsWorks = Configuration | CloudFormation = Provisioning

Tài liệu tham khảo