0
votes

In AWS cloud formation, i use the cloud former tool. 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). 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 ?

2

2 Answers

1
votes

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.

You can leverage the EC2 Userdata to manually pull files from S3 or other repos as the instance boots.

Or is there any better way ?

If you want to share data between applications, EFS is always an option. In your case, though, using Userdata might be effective.

1
votes

If you wish to launch new EC2 instances with software automatically loaded, there are basically two choices:

  • Use a pre-configured AMI, or
  • Use a startup script to load the software

Pre-configured AMI

An Amazon Machine Image (AMI) is a copy of a disk. 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.

A common practice is to boot an EC2 instance and configure it as desired. Then, create an AMI. Thereafter, when a new EC2 instance is required for the application, launch it using the pre-built AMI.

There are also tools available to automate the building of an AMI, such as Netflix Aminator and Packer.

Benefits: New machine boots quickly, fully-configured.

Issues: Need to create a new AMI whenever you update your software.

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. 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.