An AWS EC2 production deployment for a health API is more than launching an instance and opening port 443. The instance sits in a network, reads credentials from the metadata service, needs patching, and must leave an audit trail, and each of those choices affects how well protected health information stays protected.
CTOs and engineering leads running a health API on EC2 will find where the instances should sit, why IMDSv2 should be required, how to patch and reach instances without SSH, what to log, and a hardening checklist to work through before go-live.
What does an AWS EC2 production deployment for a health API involve?
An AWS EC2 production deployment for a health API involves placing the instances in private subnets behind a load balancer, requiring IMDSv2, giving each instance a narrow IAM role, patching from a repeatable image pipeline, reaching instances through Session Manager instead of SSH, and logging activity so access to health data can be reviewed.
Moving a health API onto EC2?
We set up the network, images, access and logging for production health workloads.
EC2 still makes sense for many health APIs: long-running services, workloads with specific runtime or licensing needs, and teams moving from on-premises servers. The work is in making the instance boring, predictable and replaceable.
Where should the instances sit in the network?
The instances should sit in private subnets with no public IP addresses, behind an Application Load Balancer in public subnets that terminates TLS and forwards only the API port. Nothing on the internet should reach an instance directly.
- Load balancer: in public subnets, with security group rules allowing HTTPS from the internet or from your API gateway only.
- API instances: in private subnets across at least two Availability Zones, accepting traffic only from the load balancer's security group.
- Database: in its own private subnets, accepting connections only from the API instances' security group.
- Outbound traffic: through VPC endpoints for AWS services where possible, and a NAT gateway only for what truly needs the internet.
Referencing security groups instead of IP ranges keeps the rules correct as instances are replaced. It also makes the allowed paths readable in a review.
Why require IMDSv2?
You should require IMDSv2 because the instance metadata service hands out the temporary credentials of the instance role, and the session-based version makes those credentials harder to steal through a vulnerable application.
AWS documentation says IMDSv2 uses session-oriented requests: a PUT request returns a token, valid for up to six hours, that must accompany later GET requests. When token use is set to required, requests without a valid token get a 401 error, PUT requests carrying an X-Forwarded-For header are rejected, and the PUT response has a default hop limit of 1.
In practice, a server-side request forgery bug that can only make simple GET requests cannot fetch the token, and a request relayed through a proxy that adds X-Forwarded-For is refused. Set the metadata options to require tokens in the launch template, and keep the hop limit at 1 unless a container setup on the instance needs more.
Check that your AWS SDKs and agents are recent enough to use IMDSv2 before switching it on, then watch for failed metadata calls after the change.
How should admins reach the instances?
Admins should reach instances through Session Manager, with access controlled by IAM and every session logged, rather than through SSH keys and a bastion host.
AWS documentation says Session Manager, a capability of AWS Systems Manager, provides node management without the need to open inbound ports, maintain bastion hosts or manage SSH keys, with access granted through IAM policies.
Session Manager needs the SSM Agent on the instance and a path to the Systems Manager endpoints, either through VPC endpoints or outbound access. Send session logs to CloudWatch Logs or S3 so each interactive session can be reviewed later.
Most days, nobody should need a shell on a production instance at all. If people log in often, that usually points to missing automation or missing logs.
How do you keep instances patched?
You keep instances patched by building a new machine image on a schedule with current updates, testing it, and replacing running instances with it, rather than patching long-lived servers by hand.
- Image pipeline: start from a supported base image, apply updates and your hardening, then run tests before publishing.
- Launch template: points at the latest approved image, with IMDSv2 required and the instance role attached.
- Rolling replacement: an Auto Scaling group replaces instances gradually so the API stays available.
- Emergency patches: a documented path to patch in place with Systems Manager when a fix cannot wait for the next image.
Replaceable instances also make recovery simpler. If an instance looks compromised, isolate it for investigation and let the group start a clean one.
Keep a record of which image each instance runs and when it was built. During a security review or after a vulnerability announcement, that record shows at once which servers are exposed.
Secrets, roles and encryption
Secrets, roles and encryption decide what an attacker gets if they reach an instance. The aim is that the instance holds nothing it does not need.
- One IAM role per service, granting only the actions and resources that service uses.
- No access keys on disk: the application reads credentials from the instance role.
- Database passwords and API keys in Secrets Manager or Parameter Store, read at start-up.
- EBS volumes and snapshots encrypted with KMS keys, with key policies reviewed.
- TLS from the load balancer to the instances where your threat model or contracts require it.
What should be logged for a health API?
A health API should log who did what to which data, at the application level and the infrastructure level, without writing protected health information into the log lines themselves.
The HIPAA Security Rule's audit controls standard, 45 CFR 164.312(b), requires hardware, software or procedural mechanisms that record and examine activity in information systems that contain or use electronic protected health information.
- Application audit events: user or client, action, record identifier, result and time.
- AWS CloudTrail: API calls against the account, including changes to roles, security groups and keys.
- Load balancer access logs and VPC Flow Logs: who connected to what.
- Session Manager logs: every interactive session on an instance.
Keep log retention and access rules written down, and restrict who can read the logs. Audit logs often reveal as much about patients as the database does.
Add health checks and alarms alongside the logs. The load balancer should check an endpoint that confirms the API can reach its database, and alarms should cover unhealthy targets, error rates, CPU and disk, and failed metadata or Session Manager calls after any configuration change.
The EC2 hardening checklist
The hardening checklist below collects the settings to confirm before a health API on EC2 takes production traffic.
| Area | Setting | Why it matters |
|---|---|---|
| Network | Instances in private subnets, no public IP | Nothing on the internet reaches an instance directly |
| Security groups | API accepts traffic only from the load balancer group | Limits the paths into the instance |
| Metadata | IMDSv2 required, hop limit 1 | Protects instance role credentials |
| Access | Session Manager, no inbound SSH | Access through IAM, sessions logged |
| Identity | One narrow IAM role per service | Limits what a compromised instance can do |
| Patching | Scheduled image builds and rolling replacement | Updates applied in a tested, repeatable way |
| Storage | Encrypted EBS volumes and snapshots | Protects data at rest |
| Logging | CloudTrail, flow logs, access logs, app audit events | Activity can be reviewed after the fact |
| Secrets | Secrets Manager or Parameter Store | No credentials in code, images or disk |
How do teams deploy step by step?
Teams deploy a health API on EC2 in an order that builds the protections first and the application last, so the first production instance is already hardened.
- Step 1: define the VPC, subnets, route tables and endpoints as infrastructure code.
- Step 2: create security groups and IAM roles, with reviews of both.
- Step 3: build the hardened image and the launch template with IMDSv2 required.
- Step 4: set up logging, Session Manager and alarms before any traffic arrives.
- Step 5: deploy the application through the Auto Scaling group behind the load balancer.
- Step 6: run a security review and a failover test, then open traffic.
What are the common mistakes with AWS EC2 production deployment?
The common mistakes with AWS EC2 production deployment are shortcuts taken during setup that stay in place once the API is live.
- Leaving IMDSv1 enabled because one old script still uses it.
- Opening SSH to the internet for a quick fix and never closing it.
- Sharing one broad IAM role across every service.
- Patching by hand, so no two instances are quite the same.
- Logging full request bodies that contain patient data.
What does EC2 hardening mean for the build plan?
EC2 hardening adds infrastructure code, an image pipeline, logging and access setup to the plan before the first release. Each needs an owner after launch as well.
- Confirm which AWS services are covered under your Business Associate Addendum with AWS before using them for PHI.
- Write infrastructure as code so the hardened setup can be reviewed and recreated.
- Schedule image rebuilds and assign who approves each new image.
- Agree log retention, access and review with your compliance lead.
How Agnotic helps with EC2 production deployment
Agnotic Technologies builds and hardens AWS environments for health APIs: VPC design, launch templates with IMDSv2 required, image pipelines, Session Manager access, audit logging and the review before go-live. We can also take over an existing EC2 setup and close the gaps one change at a time.
Harden the API before it carries patient data
Private subnets, IMDSv2, clean images and logs you can review.
Related reading on Agnotic
AWS, DevOps and HIPAA engineering.


