Creating a Custom Amazon Machine Image (AMI)
When you create an AWS Elastic Beanstalk environment, you can specify an Amazon Machine Image (AMI) to
use instead of the standard Elastic Beanstalk AMI included in your platform configuration's solution stack.
A custom AMI can improve provisioning times when instances are launched in your environment if
you need to install a lot of software that isn't included in the standard AMIs.
Using .ebextensions is great for configuring and customizing your environment quickly and consistently. Applying configurations, however, can start to take a long time during environment creation and updates. If you do a lot of server configuration in
A custom AMI also allows you to make changes to low level components, such as the Linux kernel, that are difficult to implement or take a long time to apply in
To create a custom AMI, launch the base Elastic Beanstalk, Amazon Linux or other community AMI in Amazon EC2, customize the software and configuration to your needs, and then stop the instance and save an AMI from it.
If you create a custom AMI from an Amazon Linux AMI instead of Elastic Beanstalk's, provisioning time will
increase because Elastic Beanstalk must install its own software components to support features such as
Enhanced Health Reporting. We recommend basing your
custom AMI off of an Elastic Beanstalk AMI whenever possible.
You can also create a custom AMI from an Amazon Linux AMI or any community AMI.
Using .ebextensions is great for configuring and customizing your environment quickly and consistently. Applying configurations, however, can start to take a long time during environment creation and updates. If you do a lot of server configuration in
.ebextensions, you can reduce this time by making a custom AMI
that already has the software and configuration that you need.A custom AMI also allows you to make changes to low level components, such as the Linux kernel, that are difficult to implement or take a long time to apply in
.ebextensions. You can base your custom AMI off of an Elastic Beanstalk image, or make a
custom image from standard Amazon Linux AMIs. To create a custom AMI, launch the base Elastic Beanstalk, Amazon Linux or other community AMI in Amazon EC2, customize the software and configuration to your needs, and then stop the instance and save an AMI from it.
Note
Do not create an AMI from an instance that was launched in an Elastic Beanstalk environment. Elastic Beanstalk
makes changes to instances during provisioning that can cause issues in the saved AMI. Saving
an image from an instance in an Elastic Beanstalk environment will also bake in the version of your
application that was deployed to the instance.
To identify the base Elastic Beanstalk AMI
- Open the Elastic Beanstalk console.
- Create an Elastic Beanstalk environment running your application. For more information on how to launch an Elastic Beanstalk application, go to the Getting Started Using Elastic Beanstalk.
- Navigate to the management console for your environment.
- Choose Configuration
- Next to Instances, click
. - Note the value in the Custom AMI ID box.
To create a custom AMI
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- Click Launch Instance.
- Click Community AMIs
- Enter the AMI ID of the Elastic Beanstalk or community AMI that you will customize to create a custom AMI and press Enter.
- Click Select to select the AMI.
- Select an instance type and click Next: Configure Instance Details.
- Expand the Advanced Details section and paste the following text in
the User Data field:
The repository version number is the year and month version in the AMI name. For example, AMIs based on the March 2015 release of Amazon Linux have a repository version number#cloud-config repo_releasever:repository version numberrepo_upgrade: none2015.03. For Elastic Beanstalk image, this matches the date shown in the solution stack name for your platform configuration.
NoteThese settings configure the lock-on-launch feature, which causes the AMI to use a fixed, specific repository version when it launches, and disables the automatic installation of security updates. Both are required to use a custom AMI with Elastic Beanstalk. - Proceed through the wizard to launch the EC2 instance. When prompted, select an SSH key
that you have access to so that you can use SSH to connect to the instance for the next
steps.
NoteFor additional information on how to launch an Amazon EC2 instance, go to Running an Instance in the Amazon Elastic Compute Cloud User Guide. - Connect to the instance. For more information on connecting to an Amazon EC2 instance, go to Connecting to Instances in the Amazon Elastic Compute Cloud User Guide.
- After customizing a Windows instance, you need to run the EC2Config service Sysprep. For information about EC2Config, go to Configuring a Windows Instance Using the EC2Config Service.
- If you are using an AMI with Apache and Tomcat, you will need to perform your
customizations.
Apache and Tomcat are not automatically started when you manually launch the Elastic Beanstalk AMI using the Amazon EC2 tab on the AWS Management Console. Enter the following commands at your Amazon EC2 instance's command prompt to start Apache and Tomcat.
sudo -s cd /etc/init.d ./httpd start ./tomcat7 start - Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- Stop the EC2 instance.
- Select the stopped instance that you've just modified and choose Create Image (EBS AMI) from the Instance Actions menu.
- To avoid incurring additional AWS charges, terminate the Amazon EC2 instance. For instructions on how to terminate an instance, go to Terminate Your Instance in the Amazon Elastic Compute Cloud User Guide.
- To use your custom AMI, specify your custom AMI ID in the Custom AMI
ID text box in the Elastic Beanstalk Edit Configuration dialog box.
Existing instances will be replaced with new instances launched from the new custom
AMI.
source : http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.customenv.html
Comments
Post a Comment