AWS CloudFormation 시작하기
Source: Dev.to

Introduction
Infrastructure as Code (IaC)는 클라우드 리소스를 관리하고 배포하는 방식을 혁신했습니다. AWS CloudFormation은 이 분야에서 가장 강력한 도구 중 하나로, 개발자와 DevOps 엔지니어가 선언형 템플릿을 사용해 전체 인프라를 정의할 수 있게 해줍니다.
What is AWS CloudFormation?
AWS CloudFormation은 Amazon Web Services 리소스를 모델링하고 설정하는 데 도움을 주는 서비스로, 리소스 관리에 드는 시간을 줄이고 애플리케이션에 더 집중할 수 있게 해줍니다.
Business Value
Cost Reduction
- Reduced Manual Errors: 수동 인프라 프로비저닝에서 발생하는 비용이 많이 드는 실수를 없앱니다.
- Faster Time-to-Market: 환경을 며칠·몇 주가 아니라 몇 분 안에 배포합니다.
- Resource Optimization: 사용되지 않는 리소스를 자동으로 종료해 비용 초과를 방지합니다.
- Predictable Budgeting: 템플릿 기반 배포는 일관된 비용 추정치를 제공합니다.
Operational Efficiency
- Team Productivity: DevOps 팀이 반복 작업보다 혁신에 집중할 수 있습니다.
- Compliance Assurance: 내장된 거버넌스를 통해 모든 배포가 보안 표준을 충족하도록 보장합니다.
- Disaster Recovery: 장애 발생 시 템플릿을 사용해 전체 환경을 신속히 재생성합니다.
- Audit Trail: 규제 준수 및 문제 해결을 위한 완전한 변경 이력을 제공합니다.
Scalability Benefits
- Multi‑Region Deployment: 전 세계 여러 리전에서 인프라를 손쉽게 복제합니다.
- Environment Parity: 개발, 스테이징, 프로덕션 환경이 동일하도록 보장합니다.
- Rapid Scaling: 수요 패턴에 따라 리소스를 자동으로 프로비저닝합니다.
Why CloudFormation
- Consistency: 여러 환경에 동일한 인프라를 배포합니다.
- Version Control: 인프라 변경 사항을 시간에 따라 추적합니다.
- Rollback Capability: 실패한 배포를 자동으로 롤백합니다.
- Cost Management: 비용을 쉽게 추정하고 리소스 사용량을 추적합니다.
CloudFormation Template Structure
AWSTemplateFormatVersion: '2010-09-09'
Description: 'A sample CloudFormation template'
Parameters:
# Input parameters for the template
Resources:
# AWS resources to create
Outputs:
# Values to return after stack creation
Your First CloudFormation Template
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Simple S3 bucket creation'
Parameters:
BucketName:
Type: String
Description: Name for the S3 bucket
Default: my-cloudformation-bucket
Resources:
MyS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref BucketName
VersioningConfiguration:
Status: Enabled
Outputs:
BucketName:
Description: 'Name of the created S3 bucket'
Value: !Ref MyS3Bucket
Actionable Tips
- Use Parameters and Mappings – 템플릿을 유연하고 재사용 가능하게 만드세요.
- Implement Proper Naming – 일관된 명명 규칙을 사용하세요.
- Add Documentation – 상세한 설명을 포함하세요.
- Use Cross‑Stack References – 스택 간에 값을 내보내고 가져오세요.
- Implement Rollback Triggers – CloudWatch 알람을 설정하세요.
Deployment Strategies
Blue‑Green Deployments
Resources:
BlueEnvironment:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: blue-targets
Rolling Updates
Resources:
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 2
Wrapping it Up
AWS CloudFormation은 인프라 관리에 일관성, 신뢰성, 확장성을 제공합니다. 간단한 템플릿으로 시작해 점차 복잡성을 높이며 CloudFormation의 기능에 익숙해지세요.
References
- AWS CloudFormation Documentation – CloudFormation Docs
- AWS CloudFormation Template Reference – Template Reference
- AWS CloudFormation Best Practices – Best Practices Guide
- AWS Well‑Architected Framework – Well‑Architected
- Infrastructure as Code: Managing Servers in the Cloud – Kief Morris, O’Reilly Media
- AWS CloudFormation Sample Templates – AWS Labs Templates
- AWS CloudFormation Linter (cfn‑lint) – cfn‑lint GitHub
- AWS CloudFormation Guard – Guard GitHub