A secure, serverless hospital backend system built with AWS SAM, allowing patients to access their medical records and administrators to view aggregate health metrics.
- Patient Self-Service: Patients can securely retrivew their own medical records
- Admin Dashboard: Web-based interface for viewing aggregate health metrics
- Secure Authentication: AWS Cognito-based JWT authentication
- Role-Based Access: Separate permissions for patients and administrators
- Serverless Architecture: Scalable, pay-per-use infrastructure
- Infrastructure as Code: Complete SAM template for reproducible deployments
- AWS IAM account with administrative access
- AWS CLI v2.x configured locally with credentials
- AWS SAM CLI v1.100+
- Python 3.11+
- Git
git clone https://github.com/iamtripathi25/hospital-backend.git
cd hospital-backend# Create virtual environment
python -m venv .venv
# Activate virtual environment
.venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtsam buildpytest# First deployment (guided)
sam deploy --guided
# Follow the prompts:
# - Stack Name: hospital-backend
# - AWS Region: us-east-1 (or your preferred region)
# - Parameter Environment: dev
# - Confirm changes before deploy: Y
# - Allow SAM CLI IAM role creation: Y
# - Save arguments to configuration file: Y
# Subsequent deployments
sam deploy
# Recommended
sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --stack-name $STACK_NAMEaws cloudformation describe-stacks --stack-name $STACK_NAME --output json > exports.jsonpython3 .\scripts\generate_config.py <stack-name>aws s3 sync ./dashboard/ s3://$DASHBOARD_BUCKET --delete
# Get s3_bucket_name from exports.json# Dry run first (recommended)
python3 -m scripts.seed_cognito_users \
--user-pool-id $USER_POOL_ID \
--count 100 \
--output cognito_users.csv
--dry-run
python3 -m scripts.seed_cognito_users \
--user-pool-id $USER_POOL_ID \
--count 100 \
--output cognito_users.csv
# Get User_POOL_ID from exports.jsonpython3 -m scripts.seed_dynamodb_records \
--input cognito_users.csv \
--table-name $PATIENT_RECORD_TABLE \
# Dry run first (recommended)
python3 -m scripts.seed_dynamodb_records \
--input cognito_users.csv \
--table-name $PATIENT_RECORD_TABLE \
--dry-run
# Get PATIENT_RECORD_TABLE from export.jsonpython3 -m scripts.make_admin_user \
--user-pool-id $USER_POOL_ID \
--name <admin_name> \
--email <admin_email_id> \
--password <admin_password># Call this url in browser or postman to check health of backend
$API_ENDPOINT/health
# Call this in browser to get id_token after successful login. In case of Admin application redirects to admin dashboard
$COGNITO_HOSTED_URL
# Call this url in postman with Authorization as header with value id_token from above
$API_ENDPOINT/patient/me #
# To get json data call following url in postman with above id_token
$API_ENDPOINT/admin/metrics/overview
$API_ENDPOINT/admin/metrics/medications
$API_ENDPOINT/admin/metrics/diseases
# Get API_ENDPOINT, COGNITO_HOSTED_URL from exports.json
# Delete all S3 objects first
aws s3 rm s3://$DASHBOARD_BUCKET --recursive
# Delete the CloudFormation stack
sam delete
# Or use AWS CLI
aws cloudformation delete-stack --stack-name $STACK_NAME
# Verify deletion
aws cloudformation describe-stacks --stack-name $STACK_NAME