An EC2 instance runs the application or web server. A load balancer provides a stable entry point and distributes requests across healthy targets. Separating the public entry point from private application instances can reduce direct exposure and make scaling or replacement easier.
Before You Begin
- An AWS VPC with public and private subnet design.
- An EC2 application instance or launch template.
- A domain name and certificate if serving HTTPS.
Recommended Approach
1. Choose the load balancer type
Use an Application Load Balancer for HTTP/HTTPS routing, host/path rules, and web application traffic. Use a Network Load Balancer for supported Layer 4 use cases requiring TCP/UDP/TLS behavior or static IP characteristics.
2. Place resources in suitable subnets
Deploy the load balancer across at least two Availability Zones for resilience. Place application instances in private subnets when they do not need direct inbound internet access.
3. Create a target group
Choose the target type and protocol/port used by the application. Configure a health check endpoint that reports whether the application can serve traffic, not merely whether the operating system is running.
4. Configure security groups
Allow inbound client traffic to the load balancer. Allow the application port on EC2 only from the load balancer security group. Keep SSH or administration access on a separate restricted path.
5. Configure TLS and routing
Attach an ACM certificate to the HTTPS listener, add redirect behavior from HTTP where appropriate, and configure host/path rules. Ensure the application understands forwarded protocol and client-address headers from trusted proxies.
6. Deploy and observe
Register targets, wait for healthy status, and test the application through the load balancer DNS name. Monitor target health, latency, 4xx/5xx responses, capacity, and scaling events.
Operational Considerations
Cloud storage and compute designs should account for security, availability, lifecycle, and cost together. Decide where data resides, how long it is retained, which identities can reach it, and how the service behaves during a regional or credential failure. Separate production and test resources when their access needs differ. Review data-transfer charges, request volume, version retention, and abandoned multipart uploads as part of routine operations.
How to Verify the Result
Test the workflow using the same role and network path that the deployed application will use. Verify successful access to the intended object or service, denial for an unrelated object, and behavior after a temporary credential expires. Check logs for the principal and operation, and confirm that lifecycle, versioning, and backup settings match the data-retention policy.
Example Configuration
Illustrative example — adapt values to your environment
# Example security-group intent
# ALB security group: inbound TCP 443 from approved client ranges
# EC2 security group: inbound TCP 8000 from the ALB security group only
Common Mistakes to Avoid
- Do not expose the application port to 0.0.0.0/0 if only the load balancer should reach it.
- Health checks should not depend on a user session or return success when critical dependencies are unavailable.
- Forwarded headers must be trusted only when received from the known proxy/load balancer path.
Make one change at a time, test it from the perspective of the actual user or application, and record the reason for the change. Keep a rollback path for network, identity, and production configuration changes.
Final Checklist
- The configuration matches the intended environment and service version.
- Access is limited to the required identities, resources, ports, and operations.
- The expected workflow has been tested, including a negative test for unauthorized access.
- Secrets and temporary credentials are protected and excluded from logs and source control.
- The configuration owner, purpose, and review or expiration date are documented.