aws-templateslamp-production-ready

Customize the Bitnami LAMP Production-Ready Stack AMIs

If the default configuration of the LAMP Production-Ready solution does not meet your requirements, it is also possible to customize the configuration, by creating a custom Amazon Machine Image (AMI) and using this in place of the default one. The steps to do this are as follows:

  • Launch a new LAMP Production-Ready solution and wait until the CloudFormation dashboard display the status “CREATE_COMPLETE” for the deployment.

    Template creation

  • Navigate to the EC2 console, choose “Instances” from the navigation panel and select one of the application instances. You can filter by the tags you set when deploying the solution.

  • From the “Description” tab, obtain the AMI ID, as shown below:.

    Obtain AMI ID

  • Launch the AMI separately, always ensuring that you pass the SKIP_FIRST_BOOT parameter to the cloud-init script. This can be passed to the instance in the “user data” field when configuring an EC2 instance with the AMI. Here is the necessary code for the cloud-init script:

    #!/bin/bash
    
    SKIP_FIRST_BOOT=1
    

    AMI user data

    NOTE: This step is necessary to launch the AMI and bypass the initial configuration steps (adding firewall entries, configuring the database connection and so on). Doing this ensures that the AMI can be reused correctly with the LAMP Production-Ready solution.

    Learn more about passing user data to an EC2 instance.

    It’s also possible to automate customizations for future releases, by adding the customization commands in the cloud-init script. Some examples of customizations include:

    • Adding custom virtual hosts (use the /opt/bitnami/apache/vhosts directory)
    • Setting up custom HTTPS certificates (using the /opt/bitnami/apache/conf/bitnami/certs directory and naming the files server.crt and server.key)
    • Installing custom packages, enabling Apache modules and other system changes, as shown in the example code below:

      # Installing a custom system package
      sudo apt-get update && sudo apt-get install -y vim
      # Enable a custom Apache module
      sudo sed -i -r 's/#LoadModule ratelimit_module/LoadModule ratelimit_module/' /opt/bitnami/apache/conf/httpd.conf
      
  • Once you have a running EC2 instance with the new AMI, include (and test) any required customizations, stop the instance (if started) and republish the AMI with your changes.

  • You now have two options to deploy your customized AMI:

    • Create a new deployment (and delete the old one)
    • Update the existing deployment

Option 1: Create a new deployment, replacing the old one

Option 2: Update the existing deployment

  • Navigate to the CloudFormation console, select the deployment and click the “Update” button.

    Update AMI

  • If prompted, navigate to the root stack.

    Select root stack

  • Modify the AMI field to use the custom AMI.

    Change AMI

  • Proceed with the deployment in the usual way and wait until the CloudFormation dashboard displays the status “UPDATE_COMPLETE” for the deployment.

Last modification August 21, 2019