Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put Elastic Beanstalk config commands that are only run once on spin-up?

Tags:

I know I can put commands in my source code in .ebextensions/*.config using the commands array. These are executed on every deploy however. What about if I want to execute a configuration command only once when spinning up a new instance?

like image 575
Gabe Kopley Avatar asked May 30 '13 03:05

Gabe Kopley


People also ask

Where is Elastic Beanstalk config file?

Saved configurations are stored in the Elastic Beanstalk S3 bucket in a folder named after your application. For example, configurations for an application named my-app in the us-west-2 region for account number 123456789012 can be found at s3://elasticbeanstalk-us-west-2-123456789012/resources/templates/my-app .

When launching an Elastic Beanstalk environment for the first time which three items must be selected?

Instance type, root volume, key pair, and AWS Identity and Access Management (IAM) role. Internal Amazon RDS database.

What command will you use to see configuration environments and services for an application?

You can use the eb config command to apply a saved configuration to a running environment. Use the --cfg option with the name of the saved configuration to apply its settings to your environment. In this example, v1 is the name of a previously created and saved configuration file.


1 Answers

Commands can be run conditionally using the test: modifier. You specify a test to be done. If the test returns 0, the command is run, otherwise it is not.

If the last command in your config file touches a file, and the commands above that you only want to run once check for the existence of that file, then those commands will only run the first time.

commands:
  01-do-always:
    command: run_my_script
  02-do-on-boot:
    command: script_to_run_once
    test: test ! -f .semaphore
  99-signal-startup-complete:
    command: touch .semaphore

On Windows it would be something like this

commands:
  01-do-always:
    command: run_my_script
  02-do-on-boot:
    command: script_to_run_once
    test: if exists c:\\path\\to\\semaphore.txt (exit 0) else (exit 1)
  99-signal-startup-complete:
    command: date > c:\\path\\to\\semaphore.txt
like image 129
Jim Flanagan Avatar answered Oct 12 '22 05:10

Jim Flanagan