Sign inSign up

hiremostafa/aws-ecs-helloworld

By hiremostafa

•Updated 4 days ago

Production-ready Hello World for Amazon ECS: FastAPI, health checks

Image
API management
0

77

hiremostafa/aws-ecs-helloworld repository overview

⁠aws-ecs-helloworld

A production-ready Hello World container for Amazon ECS. Deploy it to verify your cluster, service, load balancer and health checks end to end, before shipping your real application.

aws-ecs-helloworld home page

⁠Features

  • FastAPI + uvicorn with a clean, plain HTML home page (no JavaScript, strict CSP)
  • Health checks built in: /health (liveness) and /ready (readiness)
  • Curl-free container health check: python -m app.healthcheck
  • ECS-aware: detects Amazon ECS and exposes live task metadata (cluster, service, task, AZ, private IP, image) at /api/info
  • CloudWatch-friendly JSON logs with request IDs; health check requests are not logged by default
  • Secure by default: runs as a non-root user (UID 10001), security headers, works with a read-only root filesystem
  • Graceful shutdown on SIGTERM, so ECS deployments drain cleanly

⁠Quick start

docker run --rm -p 8080:8080 hiremostafa/aws-ecs-helloworld:latest

Open http://localhost:8080⁠

⁠Endpoints

PathDescription
/HTML home page
/healthLiveness check. Use for ALB and container health
/readyReadiness check. Returns 503 during startup/shutdown
/api/infoApp, runtime and ECS task metadata as JSON
/docsOpenAPI documentation

⁠Deploy on Amazon ECS

  • Image: hiremostafa/aws-ecs-helloworld:1.0.0
  • Container port: 8080
  • ALB target group: protocol HTTP, port 8080, target type ip, health check path /health
  • Container health check (task definition):
"healthCheck": {
  "command": ["CMD", "python", "-m", "app.healthcheck"],
  "interval": 30,
  "timeout": 5,
  "retries": 3,
  "startPeriod": 10
}

The container listens on 8080 because it runs as a non-root user.

⁠Configuration

VariableDefaultDescription
PORT8080HTTP port
MESSAGEYour Amazon ECS app is liveHeadline on the home page
APP_NAMEaws-ecs-helloworldApplication name
LOG_LEVELinfodebug, info, warning, error
LOG_HEALTH_CHECKSfalseLog /health and /ready requests
ECS_METADATA_TIMEOUT2ECS metadata request timeout (s)
GRACEFUL_SHUTDOWN_TIMEOUT20Seconds to finish in-flight requests

⁠Tags

TagPlatform
latestlinux/amd64
1.0.0linux/amd64

⁠Source

GitHub: https://github.com/code4mk/aws-ecs-helloworld⁠

⁠Author

Crafted with ♥ by code4mk⁠. Questions, ideas or work inquiries: [email protected]⁠

Sample application. Not affiliated with or endorsed by Amazon Web Services.

Tag summary

Content type

Image

Digest

sha256:065ff2c74…

Size

52.9 MB

Last updated

4 days ago

docker pull hiremostafa/aws-ecs-helloworld