26.8 ECS Anywhere: Running ECS Tasks on On-Premises Infrastructure
Alright, let’s talk about ECS Anywhere. You read that right. You can now run ECS tasks on your own hardware. It feels a bit like AWS showing up at your datacenter with a box of tools, saying “move over, I got this,” and you’re just hoping they don’t break the coffee machine. The promise is intoxicating: a single control plane for your containers, whether they’re in the cloud or in your own server closet. The reality is, as always, a bit more interesting.
The core magic trick here is the external instance: a physical server, a VM in your VMware cluster, or even that old Dell PowerEdge humming under Bob’s desk that you’ve been meaning to decommission. To ECS, it’s just another compute resource. The secret sauce is the amazon-ecs-agent that you install on these machines. It doesn’t matter if the machine is on AWS or not; the agent knows how to phone home to the ECS control plane and say, “I’m here, assign me work.”
Why You’d Actually Do This
Before we get into the how, let’s be brutally honest about the why. You don’t do this for fun. You do it because you have to.
- The “Lift-and-Shift-and-Hope”: You’re mid-migration. Some ancient, cantankerous application has a dependency on a local mainframe or a network fileshare that makes moving it to the cloud a multi-year project. ECS Anywhere lets you containerize it now and manage it with your modern tooling, while it still lives on-prem.
- Data Gravity: Your on-prem dataset is petabytes large. Moving it is cost-prohibitive or technically unfeasible. So you bring the compute to the data, all while managing it from the AWS console.
- Low-Latency Edge Requirements: Maybe you need a node in a factory or a retail store for real-time processing, and shipping data to
us-east-1just isn’t an option.
If none of these sound like you, you can probably skip this chapter. For everyone else, let’s get our hands dirty.
The Guts: Systems Manager and IAM
ECS Anywhere leans heavily on AWS Systems Manager (SSM). This isn’t a suggestion; it’s a hard requirement. The on-prem agent doesn’t open a million inbound ports; it establishes an outbound, secure WebSocket connection to the SSM service. This is genius because it means you don’t have to reconfigure your corporate firewall to allow AWS into your network. The agent calls out.
This means your on-prem machine must have:
- Outbound internet access (or a proxy configuration it can use).
- The SSM agent installed and configured.
- An IAM identity it can assume to talk to both SSM and ECS.
Ah, IAM. The bane and savior of everything. The machine needs credentials. On an EC2 instance, this is handled by an Instance Profile. On-prem, you have two choices, and one of them is truly awful.
Option 1: IAM Anywhere (The Right Way) This uses X.509 certificates issued by IAM Roles Anywhere to grant your machine temporary IAM credentials. It’s the secure, intended method.
First, create a Trust Anchor pointing to your Certificate Authority (you are running your own PKI, right?).
# Create a trust anchor. You'll need your CA certificate PEM.
aws rolesanywhere create-trust-anchor \
--name "My-OnPrem-CA" \
--source sourceData={x509CertificateData="$(cat my-ca-cert.pem)"},sourceType=CERTIFICATE_BUNDLE
Then, create a profile that defines which roles the machine can assume.
# Create a profile that allows the machine to assume the SSM-enabled role
aws rolesanywhere create-profile \
--name "ECSAnywhereProfile" \
--roleArns "arn:aws:iam::123456789012:role/ECSAnywhereSSMRole" \
--duration-seconds 3600
Option 2: Static IAM Keys (The “Please Don’t” Way) You can configure the agent with a regular IAM user’s access key and secret key. This is a terrifyingly bad idea for anything resembling a production environment. Those keys are static, long-lived, and if that machine is compromised, so is your AWS account. I’m only showing you this so you can recognize it and run the other way.
// /etc/ecs/ecs.config (THIS IS A BAD IDEA)
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Installing and Registering the Agent
Once your machine’s identity is sorted, installing the agent is straightforward. AWS provides a script that does the heavy lifting. The critical part is the --cluster flag. This registers the machine directly into your specified ECS cluster.
# Download the install script
curl -o "ecs-anywhere-install.sh" "https://amazon-ecs-agent-packages-preview.s3.us-east-1.amazonaws.com/ecs-anywhere-install.sh"
# Make it executable and run it, specifying your cluster name
sudo bash ./ecs-anywhere-install.sh --cluster My-OnPrem-Cluster --region us-east-1
After a reboot, this machine will appear in your ECS cluster under the “ECS Instances” tab for that cluster, looking for all the world like an EC2 instance. It’s a beautiful trick.
The Rough Edges and Pitfalls
This is the part they don’t put in the marketing material. Pay attention.
- Networking is Your Problem: ECS can’t create an on-prem VPC for you. Your tasks will run on your corporate network. If you need service discovery, you’re configuring Route53 Resolver endpoints or something else entirely. The
awsvpcnetwork mode gives the task its own elastic network interface (ENI), but that ENI is on your network, not AWS’s. This has huge implications for security groups (you can’t use them) and routing. - No Fargate On-Prem: Obvious, but worth stating. If you’re using ECS Anywhere, you’re in the EC2 launch type world. You are responsible for the underlying OS, patching the Docker daemon, and provisioning enough CPU/RAM on your instances.
- The “Just Use It” Illusion: Your task definitions might need serious rework. Any reference to an S3 bucket or an RDS database in a task definition will now egress from your datacenter, not from an AWS AZ. This can introduce latency and egress costs you didn’t account for.
- The Hybrid Tax: You pay for the ECS tasks you run on-premises. Yes, you read that correctly. You’re paying an ECS price per vCPU per hour for the privilege of using your own hardware. Always, always factor this into your TCO calculations. It’s not free.
So, is it worth it? For the specific, painful, “we have no other choice” use cases, absolutely. It’s a technological bridge over a chasm you need to cross. Just know you’re paying a toll, and you’re still the one responsible for maintaining the bridge’s foundations on your side.