A single server instance is good for development but it would be bad for production environment because it’s unable to scale horizontally. Also it’s a waste of money to let a giant instance run 7x24 while we just have a few rushing hours in a day. Therefore, we need to be able to scale horizontally base on the network traffic, server cpu utilization percentage etc.
How to use Elastic Beanstalk?
I will create the Elastic Beanstalk environment by a cloudformation template and make specific server instance change in project artifact’s .ebextension config files.
AWSTemplateFormatVersion:'2010-09-09' Resources: sampleApplication: Type:AWS::ElasticBeanstalk::Application Properties: ################################### # Specify the Application name here ################################### ApplicationName:ApplicationName(XXXXX) Description:AWSElasticBeanstalkSampleApplication sampleApplicationVersion: Type:AWS::ElasticBeanstalk::ApplicationVersion Properties: ApplicationName: Ref:sampleApplication Description:AWSElasticBeanstalkSampleApplicationVersion SourceBundle: ################################### # Specify the artifact's location ################################### S3Bucket:!Sub"elasticbeanstalk-samples-${AWS::Region}" S3Key:php-newsample-app.zip sampleConfigurationTemplate: Type:AWS::ElasticBeanstalk::ConfigurationTemplate Properties: ApplicationName: Ref:sampleApplication Description:AWSElasticBeanstalkSampleConfigurationTemplate ################################### # Specify the solution stack name # The list of all solution stack can be found from https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html ################################### SolutionStackName:64bitAmazonLinux2018.03 v2.8.1runningPHP7.0 OptionSettings: ################################### # Specify the option settings of environment and platform # - Environment options: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html # - Platform specific options: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html ################################### -Namespace:aws:autoscaling:asg OptionName:MinSize Value:'2' -Namespace:aws:autoscaling:asg OptionName:MaxSize Value:'6' -Namespace:aws:elasticbeanstalk:environment OptionName:EnvironmentType Value:LoadBalanced sampleEnvironment: Type:AWS::ElasticBeanstalk::Environment Properties: ApplicationName: Ref:sampleApplication Description:AWSElasticBeanstalkSampleEnvironment TemplateName: Ref:sampleConfigurationTemplate VersionLabel: Ref:sampleApplicationVersion
NOTE: If we need to have immutable auto scaling, aws:elasticbeanstalk:healthreporting:system -> System Type should be set as “enhanced”.
.ebextensions
How about the software and the script deployment in EC2 instance? How can we refer and use the environment variables in ebextensions? Here is an example