Aws asg updater - Update AMIs within AWS Auto Scaling groups automatically.

AWS Auto Scaling Groups Updater

AWS Auto Scaling group is a great way of managing Amazon EC2 instances. AWS Auto Scaling group watches the corresponding instances' health and launches new instances whenever needed: to replace instances that became unhealthy or to scale the group. Furthermore, with an AWS Elastic Load Balancer attached, AWS Auto Scaling Group also takes ELB health checks into account, making it possible to replace the instances based on service-level signals.

However, when it comes to updating services, AWS Auto Scaling Groups become tricky. The recommended way is to create the group using a launch template containing the information required to launch new instances, such as instance type and Amazon Machine Image (AMI). Hence, to update the service, one needs to create a new AMI, update the corresponding launch template, and execute an instance refresh.

This is where AWS Auto Scaling Groups Updater comes in handy. It uses AWS EC2 API and AWS EC2 Auto Scaling API to perform the following operations automatically:

  • register a new AMI from a running instance;
  • create a new version of the Auto Scaling group's launch template with this new AMI attached;
  • execute the instance refresh for the Auto Scaling group;
  • cancel the instance refresh if it's unable to finish within the desired time;
  • handle all the errors that might happen along the way.

The tool uses the default AWS credentials config. Run aws configure or set up the environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION before running the tool.

Examples of Use

The program options to create a new AMI from the instance i-0d8767eed40de1728, name it service_ami, update the Auto Scaling group my_service_group with it:

--group my_service_group --instance i-0d8767eed40de1728 --ami service_ami

The output looks like that then:

2022/01/02 00:23:02 creating image "service_ami" from the instance i-0d8767eed40de1728
2022/01/02 00:24:03 creating image service_ami (ami-070a1f039b2945569): pending
2022/01/02 00:25:04 creating image service_ami (ami-070a1f039b2945569): pending
2022/01/02 00:26:04 creating image service_ami (ami-070a1f039b2945569): available
2022/01/02 00:26:04 created image "ami-070a1f039b2945569" from instance i-0d8767eed40de1728
2022/01/02 00:26:05 launch template id: lt-0b049e246796cc5cd
2022/01/02 00:26:05 latest launch template version id: 19
2022/01/02 00:26:06 created new version 20 for the launch template lt-0b049e246796cc5cd
2022/01/02 00:26:06 set the version 20 for the launch template lt-0b049e246796cc5cd as default
2022/01/02 00:26:06 will run instance refresh for the auto scale group "my_service_group"
2022/01/02 00:27:07 updating group my_service_group, update id 1608d67f-931c-4e83-8aff-56721c95e86a: InProgress, 0% completion
2022/01/02 00:28:08 updating group my_service_group, update id 1608d67f-931c-4e83-8aff-56721c95e86a: InProgress, 0% completion
2022/01/02 00:29:09 updating group my_service_group, update id 1608d67f-931c-4e83-8aff-56721c95e86a: InProgress, 0% completion
2022/01/02 00:30:10 updating group my_service_group, update id 1608d67f-931c-4e83-8aff-56721c95e86a: InProgress, 0% completion
2022/01/02 00:31:11 updating group my_service_group, update id 1608d67f-931c-4e83-8aff-56721c95e86a: Successful, 100% completion
2022/01/02 00:31:11 instance refresh for the auto scale group "my_service_group" completed successfully

If you already have an AMI ID, just skip the --ami and --instance options, and use the --image option, e.g.:

--group my_service_group --image ami-070a1f039b2945569

This will update the launch template and run the instance refresh:

2022/01/02 11:36:09 launch template id: lt-0b049e246796cc5cd
2022/01/02 11:36:10 latest launch template version id: 20
2022/01/02 11:36:10 created new version 21 for the launch template lt-0b049e246796cc5cd
2022/01/02 11:36:11 set the version 21 for the launch template lt-0b049e246796cc5cd as default
2022/01/02 11:36:11 will run instance refresh for the auto scale group "appscience_bot"
2022/01/02 11:37:12 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: InProgress, 0% completion
2022/01/02 11:38:13 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: InProgress, 0% completion
2022/01/02 11:39:14 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: InProgress, 0% completion
2022/01/02 11:40:15 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: InProgress, 0% completion
2022/01/02 11:41:15 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: InProgress, 0% completion
2022/01/02 11:42:16 updating group appscience_bot, update id 197f64f8-9b1e-4a9c-b4ad-85b7882ca170: Successful, 100% completion
2022/01/02 11:42:16 instance refresh for the auto scale group "appscience_bot" completed successfully

Program Arguments

  • group: the name of the Auto Scaling group to update; required.
  • image: AMI id to update the group; optional: do not use if you want to create an AMI from a running instance.
  • instance: AWS EC2 instance ID to create the AMI from; optional: do not use if you already have an AMI ID.
  • ami: the name of the AMI to be created from the selected instance; optional: use together with the --instance argument only.
  • update-timeout: the time limit to complete the instance refresh; optional: the default is 30 minutes. Use the Golang duration strings to override, see https://pkg.go.dev/time#ParseDuration.
  • update-tick: the time between status updates in the log file; optional: the default is one minute. Making this parameter lower might speed up the overall execution. Use the Golang duration strings to override, see https://pkg.go.dev/time#ParseDuration.

Installation

Assuming you already have Golang installed on the machine, simply run:

go install github.com/ashagraev/aws_asg_updater@latest

The tool will then appear in your golang binary folder (e.g., ~/go/bin/aws_asg_updater). If you don't have Golang yet, consider installing it using the official guide https://go.dev/doc/install.

Alternatively, you can download the pre-built binaries from the latest release: https://github.com/ashagraev/aws_asg_updater/releases/latest.

Similar Resources

kubetnl tunnels TCP connections from within a Kubernetes cluster to a cluster-external endpoint, e.g. to your local machine. (the perfect complement to kubectl port-forward)

kubetnl kubetnl (kube tunnel) is a command line utility to tunnel TCP connections from within a Kubernetes to a cluster-external endpoint, e.g. to you

Dec 16, 2022

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

Vault Config Operator This operator helps set up Vault Configurations. The main intent is to do so such that subsequently pods can consume the secrets

Sep 30, 2022

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

Vault Config Operator This operator helps set up Vault Configurations. The main intent is to do so such that subsequently pods can consume the secrets

Dec 19, 2022

Parallel processing through go routines, copy and delete thousands of key within some minutes

redis-dumper CLI Parallel processing through go routines, copy and delete thousands of key within some minutes copy data by key pattern from one redis

Dec 26, 2021

Enable your Go applications to self update

go-selfupdate Enable your Golang applications to self update. Inspired by Chrome based on Heroku's hk. Features Tested on Mac, Linux, Arm, and Windows

Jan 3, 2023

Triggers an update to a Koyeb app service to re-deploy the latest docker image

Triggers an update to a Koyeb app service to re-deploy the latest docker image

May 5, 2021

ArgoCD is widely used for enabling CD GitOps. ArgoCD internally builds manifest from source data in Git repository, and auto-sync it with target clusters.

ArgoCD is widely used for enabling CD GitOps. ArgoCD internally builds manifest from source data in Git repository, and auto-sync it with target clusters.

ArgoCD Interlace ArgoCD is widely used for enabling CD GitOps. ArgoCD internally builds manifest from source data in Git repository, and auto-sync it

Dec 14, 2022

Cloud Service Auto Cert

CSAC (Cloud Service Auto Cert) Features Tencent Cloud Auto DNS Certification Auto Upload Cert File Auto Update CDN HTTPS Cert Auto Update CLB HTTPS Ce

May 6, 2022

App for VMware Workstartion to auto start VM's on windows reboot

VMware Workstation AutoStart This is an auto start app for VMware Workstation to auto start VM's on windows reboot with VMware Workstation installed.

Dec 15, 2021
Rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster

k8s-r8 rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster. It was developed to make upgrading AMIs as a one command experi

Mar 27, 2022
Automatic-Update-Launcher - A general purpose updater for updating program binaries when update folder exists
Automatic-Update-Launcher - A general purpose updater for updating program binaries when update folder exists

Automatic Update Launcher A general purpose updater for updating (web) applicati

Jun 27, 2022
Service-scaling - Microservice scaling with example

Scaling examples This is the repo for my (Hungarian) Twitch streams where I spea

Jan 8, 2022
This action prints "true" if image is required to update based on the base image update.

container-image-updater This action prints "true" if image is required to update based on the base image update. Inputs Name Type Description base-ima

Apr 15, 2022
Git-auto-push - Auto commit and push to github repositories

Auto commit and push to github repositories. How to use git clone https://github

Dec 19, 2022
A Kubernetes Operator used for pre-scaling applications in anticipation of load

Pre-Scaling Kubernetes Operator Built out of necessity, the Operator helps pre-scale applications in anticipation of load. At its core, it manages a c

Oct 14, 2021
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes. This project is inspired by agones. Introduction Genera

Nov 25, 2022
GoBinClassify - A library that makes it easy to classify into groups

GoBinClassify GoBinClassify is a library that makes it easy to classify into gro

Feb 12, 2022
⚙️ Operating Account Operators (OAO) is a Golang tool to interact with the LDAP protocol to manage account groups, roles, ACLs/ACEs, etc...
⚙️ Operating Account Operators (OAO) is a Golang tool to interact with the LDAP protocol to manage account groups, roles, ACLs/ACEs, etc...

⚙️ OAO (Operating Account Operators) ⚙️ Operating Account Operators (OAO) is a Golang tool to interact with the LDAP protocol to manage account groups

May 11, 2023
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds

Website • Quickstart • Documentation • Blog • Twitter • Slack vcluster - Virtual Clusters For Kubernetes Lightweight & Low-Overhead - Based on k3s, bu

Jan 4, 2023