Managing cloud resources manually can get repetitive fast, especially if you regularly start or stop EC2 instances to save costs. In this post, I’ll show you how to automate EC2 instance management using Go and the AWS SDK for Go v2.
By the end, you’ll have a working Go script that can automatically start or stop EC2 instances based on their tags
Why Go?
Go (Golang) is one of the best languages for automation because it’s:
AWS even uses Go internally in tools like the AWS CLI v2 and Terraform, so it’s perfect for cloud automation scripts.
Project Overview
We’ll build a simple Go program that:
-
Lists EC2 instances with a specific tag (AutoManage=true)
-
Starts or stops those instances based on your chosen action
-
Logs the results in the console
You can later extend this to run on AWS Lambda or trigger it automatically using EventBridge.
Prerequisites
Before you begin, make sure you have:
-Go installed (v1.20 or newer)
-AWS CLI configured with valid credentials
-IAM permissions for ec2:DescribeInstances, ec2:StartInstances, and ec2:StopInstances
This project is a great way to get started with AWS automation using Go.
It’s small, simple, and practical and from here, you can easily build more advanced automation tools for cloud management, cost optimization, or infrastructure orchestration.
If you enjoyed this post, consider trying the next step: deploying this as a Lambda function that runs daily to automatically shut down unused EC2 instances and cut your AWS bill.
Why I Like This Approach
It’s simple, but powerful. I get a clear sense of how Go interacts with AWS APIs and how it enforces good practices. It also helps me build more efficient infrastructure tools that can scale later on.
I’ll probably keep using Python for quick prototypes and serverless functions, but Go feels great for structured, production-grade automation tools.
Check Out the Full Project
You can find the complete implementation here
https://github.com/Copubah/aws-ec2-instance-manager
It includes CLI support, Lambda deployment scripts, and detailed configuration examples. I’ll be adding more features over time as I continue testing Go for AWS automation