Creating an AWS Elastic Beanstalk Environment with CLI Commands | DevOps Engineer Exam Question | Amazon

Create AWS Elastic Beanstalk Environment with CLI Commands

Prev Question Next Question

Question

You are responsible for creating an AWS Elastic Beanstalk environment as soon as possible by using CLI commands.

It is a PHP application installed on the Linux server.

Besides, in the new environment, a cron job should be set up in all instances.

The file named as cron-linux is prepared for this and uploaded together with other application source code in an S3 bucket.

Which kind of config file and CLI command are correct to create this Elastic Beanstalk environment?

Explanations

Correct Answer - B.

Configuration (.config) files for Elastic Beanstalk are put in the .ebextensions folder together with other application codes.

Please check for the details of setting configurations during environment creation.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-during.html#configuration-options-during-console-ebextensions

Option A is incorrect: Because firstly, it should be cron-linux.config.

Secondly, if AWS Elastic Beanstalk CLI is used, the create-environment command should add options such as --environment-name test-env.

Option B is CORRECT: Because cron-linux.config has been put into the right place and eb create command is suitable to create the environment.

Option C is incorrect: Because cron-linux.cfg.yml has been put into the folder of .elasticbeanstalk/saved_configs/

This is how saved configuration is used for Elastic Beanstalk.

However, in this case, the config file instead of a saved configuration is needed to set up the cron job.

Besides, the AWS Elastic Beanstalk CLI command is used incorrectly.

Option D is incorrect: Because cron-linux.config should be placed into .ebextensions rather than .elasticbeanstalk/saved_configs/.

Methods
© Using configuration files (.ebextensions)
© Using a saved configuration

© Using the new environment wizard

Using configuration files (.ebextensions)
Include . config files in your application source bundle in a folder named . ebextensions.

For details about configuration files, see .Ebextensions.

~/workspace/my-app-v1.zip
|-- .ebextensions

| |-- environmentvariables.config
| > -- healthcheckurl. config

|-- index. php

*-- styles.css

Upload the source bundle to Elastic Beanstalk normally, during environment creation.

The Elastic Beanstalk console applies recommended values for some configuration options and has form
fields for others. Options configured by the Elastic Beanstalk console are applied directly to the
environment and override settings in configuration files.

To create an Elastic Beanstalk environment using CLI commands and configure a cron job, you need to perform the following steps:

  1. First, create an Elastic Beanstalk application using the following command:
css
aws elasticbeanstalk create-application --application-name <application-name> --region <region>

Replace <application-name> with the name of your application and <region> with the AWS region you want to deploy your application.

  1. Next, create an Elastic Beanstalk environment using the following command:
css
aws elasticbeanstalk create-environment --application-name <application-name> --environment-name <environment-name> --solution-stack-name "64bit Amazon Linux 2 v5.4.2 running PHP 7.4" --region <region>

Replace <environment-name> with the name of your environment and <region> with the AWS region you want to deploy your environment. Note that we are using the latest version of Amazon Linux 2 with PHP 7.4 installed.

  1. Configure the environment to download the cron-linux file from your S3 bucket and install it on each instance by creating a configuration file named .ebextensions/cron.config with the following content:
bash
files: "/etc/cron.d/my-cron": mode: "000644" owner: root group: root source: https://s3.amazonaws.com/<bucket-name>/cron-linux

Replace <bucket-name> with the name of your S3 bucket.

  1. Finally, update your Elastic Beanstalk environment to apply the new configuration using the following command:
css
aws elasticbeanstalk update-environment --environment-name <environment-name> --region <region>

Replace <environment-name> with the name of your environment and <region> with the AWS region you want to deploy your environment.

Once the environment update is complete, the cron-linux file should be downloaded from your S3 bucket and installed on each instance as a cron job.