简体   繁体   English

AWS Cloud形式不会将数据复制到新创建的堆栈

[英]AWS Cloud formation does not copy the data to the newly created stack

In AWS cloud formation, i use the cloud former tool. 在AWS云形成中,我使用了成云器工具。 I can use that tool to create a cloud formation template from existing resources. 我可以使用该工具从现有资源创建云形成模板。 And then use the template to create a stack. 然后使用模板创建堆栈。 I tested with that tool. 我使用该工具进行了测试。 It can work, (as in it can create instances with same memory size, with same volume size, same VPC settings, and auto start the instances). 它可以正常工作(因为可以创建具有相同内存大小,相同卷大小,相同VPC设置并自动启动实例的实例)。 But there is no files in the volume. 但是卷中没有文件。

Do i have to create a snapshot of the existing volume, create a new volume from the snapshot, attach it to the newly created instance, and copy the files manually ? 我是否必须创建现有卷的快照,从快照创建新卷,将其附加到新创建的实例,然后手动复制文件?

Or is there any better way ? 还是有更好的方法?

Do i have to create a snapshot of the existing volume, create a new volume from the snapshot, attach it to the newly created instance, and copy the files manually ? 我是否必须创建现有卷的快照,从快照创建新卷,将其附加到新创建的实例,然后手动复制文件?

Cloudformation is provisioning resources , but is not responsible for provisioning the contents of those resources - that you have to do yourself. Cloudformation 提供资源 ,但不负责提供这些资源的内容 -您必须自己做。

You can leverage the EC2 Userdata to manually pull files from S3 or other repos as the instance boots. 您可以利用EC2用户数据在实例启动时从S3或其他存储库中手动提取文件。

Or is there any better way ? 还是有更好的方法?

If you want to share data between applications, EFS is always an option. 如果要在应用程序之间共享数据,则始终可以选择EFS In your case, though, using Userdata might be effective. 但是,就您而言,使用Userdata可能是有效的。

If you wish to launch new EC2 instances with software automatically loaded, there are basically two choices: 如果要启动自动加载软件的新EC2实例,则基本上有两种选择:

  • Use a pre-configured AMI, or 使用预先配置的AMI,或者
  • Use a startup script to load the software 使用启动脚本加载软件

Pre-configured AMI 预先配置的AMI

An Amazon Machine Image (AMI) is a copy of a disk. Amazon Machine Image(AMI)是磁盘的副本。 When a new EC2 instance is launched, an AMI is selected and the boot disk (and optionally other disks) are automatically pre-loaded with the contents of the AMI. 启动新的EC2实例时,将选择AMI,并且会自动将AMI的内容预加载到引导磁盘(以及其他磁盘)中。

A common practice is to boot an EC2 instance and configure it as desired. 常见的做法是引导EC2实例并根据需要对其进行配置。 Then, create an AMI. 然后,创建一个AMI。 Thereafter, when a new EC2 instance is required for the application, launch it using the pre-built AMI. 此后,当应用程序需要新的EC2实例时,请使用预构建的AMI启动它。

There are also tools available to automate the building of an AMI, such as Netflix Aminator and Packer . 还有可用的工具来自动构建AMI,例如Netflix AminatorPacker

Benefits: New machine boots quickly, fully-configured. 好处:新机器可以快速启动,并且配置完整。

Issues: Need to create a new AMI whenever you update your software. 问题:每当您更新软件时,都需要创建一个新的AMI。

Use a startup script to load the software 使用启动脚本加载软件

When an Amazon EC2 instance is launched from a standard Amazon-provided AMI (eg Amazon Linux, Microsoft Windows), software on the AMI automatically looks at the User Data passed to an EC2 instance. 从标准的Amazon提供的AMI(例如Amazon Linux,Microsoft Windows)启动Amazon EC2实例时,AMI上的软件会自动查看传递给EC2实例的用户数据 If the User Data contains a startup script , the script will be executed -- but only the first time that an instance is launched. 如果用户数据包含启动脚本 ,则将执行该脚本-但仅在首次启动实例时执行。 This is an excellent way to install software on the instance. 这是在实例上安装软件的绝佳方法。

You are responsible for writing the script. 您负责编写脚本。 The script should install whatever tools, software and data you want on the instance. 该脚本应在实例上安装所需的任何工具,软件和数据。

Benefits: Updating your software? 好处:更新软件? Just launch a new instance and the script will install the latest version of your software (assuming you have written the script to always point to the latest version). 只需启动一个新实例,该脚本将安装软件的最新版本(假设您编写的脚本始终指向最新版本)。

Issues: It takes longer to launch the new instance, since the software is being installed. 问题:由于正在安装软件,因此启动新实例需要更长的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM