Scale your PHP application with Elastic Beanstalk - CloudParty Genova
-
Upload
corley-srl -
Category
Technology
-
view
585 -
download
2
description
Transcript of Scale your PHP application with Elastic Beanstalk - CloudParty Genova
Scale out our PHP application withElasticBeanstalk
About meCofounder Cofounder
on Github on Twitter
Corley S.r.l. - @CorleyCloudUpCloo LTD - @UpCloo
wdalmutwalterdalmut
- Internet Of Things! @ Turin [CFP] - 15 Nov - CloudComputing @ Turin [CFP ASAP]
internetof.itwww.cloudconf.it
ElasticBeanstalkScale your app workers and web apps
Queue DaemonsLoad balanced web applications
Mainly for Service Oriented Architecture
Autoscaling applied to web applications
Scale apps is not simpleHow to handle dev/testing/production? (dynamic env)How to install/update softwares? (dynamic env)How to handle user sessions? (more than one node)How to handle/tail logs? (dynamic env)How to monitor all instances (dynamic env)And more... (all things are moving!)
Run different environment per app
Typically you run: Production, Testing, Development
Different app versions per environment
Easy distributed app deploy/rollback and testing/production application management
Different configuration per environment
Upgrade your environment and switch your production without downtime
Production Env Swap
My production environment
Add a new environment
Swap production environment
ElasticBeanstalk swap env URLs in order to simplify the upgrade
Destroy your old environment
COST-SAVING!it is easier create and destroy environments than upgrade them
Environment Management
Your scaling policies
Scaling made easy
Application variablesAll environment variables are ported to your application in $_SERVER
You can pass everything like: Memcached and Mysql configurations etc.
Use Composer for DependenciesElasticBeanstalk uses composer in order to prepare your applicationUse composer hooks in order to connect all env variables to your app
configuration
Composer hooks{ /** other composer configs **/ "scripts": { "post‐update‐cmd": [ "Corley\\Deploy\\Magento::updateConf" ], "post‐install‐cmd": [ "Corley\\Deploy\\Magento::updateConf" ] },}
<?phpnamespace Corley\Deploy;
use Composer\Script\Event;
class Magento{ public static function updateConf(Event $event) { if (array_key_exists("OVERWRITE_CONF", $_SERVER)) { // Update your config file when $_SERVER contains "OVERWRITE_CONF" variable } }}
Need more customizations?Create a folder in your project root with name .ebextensions and
append your configuration files with extension .config
ElasticBeanstalk will use them during the application provisioning
Cronjobs runs on the leader instance only.ebextensions/05_cron_jobs.config
container_commands: 01_magento_cron_job: command: "cat .ebextensions/magento_cron_job.txt > /etc/cron.d/magento_cron_job && chmod 644 /etc/cron.d/magento_cron_job" leader_only: true
All configuration files are just simple YAML files
Monitor your environment
You can monitor many metrics with CloudWatchUDP/IP CloudWatch agent on local machine: https://github.com/wdalmut/cloudwatch-agent
What we are missing?
Logs!
Grab all active instances logs
But my application logs?commands: 21_application_logs: command: echo "/var/app/current/var/log/*.log" > myapp.conf cwd: /opt/elasticbeanstalk/tasks/bundlelogs.d 22_application_logs: command: echo "/var/app/current/var/log/*.log" > myapp.conf cwd: /opt/elasticbeanstalk/tasks/systemtaillogs.d 23_application_logs: command: echo "/var/app/current/var/log/*.log" > myapp.conf cwd: /opt/elasticbeanstalk/tasks/taillogs.d 24_application_logs: command: echo "/var/app/current/var/log/*.log" > myapp.conf cwd: /opt/elasticbeanstalk/tasks/publishlogs.d
.ebextensions/06_prepare_logs.config
Collecting all application logsAWS ELB can store all logs into a S3 bucket using a scheduled system
COST-SAVING! we don't need to propagate logs via "rsyslog"
Thanks for listening
Any question?