AWS CloudFormation
1. 简介
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html
CloudFormation是AWS对Infrastructure as Code (IaC)基础设施即代码的实现。把要用的AWS资源,写成模板文件,方便复用和追踪版本变更。
CloudFormation用配置文件搭建和管理AWS资源,简化对基础设施的管理,可以将一组AWS资源作为一个单独的单元进行管理。资源配置完全是用配置文件实现的,因此可以对配置文件做版本管理,回退以及更新都十分简单。
CloudFormation负责创建和管理资源,对资源的后续具体操作,与CloudFormation无关。CloudFormation可以在销毁AWS资源的时候使用DeletionPolicy保留部分资源。
2. 概念
1. templates
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
模版定义了AWS的资源以及特性,定义在配置文件中。CloudFormation通过调用底层的AWS服务来配置资源。每个template定义一个stack,单个stack中可以包含多种不同的AWS资源。
1 |
|
AWS CloudFormation Designer使用图形界面编辑并生成templates.
2. Stacks
CloudFormation通过template配置和管理的资源集合称为stack
A stack is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting stacks. All the resources in a stack are defined by the stack’s AWS CloudFormation template. A stack, for instance, can include all the resources required to run a web application, such as a web server, a database, and networking rules. If you no longer require that web application, you can simply delete the stack, and all of its related resources are deleted.
3. Change sets
change sets用来更新stacks,将修改后的templates和原始的templates对比生成change sets。应用至Stacks。Change sets反应了即将进行的更新对各种stack资源的修改。
When you need to update your stack’s resources, you can modify the stack’s template. You don’t need to create a new stack and delete the old one. To update a stack, create a change set by submitting a modified version of the original stack template, different input parameter values, or both. CloudFormation compares the modified template with the original template and generates a change set. The change set lists the proposed changes.
3. Getting started
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/GettingStarted.Walkthrough.html
1. template参数化
CloudFormation支持向template中传入参数,可以在创建stack的时候定制stack
2. template存储
template可以存储至本地或者S3。
在使用template创建stack时,CloudFormation会将templates存储至对应region的S3特定bucket中。
3. template基础
常见函数:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
1. Resources
AWS资源的配置以及相互关联
1 |
|
2. Parameters
定义输入参数的特性以及限制(用于验证输入是否合法),Parameters可以被后续的Resources等引用。
无默认值的参数必须指定,如KeyName,有默认值的参数未指定时使用默认参数。
1 |
|
3. Mappings
更加灵活的将值与值做映射。
1 |
|
4. Outputs
stack输出的log
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!