Sunday, 11 March 2018

AWS Elastic Beanstalk

Overview
  • PAAS offering for application management of simple 3-tiered applications.
  • "overlay" on many other services (e.g. EC2, S3 ELB, RDS, Route53)
  • Less complex than OpsWorks
  • Use cases
    • Simplified deployment as EB takes care of all the resource provisioning
      • Implements many best practices
      • Good for simple tiered applications
      • Optimized for many common Web and Web Services patterns

Model
  • Application
    • logical collection of:
      • application versions
      • environments
      • environment configurations
  • Application Version
    • iteration of deployable code (~CodeDeploy: revision)
    • Points to S3
  • Environment - application version deployed onto specific AWS resources
    • Runs single application version at a time
    • Can be grouped together
    • ~CloudFormation: Stack
  • Environment Tier - see below
  • Environment Configuration - configuration of resources.
    • Defines how environment and its resources should behave
    • It can be updated and EB will automatically apply changes (see Deployments below)
  • Platform - see below

Platform
  • Machine setup that allows to run user application 
    • Supports specific lanuage/framework (e.g. IIS, Apache, Ruby, Docker) 
    • Versioned
      • Underlying platform may be updated automatically (weekly maintenance window)
  • Predefined: Ruby, Java, PHP,  Node.js, .NET, Go, Python
    • Docker
      • Single-container, Multi-container, Pre-configured
  • Custom
    • Based on custom AMI (Ubuntu, RHEL, or A-Linux)
    • Uses Packer
      • Open-source tool for creating machine images


Environment Tier
  • Web: processes HTTP requests
    • Route53 entry created
    • Environment Type
      • single instance
      • ELB + auto-scaling
    • environment URL
      • e.g. testapplication-env.eu-central-1.elasticbeanstalk.com
  • Worker: instance reading off SQS queue
    • auto-scaling     

Host Manager (agent)
  • EB agent running on EC2 instance
  • Responsibilities
    • Deploy application version
    • Aggregate events and metrics
    • Generate instance-level events
    • Monitor application logs for critical errors
    • Monitor the application server
    • Patch instance components
    • Rotate application logs and publish them to S3


Healthcheck
  • Basic
    • ELB environments -> uses ELB healtcheck
    • Single instance environment -> EC2 healtchecks
    • Colors
      • Grey - environment is being updated
      • Green - passed most recent checks, at least 1 instance is availale
      • Yellow - failed 1 or more checks
      • Red - requests are constantly failing
    • Additional checks
      • ASG available and has at least 1 instance
      • SG has port 80 open
      • CNAME exists and points to ELB
      • SQS polled at least 1 per 3 minutes (worker environment)
  • Enhanced
    • Higher bar 
    • Uses Host Manager (agent)
      • monitors web server logs and system metrics
      • reports directly to EB service (every 10 seconds)
      • can publish "EnvironmentHealth" CloudWatch metric
    • Displays "cause" next to the color status
    • Not supported on Windows
    • Contains all basic healthchecks plus:
      • HTTP requests status (number, result, latency)
      • OS metrics


Application Version deployment
  • Rolling
    • Similar to Rolling Configuration Update
    • Healthcheck can be ignored
    • DeploymentPolicy
      • Rolling - Rolling Deployment
      • AllAtOnce - No rolling
      • RollingWithAdditionalBatch - maintain constant number of servers in-service (n+m = more expensive)
  • Blue/Green
    • DNS based - swap Environment Url (CNAME)
    • All or Nothing

Instance Log Management
  • On demand
    • Tail logs
      • 100 last lines of most commonly used logs
      • Web server, EB operatational etc.
      • When requested agent on instance concatenates and uploads to S3
    • Bundle logs (Full Logs)
      • wide range of log files (including cron, yum, CF, etc.)
      • When requested zip archive created an uploaded 
    • Stored 15 minutes in S3
  • Published (log rotation)
    • Enable in Environment Configuration settings
  • Extending
    • Non-standard location
      • Use .ebextensions to specify
    • Add .config entries for custom log files
  • EB uses logrotate on instances

Permissions
  • Instance profile - for launched EC2 instances
  • Service role - allows AWS EB service  to monitor environment resources

Limitations
  • Environment cannot be stopped (it is terminated)
  • No static IP references
  • EBS disk persistence requires additional setup
  • Database must be managed separately 
  • Inflexible for complex setups
    • Consider OpsWorks or CloudFormation



No comments:

Post a Comment