Skip to content

Latest commit

 

History

History
57 lines (54 loc) · 3.46 KB

aws-devops-eb-ebextentions.md

File metadata and controls

57 lines (54 loc) · 3.46 KB

.ebextensions files - Other random commands (files processed in alphabetic order)

  • Create separate .ebextensions files for commands
  • Commands specified in YAML or JSON map, run in alphabetic order by name
  • Will redeploy a new instance version - so they are run in a fresh environment
  • Many declarative sections - processed in specific order (windows slightly different from linux)
    • option_settings - EB options and controls (not ordered); precedence is direct applied > saved config > option_settings (alphabetic order by filename) > defaults
    • packages - supports package managers rpm, yum, python and rubygems (priority order) - within a package manager no ordering https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-packages
    • groups, users - local groups and users (linux only)
    • sources - e.g. /etc/myapp: https://mybucket.s3.amazonaws.com/myobject
    • files - specific file location, mode, owner, content
    • commands, services, container_commands - see below
  • KEY IDEA: Two kinds of command blocks - commands and container_commands
    • commands: run commands on the EC2, runs BEFORE APPLICATION AND WEB SERVER SET UP - set up files and packages (although also separate packages and files sections)
    • container_commands: commands that affect application source code - run AFTER APPLICATION/WEB SERVER SET UP but BEFORE application deployed
    • Sequence
      • commands
      • application/web server setup
      • version archive extracted
      • container_commands - common use cases
        • modify index.html to have timestamp or version info
        • do database migrations
  • KEY IDEA: have leader_only: true option
    • only run on the single "leader" instance
    • only for container_commands

Can customize environment using saved configs

  • But also create .ebextensions files IN PROJECT ROOT that give further environment configs
  • File names *.config - really YAML or JSON
  • option_settings section - autoscaling configs, instance types, custom image, security groups, etc.
    • Two syntaxes - listed key/value array, or e.g. aws:autoscaling:asg
    • just do an eb deploy to redeploy

Can also use CloudFormation template language directly (Resources block)

  • You can output names/ARNs
  • Can also use together with option_settings section to set environment variables -> pass to the application - really great for autogenerated names e.g. SNS topic names
  • Can do SNS notifications - EB auto-creates and subscribes an email address.
  • Weird syntax:
    option_settings:
      aws:elasticbeanstalk:application:environment:
        # these are assigned dynamically during a deployment
        NOTIFICATION_TOPIC: '`{"Ref" : "NotificationTopic"}`'
        DYNAMODB_TABLE: '`{"Ref" : "DynamoDBTable"}`'
        AWS_REGION: '`{"Ref" : "AWS::Region"}`'
  • When deployed onto instance, they will be resolved
  • /opt/elasticbeanstalk/bin/get-config environment
  • /opt/elasticbeanstalk/bin/get-config optionsettings

Note that this DynamoDB table and SNS topic part of CloudFormation

  • KEY IDEA: if you want lifecycle to not be linked to EB lifecycle, create it externally
  • they are tied to the environment - another environment gets another
  • delete environment -> delete resources
  • so for external/permanent tables etc. don't make part of the EB environment
  • 2 options
    • Create it manually and just reference it by name in the eb environment properties
    • External CloudFormation