Chapter 6
Deployment Strategies

THE AWS CERTIFIED DEVELOPER – ASSOCIATE EXAM TOPICS COVERED IN THIS CHAPTER MAY INCLUDE, BUT ARE NOT LIMITED TO, THE FOLLOWING:

  • Domain 1: Deployment
  • check mark 1.1 Deploy written code in AWS using existing CI/CD pipelines, processes, and patterns.
  • check mark 1.2 Deploy applications using AWS Elastic Beanstalk.

    Content may include the following:

    • Environments and architectures
    • Environment variables
    • Software Development Lifecycle (SDLC)
    • AWS services for automating deployments
    • AWS Cloud tiers: Web servers, worker applications, and databases
    • Deployment strategies
  • Domain 2: Security
  • check mark 2.3 Implement application authentication and authorization.

    Content may include the following:

    • AWS Identity and Access Management (IAM) Roles in AWS Elastic Beanstalk
  • Domain 5: Monitoring and Troubleshooting

    Content may include the following:

    • Monitoring AWS Elastic Beanstalk
    • Troubleshooting AWS Elastic Beanstalk

Deployments on the AWS Cloud

As a developer in the cloud, you will often create three-tier architectures that consist of a web tier, an application tier, and a database tier. To enable your customers to use your application immediately, you must rapidly deploy both your infrastructure and code. The AWS Cloud environment offers several deployment options and several ways to provision AWS services to set up highly available and reliable applications. Ideally, deployments are seamless streams of automated processes that create, build, deploy, monitor, and modify code throughout the entire software development lifecycle (SDLC). This stream of processes must be continuous and fully integrated with your AWS services.

In a traditional environment, deployments can require substantial time to push the code to multiple environments. AWS helps to speed up this process by automating the actions required to deploy code to your environments. When you need to upload and demonstrate a code project in the cloud, you can launch an application in minutes.

Phases of the Release Lifecycle

Each team’s release lifecycle is different based on the needs of the team. Nearly all traditional release lifecycles are composed of five major phases, as shown in Figure 6.1: Source, Build, Test, Production, and Monitor. Each phase of the cycle provides increased confidence that the code will work in the intended way for customers. This also translates to a release lifecycle implemented in the AWS Cloud environment.

Build Phase

The figure shows major phases of the release lifecycle. These phases are Source, Build, Test, Production, and Monitor.

Figure 6.1 Major phases of the release lifecycle

Source Phase

During the Source phase, developers check changes into a source code repository. Many teams require peer feedback on code changes before delivering code to production or target environments. Teams may use several methods for code reviews, such as pair programming and tool-assisted options.

During the Build phase, an application’s source code is built, and the quality of the code is tested on the build machine. The most common types of quality checks are automated tests that do not require a server to execute and can be initiated from a test harness. Some teams extend their quality tests to include code metrics and style checks. There is an opportunity for automation any time a human must decide on the code.

Test Phase

The goal of the Test phase is to perform tests that cannot be done during the Build phase and that require the software to be deployed to production-like stages. Often, these tests include testing integration with other live systems, load testing, user interface (UI) testing, and penetration testing. AWS has many different stages to which it deploys. Teams deploy to preproduction stages where their application interacts with other systems to ensure that the newly changed software works in an integrated environment.

Deployment Phase

In the Deployment phase, code is deployed to production. Different teams have different deployment strategies, though it is common to set goals to reduce risk when deploying new changes and minimize the impact when a bad change is rolled into production.

Monitor Phase

During the Monitor phase, you must check the application to detect unusual activities and errors quickly.

You can automate each of these phases without automating the entire release lifecycle.

Environment Variables

Before you deploy your infrastructure and code, first determine the environmental variables. The SDLC in a traditional infrastructure contains manual implementations to release, test, and deploy code, in addition to the corresponding required documentation. Most SDLC models would benefit from an efficient lifecycle with accurate execution and no administration.

In traditional deployments, operating system patching, updates, language versioning, and infrastructure changes frequently do not occur in synchronization and may not always match between environments. It is often difficult to replicate configurations between environments in a traditional infrastructure. Unit tests, user acceptance tests, and load tests can produce different results in test and production environments. These results differ because of differences in environment variables, such as unapplied patches or nonupdated configurations. An ideal test environment matches the production environment exactly, providing the capability to test an application as if it were running in production and to receive accurate results.

Additionally, the SDLC requires the maintenance of phases that you customize to meet business requirements. This includes configurations to audit and perform quality assurance. AWS Cloud solutions automatically align the phases and environments. You can choose an AWS service to automate deployments seamlessly, saving you hours that you would normally spend managing your infrastructure and code. Although certain environmental variables are clearly defined as business requirements, others evolve as you commit changes. Code modifications are also inherently environment-based and focused on the configuration of the modification itself.

AWS services enable you to deploy applications rapidly and manage environments and the multiple tiers of your infrastructure (web servers, worker applications, and databases) automatically. You can automatically provision and manage resources for the environments and configurations that you create. Your configurations can include Auto Scaling groups, security groups, Amazon Elastic Compute Cloud (Amazon EC2) instances, other AWS resources, and AWS Identity and Access Management (IAM) roles to manage resources from AWS deployment services.

Software Development Lifecycle with AWS Cloud

Determine how to manage the SDLC with AWS services based on environment variables, infrastructure tiers, and the type of applications or services you launch. Each of the AWS services you use in a deployment has its own configuration, or service-specific settings, which affect your deployment implementation. Consider the types of deployments that you will perform so that you can implement the most appropriate services into your seamless chain of events or a pipeline. This seamless or “continuous” chain of events on the AWS Cloud is the continuous integration/continuous deployment (CI/CD) pipeline.

Continuous Integration/Continuous Deployment

The CI/CD pipeline helps developers implement continuous builds, tests, and code deployments with multiple AWS resources and a continuous integration server. You can integrate AWS Elastic Beanstalk with the CI/CD pipeline as one of the deployment resources. You can also use AWS CodeCommit as a CI/CD resource paired with a Git repository, from which Elastic Beanstalk can extract and deploy code.

Continuous integration (CI) is the software development practice in which you continuously integrate (or check in) all code changes into a main branch of a central repository. This practice enables you to verify your code changes early and often with an automated build and test process. Whenever you check in code changes, engineers can automate various processes, such as building assets and testing code syntax. By implementing continuous integration practices, teams become more productive and develop new features more quickly. Teams also write scripts to validate the functionality and improve the quality of the software being released.

Continuous delivery (CD) is the software development practice in which all code changes are automatically prepared and always deployable (ready to go into production) at a single step.

Continuous delivery extends continuous integration to include testing production-like stages and running verification testing against those deployments. Although continuous delivery can extend to a production deployment, it requires manual intervention between a code check-in and when that code is available for customer use.

Practicing continuous delivery means that teams gain a greater level of certainty that their software will work in production.

Continuous deployment extends continuous delivery and is the automated release of software to customers, from check-in through production, without human intervention. Continuous deployment helps customers gain value quickly from the code base, with the development team getting faster feedback on the changes made.

Symbol of Note An important distinction between continuous delivery and continuous deployment is that in continuous deployment, changes are automatically released to production after build/test stages; there is no manual approval step.

Figure 6.2 displays the CI/DI pipeline.

The figure displays the continuous integration/continuous deployment (CI/CD) pipeline.

Figure 6.2 CI/DI pipeline

The CI/DI pipeline integrates with other AWS Code services, as illustrated in Figure 6.3.

The figure shows how the continuous integration/continuous deployment (CI/CD) pipeline integrates with other AWS Code services.

Figure 6.3 AWS Code services

AWS CodePipeline AWS CodePipeline is a service for fast and reliable application updates. You can model and visualize the software release process. To build, test, and deploy your code every time there is a code change, integrate this service with third-party tools and AWS.

AWS CodeCommit AWS CodeCommit is a secure, highly scalable, managed source-control service that hosts private Git repositories. It enables you to store and manage assets (such as documents, source code, and binary files) privately in the AWS Cloud.

AWS CodeBuild AWS CodeBuild compiles source code, runs tests, and produces ready-to-deploy software packages. There is no need to manage build servers.

AWS CodeDeploy AWS CodeDeploy automates code deployments to any instance. It handles the complexity of updating your applications, which avoids downtime during application deployment. It deploys to Amazon EC2 or on-premises servers, in any language and on any operating system. It also integrates with third-party tools and AWS.

Deploying Highly Available and Scalable Applications

Load balancing is an integral part to directing and managing traffic among your instances. As you launch applications in your environments, you will want them to have high performance and high availability for your users. To enable both of these features, a load balancer will be necessary.

Elastic Load Balancing (ELB) supports three types of load balancers: Application Load Balancers, Network Load Balancers, and Classic Load Balancers. You select a load balancer based on your application needs.

  • The Application Load Balancer provides advanced request routing targeted at delivery of modern application architectures, including microservices and container-based applications. It simplifies and improves the security of your application by ensuring that the latest Secure Sockets Layer (SSL)/Transport Layer Security (TLS) ciphers and protocols are used at all times. The Application Load Balancer operates at the request level (Layer 7) to route HTTP/HTTPS traffic to its targets: Amazon EC2 instances, containers, and IP addresses based on the content of the request. It is ideal for advanced load balancing of HTTP and HTTPS traffic.
  • The Network Load Balancer operates at the connection level (Layer 4) to route TCP traffic to targets: Amazon EC2 instances, containers, and IP addresses based on IP protocol data. It is the best option for load balancing of TCP traffic because it’s capable of handling millions of requests per second while maintaining ultra-low latencies. Network Load Balancer is optimized to handle sudden and volatile traffic patterns while using a single static IP address per Availability Zone. It is integrated with other popular AWS services, such as AWS Auto Scaling, Amazon Elastic Container Service (Amazon ECS), and AWS CloudFormation. Amazon ECS provides management for deployment, scheduling, and scaling, and management of containerized applications.
  • The Classic Load Balancer provides basic load balancing across multiple Amazon EC2 instances and operates at both the request level and the connection level. The Classic Load Balancer is intended for applications that were built within the EC2-Classic network. When you’re using Amazon Virtual Private Cloud (Amazon VPC), AWS recommends the Application Load Balancer for Layer 7 and Network Load Balancer for Layer 4).

Figure 6.4 displays the flow for deploying highly available and scalable applications.

The figure displays the flow for deploying highly available and scalable applications.

Figure 6.4 Deploying highly available and scalable applications

The flow for deploying highly available and scalable applications includes the following components:

  • Multiple Availability Zones and AWS Regions.
  • Health check and failover mechanism.
  • Stateless application that stores the session state in a cache server or database.
  • AWS services that help you to achieve your goal. For example, Auto Scaling helps you maintain high availability and scalability.

Symbol of Tip Elastic Load Balancing and Auto Scaling are designed to work together.

Deploying and Maintaining Applications

AWS provides several services to manage your application and resources, as shown in Figure 6.5.

The figure shows how AWS provides several services to manage the application and resources.

Figure 6.5 Deployment and maintenance services

With AWS Elastic Beanstalk, you do not have to worry about managing the infrastructure for your application. You deploy your application, such as a Ruby application, in a Ruby container, and Elastic Beanstalk takes care of scaling and managing it.

AWS OpsWorks is a configuration and deployment management tool for your Chef or Puppet resource stacks. Specifically, OpsWorks for Chef Automate enables you to manage the lifecycle of your application in layers with Chef recipes. It provides custom Chef cookbooks for managing many different types of layers so that you can write custom Chef recipes to manage any layer that AWS does not support.

AWS CloudFormation is infrastructure as code. The service helps you model and set up AWS resources so that you can spend less time managing them. It is a template-based tool, with formatted text files in JSON or YAML. You can create templates to define what AWS infrastructure you want to build and any relationships that exist among the parts of your AWS infrastructure.

Symbol of Note Use AWS CloudFormation templates to provision and configure your stack resources.

Automatically Adjust Capacity

Use AWS Auto Scaling to monitor the AWS resources that are part of your application. The service automatically adjusts capacity to maintain steady, predictable performance. You can build scaling plans to manage your resources, including Amazon EC2 instances and Spot Fleets, Amazon Elastic Container Registry (Amazon ECR) tasks, Amazon DynamoDB tables and indexes, and Amazon Aurora Replicas.

AWS Auto Scaling makes scaling simple, with recommendations that allow you to optimize performance, costs, or balance between them. If you are already using EC2 Auto Scaling to scale your Amazon EC2 instances dynamically, you can now combine it with AWS Auto Scaling to scale additional resources for other AWS services. With AWS Auto Scaling, your applications have the right resources at the right time.

Auto Scaling Groups

An Auto Scaling group contains a collection of Amazon EC2 instances that share similar characteristics. This collection is treated as a logical grouping to manage the scaling of instances. For example, if a single application operates across multiple instances, you might want to increase the number of instances in that group to improve the performance of the application or decrease the number of instances to reduce costs when demand is low.

You can use the Auto Scaling group to scale the number of instances automatically based on criteria that you specify or maintain a fixed number of instances even if an instance becomes unhealthy. This automatic scaling and maintaining the number of instances in an Auto Scaling group make up the core functionality of the EC2 Auto Scaling service.

An Auto Scaling group launches enough Amazon EC2 instances to meet its desired capacity. The Auto Scaling group maintains this number of instances by performing periodic health checks on the instances in the group. If an instance becomes unhealthy, the group terminates the unhealthy instance and launches another instance to replace it.

You can use scaling policies to increase or decrease the number of instances in your group dynamically to meet changing conditions. When the scaling policy is in effect, the Auto Scaling group adjusts the desired capacity of the group and launches or terminates the instances as needed. You can also manually scale or scale on a schedule.

AWS Elastic Beanstalk

AWS Elastic Beanstalk is an AWS service that you can use to deploy applications, services, and architecture. It provides provisioned scalability, load balancing, and high availability. It uses common languages, including Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker, on common-type web servers, such as Apache, NGINX, Passenger, and IIS.

Symbol of Note Elastic Beanstalk charges only for the resources you use to run your application.

Elastic Beanstalk is a solution that enables the automated deployments and management of applications on the AWS Cloud. Elastic Beanstalk can launch AWS resources automatically with Amazon Route 53, AWS Auto Scaling, Elastic Load Balancing, Amazon EC2, and Amazon Relational Database Service (Amazon RDS) instances, and it allows you to customize additional AWS resources.

Deploy applications without worrying about managing the underlying technologies, including the following:

Components

  • Environments
  • Application versions
  • Environment configurations

Permission Model

  • Service role
  • Instance profile

Figure 6.6 displays the Elastic Beanstalk underlying technologies.

The figure shows the AWS Elastic Beanstalk underlying technologies.

Figure 6.6 AWS Elastic Beanstalk underlying technologies

Elastic Beanstalk supports customization and N-tier architectures. It mitigates common manual configurations required in a traditional infrastructure deployment model. With Elastic Beanstalk, you can also create repeatable environments and reduce redundancy, thus rapidly updating environments and facilitating service-managed application stacks. You can deploy multiple environments in minutes and use various automated deployment strategies.

Symbol of Tip AWS Elastic Beanstalk allows you to focus on building your application.

Implementation Responsibilities

AWS and our customers share responsibility for achieving a high level of software component security and compliance. This shared model reduces your operational burden. The service you select determines the level of your responsibility. For example, Elastic Beanstalk helps you perform your side of the shared responsibility model by providing a managed updates feature. This feature automatically applies patch and minor updates for an Elastic Beanstalk supported platform version.

Developer Teams

Using AWS Elastic Beanstalk, you build full-stack environments for web and worker tiers. The service provides a preconfigured infrastructure.

  • Single-instance (development, low cost)
  • Load balanced, AWS Auto Scaling (production)

Elastic Beanstalk Responsibilities

Elastic Beanstalk provisions the necessary infrastructure resources, such as the load balancer, Auto Scaling group, security groups, and database (optional). It also provides a unique domain name for your application (for example, yourapp.elasticbeanstalk.com).

Figure 6.7 displays Elastic Beanstalk responsibilities.

The figure shows Elastic Beanstalk responsibilities.

Figure 6.7 AWS Elastic Beanstalk responsibilities

Working with Your Source Repository

Developer teams generally begin their SDLC processes by managing their source code in a source repository. Uploading and managing the multiple changes on application source code is a repeated process. With Elastic Beanstalk, you can create an application, upload a version of the application as a source bundle, and provide pertinent information about the application.

The first step is to integrate Elastic Beanstalk with your source code to create your source bundle. As your source repository, you can install Git for your applications or use an existing repository and map your current branch from a local repository in Git to retrieve the source code.

Alternatively, you can use AWS CodeCommit as a source control system to retrieve source code. By using Elastic Beanstalk with the AWS CodeCommit repository, you extract from a current branch on CodeCommit.

To deploy a new application or application version, Elastic Beanstalk works with source bundles or packaged code. Prepare the code package with all of the necessary code dependencies and components.

Elastic Beanstalk can either retrieve the source bundle from a source repository or download the bundle from an Amazon Simple Storage Service (Amazon S3) bucket. You can use the IAM role to grant Elastic Beanstalk access to all services. The service accesses the source bundle from the location you designate, extracts the components from the bundle, deploys new application versions by launching the code, creates and configures the infrastructure, and allocates the platform on Amazon EC2 instances to run the code.

The application runs on the resources and instances that the service generates. Your configuration for these resources and your application will become your environment settings, supporting the entire configuration of your deployment. Each deployment has an auto-incremented deployment identity (ID), so you are able to manage your multiple running deployments. Think of these as multiple running code releases in the AWS Cloud.

Symbol of Note You can also work with different hosting services, such as GitHub or Bitbucket, with your code source.

Concepts

AWS Elastic Beanstalk enables you to manage all the resources that run your application as environments. This section describes some key Elastic Beanstalk concepts.

Application

Elastic Beanstalk focuses on managing your applications as environments and all of the resources to run them. Each application that launches in the service is a logical collection of environment variables and components, application versions, and environment configurations.

Application Versions

Application versions are iterations of the application’s deployable code. Application versions in Elastic Beanstalk point to an Amazon S3 object with the code source package. An application can have many versions, with each version being unique. You can deploy and access any application version at any time. For example, you may want to deploy different versions for different types of tests.

Environment

Each Elastic Beanstalk environment is a separate version of the application, and that version’s AWS Cloud components deploy onto AWS resources to support that version. Each environment runs one application version at a time, but you can run multiple environments, with the same application on each, along with its own customizations and resources.

Environment Tier

To launch an environment, you must first choose an environment tier. Elastic Beanstalk provisions the required resources to support both the infrastructure and types of requests the application will support. The environment can launch and access other AWS resources. For example, it may pull tasks from Amazon Simple Queue Service (Amazon SQS) queues or store temporary configuration files in Amazon S3 buckets (according to your customizations). Each environment will then have an environment configuration—a collection of settings and parameters based on your customizations that define associated resources and how the environment will work.

Environment Configuration

You can change your environment to create, modify, delete, or deploy resources and change the settings for each. Your environment configuration saves to a configuration template exclusive to each environment and is accessible by either the Elastic Beanstalk application programming interface (API) calls or the service’s command line interface (EB CLI).

In Elastic Beanstalk, you can run either a web server environment or a worker environment. Figure 6.8 displays an example of a web server environment running in Elastic Beanstalk with Amazon Route 53 as the domain name service (DNS) and ELB to route traffic to the web server instances.

The figure displays an example of a web server environment running in Elastic Beanstalk with Amazon Route 53 as the domain name service (DNS) and Elastic Load Balancing to route traffic to the web server instances.

Figure 6.8 Application running on AWS Elastic Beanstalk

Figure 6.9 shows a worker environment architecture, where AWS resources create configurations, such as Auto Scaling groups, Amazon EC2 instances, and an IAM role, to manage resources for your worker applications.

The figure shows a worker environment architecture, where AWS resources create configurations, such as Auto Scaling groups, Amazon EC2 instances, and an IAM role, to manage resources for your worker applications.

Figure 6.9 Worker tier on AWS Elastic Beanstalk

For the worker environment tier, Elastic Beanstalk creates and provisions additional resources and files to support the tier. This includes services like Amazon SQS queues operating between worker applications, AWS Auto Scaling groups, security groups, and EC2 instances.

The worker environment infrastructure uses all of your customization and provision resources to determine the types of requests it receives.

Docker Containers

You can also use Docker containers with Elastic Beanstalk to run your applications from a container. Install Docker, choose the software you require, and select the Docker images you want to launch. Define your runtime environment, platform, programming language, and application dependencies and tools. Docker containers are self-contained and include configurations and software that you specify for your application to run. Each Docker container restarts automatically if another container crashes. When you choose to deploy your applications with Docker containers, your infrastructure is provisioned with capacity provisioning, load balancing, scaling, and health monitoring, much like a noncontainer environment. You can continue to manage your application and the AWS resources you use.

Docker requires platform configurations that enable you to launch single or multicontainer deployments. A single container deployment launches a single Docker image, and your application uses a single container configuration for a single Amazon EC2 instance. A multicontainer deployment uses the Amazon ECS to launch a cluster of containers with Docker images. A multicontainer configuration is applied to each instance. You can also run preconfigured Docker platform configurations with generic customization for popular software stacks that you want to use for your application.

AWS Elastic Beanstalk Command Line Interface

Elastic Beanstalk has its own command line interface separate from the AWS CLI tool. To create deployments from the command line, you download and install the AWS Elastic Beanstalk CLI (EB CLI).

Table 6.1 lists common EB CLI commands.

Table 6.1 Common AWS Elastic Beanstalk Commands

Command Definition
eb init application-name Sets default values for Elastic Beanstalk applications with the EB CLI configuration wizard
eb create Creates a new environment and deploys an application version to it
eb deploy Deploys the application source bundle from the initialized project directory to the running application
eb clone Clones an environment to a new environment so that both have identical environment settings
eb codesource Configures the EB CLI to deploy from an AWS CodeCommit repository, or disables AWS CodeCommit integration and uploads the source bundle from your local machine

Customizing Environment Configurations

You can use Elastic Beanstalk to customize the platforms used to support your application and your infrastructure. To do so, create a configuration file in the ebextensions directory (or .ebextensions) to include with your web application’s source code. The configuration file allows for simple and advanced customizations of your environment and contains settings for your AWS resources. To deploy customized resources to support your application source bundle, use YAML to configure the file.

The configuration file has several sections. The option_settings section defines your configuration option values for your AWS resources. The resources section adds further customization in your application environment beyond the service functionality, which includes AWS CloudFormation–supported resources that Elastic Beanstalk can access and run. The remaining sections allow for fine-grained configurations to integrate packages, sources, files, and container commands.

Symbol of Note Launch environments from integrated development environment (IDE) tools to avoid poorly formatted configurations and source bundles that could cause unrecoverable failures.

You apply configuration files in the ebextensions directory to Elastic Beanstalk stacks. The stacks are the AWS resources that you allocate for your infrastructure and application. If you have any resource, such as Amazon VPC, Amazon EC2, or Amazon S3, that was updated or configured, these files deploy with your changes. You can zip your ebextension files, upload, and apply them to multiple application environments. You can view your environment variables in option_settings for future evaluation or changes. These are accessible from the AWS Management Console, command line, and API calls.

Symbol of Tip You can view Elastic Beanstalk stacks in AWS CloudFormation, but always use the Elastic Beanstalk service and ebextensions to make modifications. This way, edits and modifications to the application stacks are simplified without introducing unrecoverable failures.

Elastic Beanstalk generates logs that you can view to troubleshoot your environments and resources. The logs display Amazon EC2 operational logs and logs that are specific to servers running for your applications.

Integrating with Other AWS Services

Elastic Beanstalk automatically integrates or manages other AWS services with application code to provision efficient working environments. However, you might find it necessary to add additional services, such as Amazon S3 for content storage or Amazon DynamoDB for data records, to work with an environment. To grant access between any integrated service and Elastic Beanstalk, you must configure permissions in IAM.

Amazon S3

You can use Amazon S3 to store static content you want to integrate with your application and point directly to objects you store in Amazon S3 from your application or from other resources. In addition to setting permissions in IAM policies, take advantage of presigned URLs for controlled Amazon S3 GET and PUT operations.

Amazon CloudFront

You can integrate your Elastic Beanstalk environment with Amazon CloudFront, which provides content delivery and distribution through the use of edge locations throughout the world. This can decrease the time in which your content is delivered to you, as the content is cached and routed through the closest edge location serving you. After you deploy your application on Elastic Beanstalk, use the Amazon CloudFront content delivery network (CDN) to cache static content from your application. To identify the source of your content in Amazon CloudFront, you can use URL path patterns to cache your content and then retrieve it from the cache. This approach serves your content more rapidly and offloads requests directly sourced from your application.

AWS Config

With AWS Config, you can visualize configuration history and how configurations evolve over time. Tracking changes helps you to fulfill compliance obligations and meet auditing requirements. You can integrate AWS Config directly with your application and its versions or your Elastic Beanstalk environment. You can customize AWS Config to record changes per resource, per region, or globally. In the AWS Config console, you can select Elastic Beanstalk resource types to record specific applications and environment resources. You can view the recorded information in the AWS Config dashboard under Resource Inventory.

Amazon RDS

Various options are available for creating databases for your environment, such as Amazon Relational Database Service (Amazon RDS) for SQL databases and Amazon DynamoDB for NoSQL databases. Elastic Beanstalk can create a database and store and retrieve data for any of your environments. Each service has its own features to handle scaling, capacity, performance, and availability.

To store, read, or write to your data records, you can set up an Amazon RDS database instance or an Amazon DynamoDB table by using the same configuration files for your other service option settings. You must create connections to the database, which require you to set up password management in Elastic Beanstalk. Your configurations are saved in the ebextensions directory. You can also create direct connections, within your application code or application configuration files, to both internal and external databases. When using Amazon RDS, avoid accidentally deleting and re-creating databases without a properly installed backup. To reduce the risk of losing data, take a manual snapshot of the master Amazon RDS database immediately before deleting.

Symbol of Note If you create periodic tasks with a worker environment, Elastic Beanstalk automatically creates an Amazon DynamoDB table to perform leader election and stores task information.

Amazon ElastiCache

For caching capabilities, you can integrate Amazon ElastiCache service clusters with the Elastic Beanstalk environment. If you use a nonlegacy container, you can set your configuration files to use the supported container and then offload requests to the cache cluster. Doing so enables you to increase the performance of your application and databases running in your Elastic Beanstalk environment.

AWS Identity and Access Management Roles

Elastic Beanstalk integrates with AWS Identity and Access Management (IAM) roles to enable access to the services you require to run your architecture.

When you launch the service to create an environment, a default service role and instance profile are created for you through the service API. Managed policies for resources permissions are also attached, including policies for Elastic Beanstalk instance health monitoring within your infrastructure and platform updates that can be made on behalf of the service. These policies, called AWSElasticBeanstalkEnhancedHealth and AWSElasticBeanstalkService, attach to the default service role and enable the default service role to specify a trusted entity and trust policy.

When you use commands from the EB CLI, the role allows automatic management of the AWS Cloud that services you run. The service creates an environment, if you don’t identify it specifically; creates a service-linked role; and uses it when you spin up a new environment. To create the environment successfully, the CreateServiceLinkedRole policy must be available in your IAM account.

You use IAM roles to automate the management of allocated services for your application through Elastic Beanstalk. With IAM, you can also launch code with inline policies. It is important to understand how the service creates and uses the roles to keep your application and data secure.

Symbol of Tip For IAM to manage the policies for the account better, create policies at the account level.

Deployment Strategies

A deployment is the process of copying content and executing scripts on instances in your deployment group. To accomplish this, AWS CodeDeploy performs the tasks outlined in the AppSpec configuration file. For both Amazon EC2 on-premises instances and AWS Lambda functions, the deployment succeeds or fails based on whether individual AppSpec tasks complete successfully.

After you have created a deployment, you can update it as your application or service changes. You can update a deployment by adding or removing resources from a deployment, thus updating the properties of existing resources in a deployment.

Symbol of Note A serverless application is typically a combination of AWS Lambda and other AWS services.

To create seamless deployments, choose an effective deployment strategy. Each strategy has specific advantages relative to different use cases. Appropriate strategies help create deployments where you experience minimal or no downtime, and you can apply the strategy for different purposes within your environments. Each change needs a strategy that best fits your application deployments.

All-at-Once and In-Place Deployments

An all-at-once deployment applies updates to all your instances at once. When you execute this strategy, you experience downtime, as all instances receive the change at the same time.

This is an appropriate strategy for simple, immediate update requirements when it’s not critical to have your application always available, and you’re comfortable with the site being offline for a short duration. To enable all-at-once updates, set a deployment policy either in the AWS Management Console or in the command line (DeploymentPolicy).

When you perform an in-place deployment, AWS CodeDeploy stops currently running applications on the target instance, deploys the latest revision, restarts applications, and validates successful deployment. In-place deployments can support the automatic configuration of a load balancer. In this case, the instance is deregistered from the load balancer before deployment and registered again after the deployment processes successfully.

In-place updates are also available for your platform updates, such as a coding-language platform update for a web server. Select the new platform and then run the update from the AWS Management Console or command line directly as a platform update.

Symbol of Note AWS Lambda does not support in-place deployments.

Rolling Deployments

A rolling deployment applies changes to all of your instances by rolling the updates from one instance to another. Elastic Beanstalk can deploy configuration changes in batches. This approach reduces possible downtime during implementation of the change and allows available instances to run while you deploy.

As updates are applied in a batch, the batch will be out of service for a short period while the changes propagate and then relaunch with the new configuration. When the change is complete, the service moves on to the next batch of instances to apply the changes. With this strategy, you can implement both periodic changes and pauses between updates. For example, you might specify a time to wait between health-based updates so that instances must pass health checks before moving on to the next batch. If the rolling update fails, the service begins another rolling update for a rollback to the previous configuration.

Rolling updates include changes for Auto Scaling group configurations, Amazon EC2 instance configurations, and Amazon VPC settings. It is an effective method for updating an application version on fleets of instances through the Elastic Beanstalk service. To enable rolling updates, set a deployment policy either in the AWS Management Console or in the command line (DeploymentPolicy) and choose this strategy along with specific options. You can select Rolling or Rolling with additional batch. By using Rolling with additional batch, you can launch a new batch of instances before you begin to take instances out of service for your rolling updates. This option provides an available batch for rollback from a failed update. After the deployment is successfully executed, Elastic Beanstalk terminates the instances from the additional batch. This is helpful for a critical application that must continue running with less downtime than the standard rolling update.

Blue/Green Deployment

When high availability is critical for applications, you may want to choose a blue/green deployment, where your newer environment will be separate from your existing environment. The running production environment is considered the blue environment, and the newer environment with your update is considered the green environment. When your changes are ready and have gone through all tests in your green environment, you can swap the CNAMEs of the environments to redirect traffic to the newer running environment. This strategy provides an instantaneous update with typically zero downtime.

When you deploy to AWS Lambda functions, blue/green deployments publish new versions of each function. Traffic shifting then routes requests to the new functioning versions according to the deployment configuration you define.

If your infrastructure contains Amazon RDS database instances, the data does not automatically transfer to the new environment. Without performing backups, you will experience data loss when you use the blue/green strategy. If you have Amazon RDS instances in your infrastructure, implement a different deployment strategy or a series of steps to create snapshot backups outside of Elastic Beanstalk before you execute this type of deployment.

Immutable Deployment

An immutable deployment is best when an environment requires a total replacement of instances, rather than updates to an existing part of an infrastructure. This approach implements a safety feature for updates and rollbacks. Elastic Beanstalk creates a temporary Auto Scaling group behind your environment’s load balancer to contain the new instances with the updates you apply. If the update fails, the rollback process terminates the Auto Scaling group. Immutable instances implement a number of health checks. If all instances pass these checks, Elastic Beanstalk transfers the new configurations to the original Auto Scaling group, providing an additional check before you apply your changes to other instances. Enhanced health reports evaluate instance health in the update. After the updates are made, Elastic Beanstalk deletes the temporary Auto Scaling group of the older instances.

Symbol of Note During this type of deployment, your capacity doubles for a short duration between the updates and terminations of instances. Before you use this strategy, verify that your instances have a low on-demand limit and enough capacity to support immutable updates.

See Table 6.2 for feature comparisons between all deployment strategies. The check mark indicates options that the deployment strategy supports.

Table 6.2 Deployment Strategies

Method Impact of Failed Deployment Deploy Time Zero Downtime No DNS Change Rollback Process Code Deployed To
All-at-once Downtime Symbol of Watch Redeploy Existing instances
In-place Downtime Symbol of Watch Redeploy Existing instances
Rolling Single batch out of service; any successful batches before failure running new application version Symbol of Watch Symbol of Watch Redeploy Existing instances
Rolling with additional batch Minimal if first batch fails; otherwise, similar to Rolling Symbol of Watch Symbol of Watch Symbol of Watch Redeploy New and existing instances
Blue/Green Minimal Symbol of Watch Symbol of Watch Symbol of Watch Symbol of Watch Swap URL New instances
Immutable Minimal Symbol of Watch Symbol of Watch Symbol of Watch Symbol of Watch Redeploy New instances

Container Deployments

Elastic Beanstalk enables you to launch your applications with Docker containers. With a Docker container, you can create a runtime environment with all of the dependencies, packages, and tools that your application may require to run. Your container can have all of the configurations necessary for your application. By using Docker with Elastic Beanstalk, you have the infrastructure for capacity provisioning, scalability, load balancing, and health monitoring for the instances that run on containers. The containers integrate with your Amazon VPC for network requirements and with IAM to enable resource management. You can launch different software engines with containers to provide various options and third-party tools to run containers.

You can choose from single container configurations and multicontainer configurations. A single container runs one container per instance. A multicontainer runs multiple applications or engines on one instance, with all of the software and settings you require. Preconfigured options are available with Docker, and you can integrate them with instances that run in your architecture through Elastic Beanstalk.

Monitoring and Troubleshooting

After you launch your code, check on its performance and availability. You can monitor statistics and view information about the health of your application, its environment, and specific services from the AWS Management Console. Elastic Beanstalk also creates alerts that trigger at established thresholds to monitor your environment’s health. In the AWS Management Console, the AWS Elastic Beanstalk Monitoring page shows aggregated statistics and graphs for your applications and resources. Each environment is color-coded to indicate the environment’s status. You can see at a glance whether your environment is available online at any point in time. Metrics gathered by the resources in your environment are published to Amazon CloudWatch in five-minute intervals. You can adjust the time range for the statistics and graphs and customize your views of the metrics.

Figure 6.10 shows an example of the statistics that you can view for your environment.

The figure shows an example of the statistics that you can view for your environment.

Figure 6.10 Health dashboard on AWS Elastic Beanstalk

Figure 6.11 shows an example of the graphs that you can view.

The figure shows a screenshot illustrating the AWS Elastic Beanstalk Monitoring page colors.

Figure 6.11 Metrics for monitoring on AWS Elastic Beanstalk

Table 6.3 defines the AWS Elastic Beanstalk Monitoring page colors.

Table 6.3 AWS Elastic Beanstalk Health Page Color Definitions

Color Description
Gray Your environment is being updated.
Green Your environment has passed the most recent health check. At least one instance in your environment is available and taking requests.
Yellow Your environment has failed one or more health checks. Requests to your environment are failing.
Red Your environment has failed three or more health checks, or an environment resource has become unavailable. Requests are consistently failing.

By default, Elastic Beanstalk displays Amazon EC2, Auto Scaling, and Elastic Load Balancing metrics for your application environments. These metrics are available to you on your AWS Elastic Beanstalk Monitoring page as soon as you deploy your application environment. You can access the health status from the AWS Management Console or the EB CLI.

Basic Health Monitoring

To access the health status from the AWS Management Console, select the Elastic Beanstalk service and then select the tab for your specific application environment. An environment overview shows your architecture’s instance status details, resource details, and filter capabilities. Health statuses are indicated in four distinct colors.

To access the health status from the EB CLI, enter the eb health command. The output shows the environment and the health of associated instances. Enhanced health reporting also provides the following seven health statuses, which are single-word descriptors that provide a better indication of the state of your environment:

ok   warning   degraded   severe   info   pending   unknown

You can also use the eb status command in the EB CLI or the DescribeEnvironments API call to retrieve the health status for an environment. You can check the health of the overall environment or the individual services of Amazon EC2 or an Elastic Load Balancing load balancer. Health checks on your Elastic Load Balancing port execute both for the default port 80 and a custom Elastic Load Balancing port/path.

For GET requests with the load balancer, 200 OK is the default success code and indicates a healthy status. The service can also return 400 level responses. You can also configure a health check URL for custom static page responses.

Symbol of Note Be sure to adjust the caching time to live for any health check static pages or URLs in Amazon CloudFront or for any caching mechanism you may use.

Elastic Beanstalk also reports missing configurations or other issues that could affect the health of the application environment.

Enhanced Health Monitoring

There are two types of reporting: the default health information about your resources and the enhanced health reporting that provides you more information for monitoring health.

You can use the enhanced health reporting feature to gather additional resource data and display graphs and statistics of environment health in greater detail. This is important when you deploy multiple versions of your application and when you need to analyze factors that could be degrading your application’s availability or performance. You can view these details in the AWS Elastic Beanstalk Monitoring page from the AWS Management Console. These reports require the creation of two IAM roles: a service role to allow access between the services and Elastic Beanstalk and an instance profile to write logs into an Amazon S3 bucket.

Symbol of Note Running the enhanced health report requires a version 2 or newer platform configuration that supports all platforms except Windows Server with IIS. The enhanced health reports provide data directly to Elastic Beanstalk and do not run through Amazon CloudWatch.

By default, health monitoring on Elastic Beanstalk does not publish metrics to Amazon CloudWatch, so you are not charged for the metrics. There are also custom metrics that you can run and view, for which you are not charged a fee. You can enable custom metrics by using the PutMetricData operation in worker environments. For example, you might have an Amazon SQS daemon that publishes custom metrics for environment health under the same environment namespace. You can also enable custom metrics from Amazon CloudWatch, but AWS charges for these additional metrics you publish to your monthly Amazon CloudWatch. To save costs, use the available metrics on the Elastic Beanstalk service, or enable the custom metrics that you need, paying only for what you use.

Elastic Beanstalk runs a health agent to provide detailed health resource data for enhanced health monitoring. The health agent runs in the Amazon Machine Image (AMI) for each instance operating system on a platform configuration for your application. The agent analyzes system metrics and logs to communicate the health status to Elastic Beanstalk. You receive alerts, data, and actionable insights that you can use to monitor your applications and understand, prevent, and respond to performance issues.

You can monitor recent health events that you have enabled on Elastic Beanstalk in real time. There are several health event types that can change as an environment transitions from the create state to the run state. Figure 6.12 displays the health events available in the AWS Elastic Beanstalk Monitoring page and examples of the details that allow you to respond to issues identified.

The figure shows a screenshot illustrating the health events available in the AWS Elastic Beanstalk Monitoring page and also shows examples of the details that allow you to respond to issues identified.

Figure 6.12 Events on AWS Elastic Beanstalk

Elastic Beanstalk integrates with AWS CloudTrail to capture Elastic Beanstalk API calls as log files that you can store in an Amazon S3 bucket. To view additional actions occurring with your running resources, you can also capture AWS API calls in your code using AWS CloudTrail.

Summary

In this chapter, you learned about the features of Elastic Beanstalk, how to automate deployments for your multi-tier architectures, and different deployment strategies. You also discovered options for configuring your environments and managing your resources with services such as IAM, Amazon VPC, Amazon EC2, and Amazon S3.

Exam Essentials

Know how to deploy AWS Elastic Beanstalk. Know how to deploy an application AWS Elastic Beanstalk and what platforms it supports. To complete the exam successfully, you should also understand how the architectures and services interact with the web, application, and database tiers. Focus on foundational services and how you create and work with Elastic Beanstalk.

Know about ebextensions. Understand ebextensions and the part they play in the service configuration. Be able to recognize the stacks you create and how to change them.

Know about Elastic Beanstalk resources. Understand how to manage resources with Elastic Beanstalk, including IAM. Understand the definitions and differentiate between the functions of the default IAM service role and the instance profile, which are automatically created. Understand permissions for your AWS resources in your environment.

Know Elastic Beanstalk deployment strategies. Understand what deployment strategies you can use, their differences, and which ones would be best for different use cases and other resources. Know which strategy offers less downtime and which is best suited for complex changes.

Know about Elastic Beanstalk components. Understand all of the components of Elastic Beanstalk, including applications, environments, versions, configurations, and the AWS resources it launches and with which it integrates. Know how to retain or dispose of resources as needed.

Know about Elastic Beanstalk different environment tiers. Know the differences between the single-instance tier and the web-server environment tier and when to choose one over the other. Understand the services and features used for both.

Symbol of Tip On the test itself, do not get sidetracked with small details about Elastic Beanstalk. Focus your understanding on how it works as a whole and interacts with other services.

Resources to Review

Exercises

Exercise 6.1

Deploy Your Application

In this exercise, you will sign up for an AWS account.

  1. Verify that your source code is packaged as a .zip file and is ready to be retrieved from either your source repository directory or an Amazon S3 bucket.

  • You can choose a sample application available from the AWS Management Console.

  1. Launch the AWS Management Console.
  2. To select a region in which to launch the application, select AWS Elastic BeanstalkRegion.
  3. Select AWS Elastic Beanstalk Service.
  4. Select Get Started or Create New Application. The Get Started option takes you through a wizard of guided steps to launch your first application. After this initial start, the Create New Application dialog box will be displayed for future launches.
  5. Select the type of application that you want to deploy.
  6. Enter an application name.
  7. Select the application platform for your code.
  8. For your coding language, select the preconfigured platform.
  9. Select Upload your application.
  10. Locate the file directory where your .zip file of your code resides or choose the Amazon S3 bucket with the .zip file and select Upload.
  11. Choose Next.
  12. To use the architecture with high availability, select High Availability.
  13. Modify the configurations for your architecture.
  14. Select Add databases.
  15. Select RDS database.
  16. Choose Create App (Application).

  • You now have successfully deployed an application on Elastic Beanstalk.

Exercise 6.2

Deploy a Blue/Green Solution

In this exercise, you will deploy a blue/green solution.

  1. Sign in to your AWS account.
  2. Navigate to your existing AWS Elastic Beanstalk environment and application or upload the sample.

  1. Clone your environment or launch a new environment with your new version.
  2. Deploy the second application version to the new environment. Test that the new version is running.
  3. From the new environment dashboard, select ActionsSwap Environment URLs.
  4. Under Select an Environment to Swap, select the current environment name.
  5. Choose Swap.

  • The Elastic Beanstalk service swaps the CNAME records between the two environments.

  1. On the dashboard, under Recent Events, verify the swap.

You have successfully deployed a blue/green solution on AWS Elastic Beanstalk.

Exercise 6.3

Change Your Environment Configuration on AWS Elastic Beanstalk

In this exercise, you will change your environment configuration on AWS Elastic Beanstalk. Use an existing application that is running on Elastic Beanstalk.

  1. Sign in to your AWS account.
  2. Navigate to your existing AWS Elastic Beanstalk environment and application.
  3. Choose Configuration.
  4. On the Capacity Configuration tab, choose Modify.
  5. Under Auto Scaling Group, select Load balanced.
  6. In the Instances row, change Max to 4 and Min to 2.
  7. On the Modify capacity page, choose Save.
  8. On the Configuration overview page, choose Apply.
  9. On the warning message, choose Confirm.

  • The environment might take a few minutes to update. After your environment is updated, verify your changes.

  1. Navigate to the Amazon EC2 service dashboard.
  2. Choose Load Balancers.
  3. Check for the instance-id value that matches your Elastic Beanstalk environment instance-id value and view the load balancers.

You have successfully changed an environment configuration on AWS Elastic Beanstalk.

Exercise 6.4

Update an Application Version on AWS Elastic Beanstalk

In this exercise, you will update an application version on AWS Elastic Beanstalk from the AWS Management Console.

  1. Sign in to your AWS account.
  2. Upload a second version your application that matches the configuration for your current running environment.

  1. On the AWS EB applications page, select getting-started-app.
  2. Select GettingStartedApp-env.
  3. In Overview, choose Upload and Deploy.
  4. Select Choose File and upload the next version of your source bundle that you created or downloaded.

  • The console is automatically populated with the version label based on the name of the archive that you upload. For later deployments, if you use a source bundle with the same name, you must type a unique version label.

  1. Choose Deploy. Elastic Beanstalk deploys your application to your Amazon EC2 instances.

  • You can view the status of the deployment on the environment’s dashboard. The Environment Health status turns gray while the application version is being updated. When deployment is complete, Elastic Beanstalk executes an application health check. The status reverts to green when the application responds to the health check. The environment dashboard shows the new running version as the new version label. Your new application version is added to the table of application versions.

  1. To view the table, select Application Versions.

  • You have updated an application version on AWS Elastic Beanstalk.

Review Questions

  1. Which of the following AWS services enables you to automate your build, test, deploy, and release process every time there is a code change?

    1. AWS CodeCommit
    2. AWS CodeDeploy
    3. AWS CodeBuild
    4. AWS CodePipeline
  2. Which of the following resources can AWS Elastic Beanstalk use to create a web server environment? (Select FOUR.)

    1. Amazon Cognito User Pool
    2. AWS Serverless Application Model (AWS SAM) Local
    3. Auto Scaling group
    4. Amazon Elastic Compute Cloud (Amazon EC2)
    5. AWS Lambda
  3. Which of the following languages is not supported by AWS Elastic Beanstalk?

    1. Java
    2. Node.js
    3. Objective C
    4. Go
  4. What does the AWS Elastic Beanstalk service do?

    1. Deploys applications and architecture
    2. Stores static content
    3. Directs user traffic to Amazon Elastic Compute Cloud (Amazon EC2) instances
    4. Works with dynamic cloud changes as an IP address
  5. Which operating systems does AWS Elastic Beanstalk support? (Select TWO.)

    1. Amazon Linux
    2. Ubuntu
    3. Windows Server
    4. Fedora
    5. Jetty
  6. Which of the following components can AWS Elastic Beanstalk deploy? (Select TWO.)

    1. Amazon Elastic Compute Cloud (Amazon EC2) instances with write capabilities to an Amazon DynamoDB table
    2. A worker application using Amazon Simple Queue Service (Amazon SQS)
    3. An Amazon Elastic Container Service (Amazon ECS) cluster supporting multiple containers
    4. A mixed fleet of Spot and Reserved Instances with four applications running in each environment
    5. A mixed fleet of Reserved Instances scheduled between 9 a.m. to 5 p.m. and On-Demand Instances used for processing data workloads when needed randomly
  7. Which of the following operations can AWS Elastic Beanstalk do? (Select TWO.)

    1. Access an Amazon Simple Storage Service (Amazon S3) bucket
    2. Connect to an Amazon Relational Database Service (Amazon RDS) database
    3. Install agents for Amazon GuardDuty service
    4. Create and manage Amazon WorkSpaces
  8. Which service can be used to restrict access to AWS Elastic Beanstalk resources?

    1. AWS Config
    2. Amazon Relational Database Service (Amazon RDS)
    3. AWS Identity and Access Management (IAM)
    4. Amazon Simple Storage Service (Amazon S3)
  9. Which AWS Identity and Access Management (IAM) entities are used when creating an environment? (Select TWO.)

    1. Federated role
    2. Service role
    3. Instance profile
    4. Profile role
    5. User name and access keys
  10. Which of the following describes how customers are charged for AWS Elastic Beanstalk?

    1. A monthly fee based on an hourly rate for use.
    2. A one-time upfront cost for each environment running.
    3. No additional charges.
    4. A fee is charged only when scaling to support traffic changes.
  11. Which account is billed for user-accessed AWS resources allocated by AWS Elastic Beanstalk?

    1. The account running the services
    2. The cross-account able to access the shared services
    3. The cross-account with the Amazon Simple Storage Service (Amazon S3) bucket holding a downloaded copy of the code artifact
    4. All accounts involved
  12. What can you not do to an Amazon Relational Database Service (Amazon RDS) instance with AWS Elastic Beanstalk?

    1. Create a database connection.
    2. Create a supported Oracle edition.
    3. Retain a database instance despite the deletion of the environment’s database.
    4. Create a snapshot of the existing database (before deletion).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset