AWS Elastic Beanstalk
Developer Guide (last updated: 12 December, 2014) (API Version 2010-12-01)
Did this page help you?  Yes | No |  Tell us about it...
« Previous
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Using Custom AMIs

Unless you are deploying your AWS Elastic Beanstalk application with a legacy container type, then you can use configuration files to customize and configure your environment. Configuration files are supported for the following container types:

  • Docker

  • Node.js

  • PHP 5.3, PHP 5.4, and PHP 5.5

  • Python

  • Ruby 1.8.7, 1.9.3, 2.0.0, and 2.1.2

  • Apache Tomcat 6 and 7

  • Windows Server 2008 R2 running IIS 7.5 and Windows Server 2012 running IIS 8

Currently, AWS Elastic Beanstalk does not support configuration files for the following legacy container types:

  • PHP 5.3

  • Tomcat 6 and 7

  • Windows Server 2008 R2 running IIS 7.5 and Windows Server 2012 running IIS 8

If you are unsure if you are running a legacy container, check the Elastic Beanstalk console. For instructions, see To check if you are using a legacy container type.

For more information about configuration files, see Customizing and Configuring AWS Elastic Beanstalk Environments.

If you are deploying your AWS Elastic Beanstalk application using a legacy container type, then you need to create a custom Amazon Machine Image (AMI) that AWS Elastic Beanstalk uses for your applications. You can also use custom AMIs to improve the speed of deployments for which scaling activities specified in a configuration file result in a long installation process. To do this, customize the existing AWS Elastic Beanstalk AMI. When you modify an AWS Elastic Beanstalk AMI, do not replace components included in the solution stack. This section describes how to create and deploy a customized Amazon Machine Image (AMI) for use with AWS Elastic Beanstalk.

To create and use a customized AMI

  1. Open the AWS Elastic Beanstalk console at https://console.aws.amazon.com/elasticbeanstalk/.

  2. From the region list, select a region.

  3. Launch your AWS Elastic Beanstalk application. For more information on how to launch an AWS Elastic Beanstalk application, go to the Getting Started Using AWS Elastic Beanstalk.

  4. Find the AMI ID used by AWS Elastic Beanstalk to launch your application: Click the environment name, and then click Configuration in the navigation pane. Next to Instances, click Edit. Copy the value in the Custom AMI ID box.

  5. Use the Amazon EC2 console to launch an instance using that AMI ID:

    Note

    You must use the Amazon EC2 console to launch an instance with the AMI ID. You cannot customize an instance that was launched by AWS Elastic Beanstalk.

    1. Open the Amazon EC2 console.

    2. Click Launch Instance.

    3. On the Choose an Amazon Machine Image (AMI) page, do one of the following:

      • Click the My AMIs tab to view private AMIs that you own or private AMIs that have been shared with you. Then, in the navigation pane, under Ownership, select the Owned by me check box and the Shared with me check box.

      • Click the Community AMIs tab to view AMIs provided by the AWS user community.

    4. In the Search my AMIs or Search community AMIs text box, paste the AMI ID that AWS Elastic Beanstalk used to launch your application and press Enter.

    5. In the results list, click the Select button next to the AMI that you want to use to create your customized AMI.

    6. On the Choose an Instance Type page, select the hardware configuration and size of the instance to launch. Larger instance types have more CPU and memory. For more information about instance families, see Instance Types in the Amazon Elastic Compute Cloud User Guide.

      To stay within the free tier, select the t1.micro instance, and then click Next: Configure Instance Details.

    7. On the Configure Instance Details page, click Advanced Details to expand the list of configuration options.

    8. In the User data text box, type the following:

      #cloud-config
      repo_releasever: <repository version number>
      repo_upgrade: none

      Note

      Specify the value of repo_releasever according to the repository version number of the AMI for your container. For example, the repository version number of the AMI for the container with the name 32bit Amazon Linux 2014.02 running Node.js is 2013.09. For more information about the AMI version number for your container name, see the AMI column in Supported Platforms.

      These 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 AWS Elastic Beanstalk.

    9. Continue using the Amazon EC2 wizard to launch the AWS Elastic Beanstalk AMI that you want to customize.

      Note

      When launching the instance using the AWS Management Console, make sure that you create or specify a key pair and that you select your Amazon EC2 security group for your AWS Elastic Beanstalk environment.

      For additional information on how to launch an Amazon EC2 instance, go to Running an Instance in the Amazon Elastic Compute Cloud User Guide.

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

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

  8. 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 AWS 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
  9. From the Amazon EC2 console on the AWS Management Console, select the running instance that you've just modified and select Create Image (EBS AMI) from the Instance Actions menu. For more information on how to create an image from a running instance, go to Creating an Image from a Running Instance in the Amazon Elastic Compute Cloud User Guide. You can also view the Create Your Own Customized AMI video.

  10. To avoid incurring additional AWS charges, terminate the Amazon EC2 instance you used to create the AMI. For instructions on how to terminate an instance, go to Terminate Your Instance in the Amazon Elastic Compute Cloud User Guide.

  11. To use your custom AMI, specify your custom AMI ID in the Custom AMI ID text box in the AWS Elastic Beanstalk Edit Configuration dialog box. Existing instances will be replaced with new instances launched from the new custom AMI.