将现有EC2实例导出到CloudFormation json/yaml [英] Export Existing EC2 instance to CloudFormation json/yaml
问题描述
问题:
我有一个正在运行的 EC2
实例,并且对该实例进行了一些修改:安装了docker,certs的安装目录等.现在,我想创建相同的实例,但使用基础架构作为代码主体.我没有记住自己所做的所有附加工作并手动创建模板,而是试图找到一种方法将当前的EC2实例导出为 json
或 yaml
格式这样我就可以终止该实例并创建另一个与正在运行的实例等效的实例.
I have an EC2
instance running and I have made some modifications to the instance: installed docker, setup directories for certs, etc. Now, I am wanting to create the same instance but use infrastructure as code principals. Instead of remembering all the additions that I have done and creating a template by hand, I am trying to find a way to export my current EC2 instance into a json
or yaml
format so that I can terminate this instance and create another one that is equivalent to the one running.
我已经尝试过:
aws ec2 describe-instances
搜索过的Google
搜索到的SO
推荐答案
由于您不知道实例的设置方式,因此唯一的选择是创建Amazon Machine Image(AMI).这将创建磁盘的精确副本,因此从AMI启动的任何新实例都可以使用已安装的所有内容.然后可以将CloudFormation模板配置为使用此AMI启动实例.
Since you have no knowledge of how the instance was setup, the only choice is to create an Amazon Machine Image (AMI). This will create an exact copy of the disk, so everything you have installed will be available to any new instances launched from the AMI. The CloudFormation template can then be configured to launch instances using this AMI.
另一方面,如果您知道配置实例所需的所有命令,则可以提供一个 User Data脚本,该脚本将在新实例首次启动时运行.这将自动配置实例,并且是配置实例的推荐方法,因为它易于修改,并允许实例使用最新版本的操作系统启动.
If, on the other hand, you knew all the commands that needed to be run to configure the instance, then you could provide a User Data script that would run when new instances first boot. This would configure the instances automatically and is the recommended way to configure instances because it is easy to modify and allows instances to launch with the latest version of the Operating System.
此类脚本可以作为CloudFormation模板的一部分提供.
Such a script can be provided as part of a CloudFormation template.
这篇关于将现有EC2实例导出到CloudFormation json/yaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!