Deploy, Manage, and Scale Your Apps with OpsWorks, Elastic Beanstalk, and CodeDeploy Part 1 – Elastic Beanstalk © 2017 Amazon Web Services, Inc. and its affiliates. All rights served. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon Web Services, Inc.
AWS Elastic Beanstalk Easily deploy, monitor, and scale three-tier web applications and services. Infrastructure provisioned and managed by EB – but you maintain complete control. Preconfigured application containers that are easily customizable. Support for these platforms:
Elastic Beanstalk object model Application Environments Infrastructure resources (such as EC2 instances, ELB load balancers, and Auto Scaling groups) Runs a single application version at a time for better scalability An application can have many environments (such as staging and production) Application versions Application code Stored in Amazon S3 An application can have many application versions (easy to rollback to previous versions) Saved configurations Configuration that defines how an environment and its resources behave Can be used to launch new environments quickly or roll- back configuration An application can have many saved configurations Applications are the overarching container of multiple Environments, Application Versions, and Saved Configurations Environments contain actual resources like EC2 Instances/ELBs/ASGs Application Versions are actual code versions. We get questions about limits a good amount on increasing Application Version limits. Best practice is to trim those. Do not use EB as an application storage mechanism. They should be using CodeCommit or something for version control. Customers will have to trim old App Versions.
Elastic Beanstalk environment Two types: Single instance Load balancing, auto scaling Two tiers (web server and worker) Elastic Beanstalk provisions necessary infrastructure resources such as load balancers, auto-scaling groups, security groups, and databases (optional) Configures Amazon Route 53 and gives you a unique domain name (For example: yourapp.elasticbeanstalk.com) Beanstalk is a managed service. Let Beanstalk take care of Infrastructure management and customers just deal with the code. Single Instance – usually for dev/test
On-instance configuration Focus on building your application Your code HTTP server Application server Language interpreter Operating system Host Elastic Beanstalk configures each EC2 instance in your environment with the components necessary to run applications for the selected platform No more worrying about logging into instances to install and configure your application stack Never manually log in and configure EC2 instances. Let Beanstalk do it for you – use ebextensions
Application versions and configurations All versions are stored durably in Amazon S3. Code can also be pushed from a Git repository! Saved configurations Save these for easy duplication for A/B testing or non-disruptive deployments Application lifecycle Enable auto-deletion of application versions based on application version count or application version age
Customizing Your Environment Elastic Beanstalk manages your AutoScaled environments Manual changes will be lost on scaling events ebextensions lets you customize your AutoScaling fleet Place multiple config files into “.ebextensions” folder YAML and JSON support ~/my-app/ |-- .ebextensions | |-- environmentvariables.config | `-- healthcheckurl.config |-- .elasticbeanstalk | `-- config.yml |-- index.php `-- styles.css Ebextensions lets you: Customize: API options with option_settings Installed packages Groups Users Sources Files Run custom commands Ensure services are running We parse the .config file with both a JSON and YAML parser. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html
Deployment options Via the AWS Management Console Via EB CLI Via the AWS Toolkit for Eclipse and the Visual Studio IDE $ eb deploy This used to be $ git aws.push The new eb CLI will let you clone environments, run local environments, etc. Eb deploy takes the most recent check in from your local git repo and deploys that to EB. If someone in the room says that they’re using git aws.push, then it’s time to upgrade. Git aws.push is from the EB cli v2.6 which has been deprecated.
Deployment configuration Your code Region 01 Stack (container) type 02 Single instance Load balanced with Auto Scaling 03 OR Database (RDS) 04 Optional
Example: CLI workflow Prerequisites: AWS account – your access and secret keys EB CLI Linux / Unix / Mac / Windows : Python 2.7 or 3.4 (Not 3.5) A credential file containing info from 1 Git 1.66 or later (optional)
Example: CLI workflow Initial app deployment: $ git init . $ git add . Initialize your Git repository 01 Add your code 04 $ eb init $ git commit –m “v1.0” Create your Elastic Beanstalk app 02 Commit 05 Follow the prompts to configure the environment 03 Create the resources and launch the application 06 $ eb create
Example: CLI workflow Update your app: Update your code 01 $ git add . $ git commit –m “v2.0” $ eb deploy Push the new code 02 Monitor the deployment progress 03 $ eb status
Example: Docker container Three ways: Dockerfile (image built on instance). Dockerrun.aws.json (manifest file that describes how to run the Docker image). Application archive (should include Dockerfile or Dockerrun.aws.json file). Benefits: Enables high-fidelity deployments. You own the runtime. You can use any language or framework, even those not currently supported by Elastic Beanstalk (such as Scala and Clojure). Dockerfile Dockerrun.aws.json Importance of highlighting docker is that you can now use Beanstalk to provision infrastructure and not be bound to the default solution stacks. With Beanstalk multi-container environments (that run on ECS), you can even have more than one container deployed onto ECS for you.
Example: Docker container Using the EB command line tool: $ git init . Initialize your Git repository 01 $ git add Dockerfile Add your code 04 $ eb init Create your Elastic Beanstalk app 02 $ git commit –am “v1.0” Commit 05 Follow the prompts to configure the environment and copy Dockerfile 03 06 Create the resources and launch the application $ eb create
Monitoring Enhanced Health Reporting Unique to Elastic Beanstalk No additional cost Daemon process running on each EC2 instance in your environment More detail on each individual instance EB CLI: eb health id status cause Overall Info Command is executing on 3 out of 5 instances i-bb65c145 Pending 91 % of CPU is in use. 24 % in I/O wait Performing application deployment (running for 31 seconds) i-ba65c144 Pending Performing initialization (running for 12 seconds) i-f6a2d525 Ok Application deployment completed 23 seconds ago and took 26 seconds i-e8a2d53b Pending 94 % of CPU is in use. 52 % in I/O wait Performing application deployment (running for 33 seconds) i-e81cca40 Ok Canary deployments Detect failures early and roll back
Deployments – In Batches Batched Deployments Customize a percentage of instances to be deployed to Deploy to X% and only continue if the instances become healthy Automated rollback on failures Canary deployments Detect failures early and roll back
Deployments – Zero Downtime Swap URLs Create a new environment for an existing application Deploy your updated application code to the new environment Use the “Swap Environment URLs” feature to transition users to the new production environment Swaps the CNAMEs of environments (appname.elasticbeanstalk.com) with another CNAME with a different environment. This allows blue green deployments (red/black).
Security Considerations Deploy within a VPC Understand security controls created for you Create well defined permissions in IAM
Security Updates AWS Elastic Beanstalk provides updates to platform configurations periodically Your responsibility to update your individual environments Update Platform Version in place Beanstalk solution stacks are locked to a specific AMI and release version. Hence, you need to upgrade your stacks like this to get the newest security patches. We do NOT do this for customers.
Benefits of Elastic Beanstalk Focus on your application Focus on what makes your business unique Focus on innovation, not undifferentiated heavy lifting Spend developer time in the right place Automate as much as you can Zero downtime deployment
Any Questions?