AWS CloudFormation์ด๋ ?
AWS์์ ์ธํ๋ผ๋ฅผ ์ฝ๋๋ก(Infrastructure as Code, IaC) ๊ด๋ฆฌํ ์ ์๋ ์๋น์ค์ด๋ค.
CloudFormation์ ์ฌ์ฉํ๋ฉด ์ธํ๋ผ ๋ฆฌ์์ค๋ฅผ ํ
์คํธ ํ์ผ(ํ
ํ๋ฆฟ)๋ก ์ ์ํ๊ณ , ์ด๋ฅผ ํตํด AWS ๋ฆฌ์์ค(์: EC2 ์ธ์คํด์ค, S3 ๋ฒํท, RDS ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ฑ)๋ฅผ ์๋์ผ๋ก ์์ฑ, ๊ด๋ฆฌ, ์
๋ฐ์ดํธํ ์ ์๋ค.
CloudFormation ํ ํ๋ฆฟ์ ์ฌ์ฌ์ฉํ์ฌ ๋ฆฌ์์ค๋ฅผ ์ผ๊ด๋๊ณ ๋ฐ๋ณต์ ์ผ๋ก ์์ฑ ๊ฐ๋ฅํ๋ค.
์ฆ, ์ธํ๋ผ๋ฅผ ๊ตฌ์ฑํ๋ ์๊ฐ๊ณผ ๊ณผ์ ์ ๋จ์ถ์์ผ์ค๋ค !
โณ๏ธ EC2 ์ธ์คํด์ค ์์ฑ ํ ํ๋ฆฟ ์์
AWSTemplateFormatVersion: "2010-09-09"
Description: "AWS CloudFormation Template to create an EC2 instance"
Resources:
MyEC2Instance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: "t2.micro"
ImageId: "ami-0abcdef1234567890"
โณ๏ธ ์๋ ๋ฐฉ์
- ํ ํ๋ฆฟ์ ์์ฑํด AWS ๋ฆฌ์์ค์ ํด๋น ์์ฑ์ ๋ํด ์ค๋ช ํ๊ณ ์คํ์ ์์ฑํ๋ค.
- ์คํ์ ์์ฑํ ๋๋ง๋ค CloudFormation์์ ํ ํ๋ฆฟ์ ์ค๋ช ๋ ๋ฆฌ์์ค๋ฅผ ํ๋ก๋น์ ๋ํ๋ค.
ํ ํ๋ฆฟ
JSON ๋๋ YAML ํ์์ ํ ์คํธ ํ์ผ๋ก AWS ๋ฆฌ์์ค ๊ตฌ์ถ์ ์ํ ์ฒญ์ฌ์ง
๐ํ ํ๋ฆฟ์์ ์ธ์คํด์ค ์ ํ, AMI ID, ๋ธ๋ก ๋๋ฐ์ด์ค ๋งคํ, Amazon EC2 ํค ํ์ด ์ด๋ฆ ๋ฑ๊ณผ ๊ฐ์ Amazon EC2 ์ธ์คํด์ค๋ฅผ ์ค๋ช
- ํ ํ๋ฆฟ์ด ์ ์ฅ๋๋ ์์น๋ Amazon S3 ๋ฒํท ๋๋ Git ๋ฆฌํฌ์งํ ๋ฆฌ
ํ ํ๋ฆฟ ์น์
๋ชจ๋ CloudFormation ํ ํ๋ฆฟ์ ํ๋ ์ด์์ ์น์ ์ผ๋ก ๊ตฌ์ฑ๋๋ฉฐ, ๊ฐ ์น์ ์๋ ํน์ ํ ๋ชฉ์ ์ด ์๋ค
โณ๏ธ ํ ํ๋ฆฟ ์น์
---
AWSTemplateFormatVersion: version date
Description:
String
Metadata:
template metadata
Parameters:
set of parameters
Rules:
set of rules
Mappings:
set of mappings
Conditions:
set of conditions
Transform:
set of transforms
Resources:
set of resources
Outputs:
set of outputs
- Resources
- CloudFormation ํ ํ๋ฆฟ์ ํ์ํ๊ณ ํ ํ๋ฆฟ์ ํต์ฌ์ ๊ตฌ์ฑ
- Amazon EC2 ์ธ์คํด์ค ๋๋ Amazon S3 ๋ฒํท ๊ฐ์ ์คํ ๋ฆฌ์์ค ๋ฐ ํด๋น ์์ฑ์ ์ง์
- ๊ฐ ๋ฆฌ์์ค๋ ๊ณ ์ ํ ๋ ผ๋ฆฌ์ ID, ์ ํ ๋ฐ ํน์ ๊ตฌ์ฑ ์ธ๋ถ ์ ๋ณด๋ก ์ ์
Resources:
LogicalResourceName1:
Type: AWS::ProductIdentifier::ResourceType
Properties:
PropertyName1: PropertyValue1
...
LogicalResourceName2:
Type: AWS::ProductIdentifier::ResourceType
Properties:
PropertyName1: PropertyValue1
...
- ๊ฐ ๋ฆฌ์์ค์๋ Type ์์ฑ์ด ์์ด์ผ ํ๋ฉฐ, ์ด ์์ฑ์ AWS ๋ฆฌ์์ค์ ์ข
๋ฅ๋ฅผ ์ ์
๐Amazon S3 ๋ฒํท์ Type ์์ฑ์ AWS::S3::Bucket
๐ ๋ฆฌ์์ค ๋ฐ ์์ฑ ์ฐธ์กฐ
- ์ฐธ์กฐ ๋ฆฌ์์ค๋ก ๋์ผํ CloudFormation ํ
ํ๋ฆฟ ๋ด์ ์ ์๋ ๋ฆฌ์์ค์ ์๋ณ ์์ฑ์ ๊ฒ์
๐ Ref ํจ์ ์ฌ์ฉ
Properties:
PropertyName1:
Ref: LogicalResourceName
PropertyName2: !Ref LogicalResourceName
- Parameters
- ์ ํ ์ฌํญ์ด์ง๋ง ํ ํ๋ฆฟ์ ๋ณด๋ค ์ ์ฐํ๊ฒ ๋ง๋๋ ๋ฐ ์ค์ํ ์ญํ
- ๋ฐฐํฌ๋ง๋ค ๋ฌ๋ผ์ง๋ ์ธ์คํด์ค ์ ํ์ด๋ ํ๊ฒฝ ์ค์ ์ ์ง์
Parameters:
ParameterLogicalID:
Description: Information about the parameter
Type: DataType
Default: value
AllowedValues:
- value1
- value2
- Outputs
- ์คํ์ ์์ฑ์ ๋ณผ ๋ ๋ฐํ๋๋ ๊ฐ์ ์ ์
- ๋ฆฌ์์ค ์๋ณ์ ๋๋ URL๊ณผ ๊ฐ์ ์ ์ฉํ ์ ๋ณด๋ฅผ ์ ๊ณต
Outputs:
Logical ID of resource:
Description: Information about the value
Value: Value to return
Export:
Name: Name of resource to export
ํ ํ๋ฆฟ ๋ด์ฅํจ์
ํ ๋ด์์ ์ฌ์ฉํ๊ณ ์๋ ๋ด์ฅํจ์ ์์ฃผ๋ก ์ ๋ฆฌ
- Fn::ImportValue
- ๋ค๋ฅธ ์คํ์์ ๋ด๋ณด๋ธ ์ถ๋ ฅ๊ฐ ๋ฐํ
- Fn::ImportValue: sharedValueToImport ๐ ํจ์ ์ ์ฒด
!ImportValue sharedValueToImport ๐ ์งง์ ํ์
Fn::ImportValue:
!Sub "${NetworkStackName}-SecurityGroupID"
โ !Sub์ ์งง์ ํ์์ด ํฌํจ๋๋ฉด !ImportValue์ ์งง์ ํ์ ์ฌ์ฉ ๋ถ๊ฐ !
- Fn::Join
- ์ง์ ๋ ๊ตฌ๋ถ ๊ธฐํธ๋ก ๊ตฌ๋ถ๋ ๊ฐ ์ธํธ๋ฅผ ๋จ์ผ ๊ฐ์ ์ถ๊ฐ
- ๊ตฌ๋ถ ๊ธฐํธ๊ฐ ๋น ๋ฌธ์์ด์ด๋ฉด ๊ฐ ์ธํธ๋ ๊ตฌ๋ถ ๊ธฐํธ ์์ด ์ฐ๊ฒฐ๋จ
- Fn::Join: [ delimiter, [ comma-delimited list of values ] ] ๐ ํจ์ ์ ์ฒด
!Join [ delimiter, [ comma-delimited list of values ] ] ๐ ์งง์ ํ์ - delimiter : ์กฐ๊ฐ ๋ ๊ฐ ์ฌ์ด์์ ๋ฐ์ํ๊ธธ ์ํ๋ ๊ฐ
- ListOfValues : ๊ฒฐํฉํ๋ ค๋ ๊ฐ ๋ชฉ๋ก
!Join [ '', [ 'arn:aws:codepipeline:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':', !Ref CodePipelineProject ] ]
!Join
- ''
- - 'arn:'
- !Ref AWS::Partition
- ':s3:::elasticbeanstalk-*-'
- !Ref AWS::AccountId
๐ Ref ํจ์์ ์ฌ์ฉํด์ ์ฐ๊ฒฐํ ์์
๐ arn:aws:s3:::elasticbeanstalk-us-east-1-123456789012
- ์ฒซ๋ฒ์งธ ์ธ์๋ ๊ตฌ๋ถ์๋ก, ์์์์๋ ๋น๋ฌธ์์ด('')์ด๋ฏ๋ก ๊ฒฐํฉ๋ ๋ฌธ์์ด ์ฌ์ด์ ์ถ๊ฐ์ ์ธ ๋ฌธ์๊ฐ ๋ค์ด๊ฐ์ง ์์
- !Ref๋ CloudFormation์์ ํน์ ๊ฐ์ ์ฐธ์กฐํ๋ ํจ์
- 'elasticbeanstalk-*-' ์ ์์ผ๋์นด๋(*)๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ์ ๋ช ์ ๋์ ์ผ๋ก ์ฒ๋ฆฌ
- Fn::Sub
- ์ ๋ ฅ ๋ฌธ์์ด์ ๋ณ์๋ฅผ ์ง์ ํ ๊ฐ์ผ๋ก ๋ฐ๊ฟ
Fn::Sub:
- String
- Var1Name: Var1Value
Var2Name: Var2Value
!Sub
- String
- Var1Name: Var1Value
Var2Name: Var2Value
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Sub "SSH security group for ${AWS::StackName}"
- Ref
- ์ง์ ๋ ํ๋ผ๋ฏธํฐ ๋๋ ๋ฆฌ์์ค์ ๋ํ ์ ๋ณด๋ฅผ ๋ฐํ
- Ref: logicalName ๐ ํจ์ ์ ์ฒด
!Ref logicalName ๐ ์งง์ ํ์
MyEIP:
Type: "AWS::EC2::EIP"
Properties:
InstanceId: !Ref MyEC2Instance
์ฐธ๊ณ ์๋ฃ
https://docs.aws.amazon.com/ko_kr/AWSCloudFormation/latest/UserGuide/Welcome.html
'AWS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[AWS] AWS IoT Core ์ด๊ฒ์ ๊ฒ (1) | 2024.11.21 |
---|---|
[AWS] AWS Cognito์ OAuth (3) | 2024.10.28 |
[AWS] AWS IoT Core๋ ? (0) | 2024.09.27 |
[AWS] SchedulerAsyncClient (0) | 2024.07.17 |
[AWS] Amazon EventBridge Scheduler์ AWS Lambda ์ฌ์ฉํ๊ธฐ (0) | 2024.07.10 |