AWS BeanStalk EC2 launch script

amazon ec2amazon-web-serviceselastic-beanstalk

When manually launching EC2 instances, we can specify a "launch script" using the user data feature.

However, I can't seem to find a similar feature in AWS Beanstalk.

Is it not possible to do so?

(As a workaround, I know I can create a custom AMI containing the necessary launch-time script, but that means I have to create different custom AMI for each possible launch-time script configuration).

Best Answer

You can use .ebextensions (commands/container_commands) or lifecycle hooks For e.g. we use the following commands to install newrelic agent

$ cat .ebextensions/newrelic.config
commands:
    00-cmd:
        command: yum install -y http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
        test: "[ ! -f /etc/yum.repos.d/newrelic.repo ]"

    01-cmd:
        command: yum install -y newrelic-sysmond
        test: "[ ! -f /usr/sbin/nrsysmond ]"

    02-cmd:
        command: usermod -a -G docker newrelic
        ignoreErrors: true