AWS Elastic Load Balancing (ELB) offers the ability to load balance traffic across AWS and on-premises resources using the same load balancer. Using a runbook, Octopus makes it easy to provide an automated method for modifying an AWS Elastic load balancer. This is particularly useful if you are deploying using the blue-green deployment pattern, as you can change the load balancer automatically to direct traffic to a different set of servers when you switch to your new active environment.
In this example, we'll swap out servers that are being used in an AWS Elastic load-balancer by modifying the configured listener to forward traffic to a new target group.
Create the runbook
- To create a runbook, navigate to Project ➜ Operations ➜ Runbooks ➜ Add Runbook.
- Give the runbook a name and click SAVE.
- Click DEFINE YOUR RUNBOOK PROCESS, then click ADD STEP.
- Add a Run an AWS CLI script step, and give the step a name.
- Choose the Execution Location on which to run this step.
- Choose whether to use the bundled AWS Tools, or the ones pre-installed on the worker.
- Choose the AWS Account to use.
- In the Amazon Web Services Account section select the variable that references the AWS Account or choose to execute using a service role assigned to the EC2 instance. If you don't have an AWS Account Variable yet, check our documentation on how to create one.
The supplied account can optionally be used to assume a different AWS service role. This can be used to run the AWS commands with a role that limits the services that can be affected.
If you select Yes to Execute using the AWS service role for an EC2 instance, you do not need an AWS account or account variable. Instead the AWS service role for the EC2 instance executing the deployment will be used. See the AWS documentation for more information on service roles.
- In the Inline source code section, add the following code as a PowerShell script:
$listenerArn = $OctopusParameters["Project.AWS.ALB.ListenerArn"] $targetGroup = $OctopusParameters["Project.AWS.ALB.TargetArn"] Write-Host "Modifying AWS ELB listener: $listenerArn to forward to targetGroup: $targetGroup" aws elbv2 modify-listener --listener-arn $listenerArn --default-actions Type=forward,TargetGroupArn=$targetGroup
The script will modify the ELB listener specified in the
Project.AWS.ALB.ListenerArn variable to forward traffic to the target group specified in the
Configure any other settings for the step and click Save, and in just a few steps, we've created a runbook to automate the modification of an AWS Elastic load balancer to change its target group.
We have a Pattern - Blue-Green Space on our Samples instance of Octopus. You can sign in as
Guest to take a look at this runbook example named
Change Production Group in the
Random Quotes Java project.
- Blue/Green deployment patterns with Octopus.
- Ask Octopus Episode: Blue/Green Deployments
- Blue/Green deployment knowledge base articles.
- Deployment patterns blog posts.
Need support? We're here to help.