From 033a144584fa3efd3a1f411c42b73f4f2ba6ae51 Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Sun, 26 Feb 2023 14:42:22 -0500 Subject: [PATCH 1/2] Add health check to users service --- infrastructure/cdk/src/providers/users.ts | 8 +++++++- services/users/src/index.ts | 2 ++ services/users/src/routes/health.ts | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 services/users/src/routes/health.ts diff --git a/infrastructure/cdk/src/providers/users.ts b/infrastructure/cdk/src/providers/users.ts index 0938b232e..3505129d7 100644 --- a/infrastructure/cdk/src/providers/users.ts +++ b/infrastructure/cdk/src/providers/users.ts @@ -22,7 +22,8 @@ export class UsersStack extends cdk.Stack { const { certificate, cluster, hostedZone } = props /** Create a load-balanced service for the users express API */ - new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), { + const usersService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), { + assignPublicIp: true, certificate, cluster, domainName: `${subdomains.users}.${rootDomain}`, // e.g. users.casimir.co or users.dev.casimir.co @@ -36,5 +37,10 @@ export class UsersStack extends cdk.Stack { } } }) + + /** Override the default health check path */ + usersService.targetGroup.configureHealthCheck({ + path: '/health' + }) } } \ No newline at end of file diff --git a/services/users/src/index.ts b/services/users/src/index.ts index d2dd8212f..90912376a 100644 --- a/services/users/src/index.ts +++ b/services/users/src/index.ts @@ -3,6 +3,7 @@ import cors from 'cors' import login from './routes/login' import auth from './routes/auth' import users from './routes/users' +import health from './routes/health' const port = process.env.PUBLIC_AUTH_PORT || 4000 @@ -13,6 +14,7 @@ app.use(cors()) app.use('/login', login) app.use('/auth', auth) app.use('/users', users) +app.use('/health', health) app.listen(port) console.log(`Auth server listening on port ${port}`) \ No newline at end of file diff --git a/services/users/src/routes/health.ts b/services/users/src/routes/health.ts new file mode 100644 index 000000000..96de84e2d --- /dev/null +++ b/services/users/src/routes/health.ts @@ -0,0 +1,9 @@ +import express from 'express' + +const router = express.Router() + +router.get('/', (_req, res) => { + res.status(200).send('OK') +}) + +export default router \ No newline at end of file From 807ec26486342edf36bf519d977ebcb205149df4 Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Sun, 26 Feb 2023 16:25:08 -0500 Subject: [PATCH 2/2] Set nat gateway count to zero --- infrastructure/cdk/src/providers/network.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/infrastructure/cdk/src/providers/network.ts b/infrastructure/cdk/src/providers/network.ts index 5bea9714b..277920cff 100644 --- a/infrastructure/cdk/src/providers/network.ts +++ b/infrastructure/cdk/src/providers/network.ts @@ -23,8 +23,11 @@ export class NetworkStack extends cdk.Stack { const config = new Config() /** Create a stage-specific Ec2 VPC and ECS cluster */ - this.vpc = new ec2.Vpc(this, config.getFullStackResourceName(this.name, 'vpc')) - this.cluster = new ecs.Cluster(this, config.getFullStackResourceName(this.name, 'cluster'), { vpc: this.vpc }) - + this.vpc = new ec2.Vpc(this, config.getFullStackResourceName(this.name, 'vpc'), { + natGateways: 0 + }) + this.cluster = new ecs.Cluster(this, config.getFullStackResourceName(this.name, 'cluster'), { + vpc: this.vpc + }) } } \ No newline at end of file