6

Using Elastic Beanstalk with Amazon Linux 2, I'm trying to have the same hook executed for a deployment (code deployment) and a configuration deployment, without having to duplicate my code in two different spots.

According to AWS docs eb will run hooks in .platform/hooks/prebuild within a deployment intial steps, but will run hooks in .platform/confighooks/prebuild in case of a configuration deployment.

My files look like this.

.platform
├── hooks
│   └── prebuild
│       ├── 00_hookname.sh
│       ├── 01_hookname.sh
│       └── 99_basic_auth.sh
└── httpd
    └── conf.d
        └── elasticbeanstalk
            ├── directory.conf
            ├── hardening.conf
            └── headers.conf

I'm trying to find a way to have 99_basic_auth.sh to run for a deployment and for a configuration deployment without having to duplicate that code.

Is there any way I can achieve that?

Cheers!

Julien B.
  • 231
  • 2
  • 10

2 Answers2

5

The easiest way I found to do such a thing is to simply call the first script from the second one.

.platform
├── hooks
│   └── prebuild
│       ├── 00_hookname.sh
│       ├── 01_hookname.sh
│       └── 99_basic_auth.sh
├── confighooks
│   └── prebuild
│       └── 99_basic_auth.sh
└── httpd
    └── conf.d
        └── elasticbeanstalk
            ├── directory.conf
            ├── hardening.conf
            └── headers.conf

Where the content of .platform/confighooks/prebuild/99_basic_auth.sh is:

#!/bin/bash

set -e

/bin/bash "/var/app/current/.platform/hooks/prebuild/99_basic_auth.sh"
Julien B.
  • 231
  • 2
  • 10
1

This can be also be done with symlinks, which I prefer over having a script calling another script:

mkdir -p .platform/confighooks/prebuild
ln -sr .platform/hooks/prebuild/99_basic_auth.sh .platform/confighooks/prebuild
Andy
  • 131
  • 1
  • 6