Skip to content

Commit

Permalink
fix(misc): change configuration for vpc, alb health check
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Caffey committed May 9, 2021
1 parent 6d21e17 commit 45a76c0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
.PHONY: synth
.PHONY: synth test deploy

synth:
cdk synth --app='./lib/integ.default.js'
cdk synth --app='./lib/integ.default.js'

deploy:
cdk deploy --app='./lib/integ.default.js'

destroy:
cdk destroy --app='./lib/integ.default.js'

test:
npm run test
16 changes: 16 additions & 0 deletions src/django-cdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as patterns from '@aws-cdk/aws-ecs-patterns';
import * as logs from '@aws-cdk/aws-logs';
import * as s3 from '@aws-cdk/aws-s3';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import * as cdk from '@aws-cdk/core';
Expand Down Expand Up @@ -88,12 +89,20 @@ export class DjangoCdk extends cdk.Construct {
AWS_STORAGE_BUCKET_NAME: staticFilesBucket.bucketName,
POSTGRES_SERVICE_HOST: database.rdsPostgresInstance.dbInstanceEndpointAddress,
POSTGRES_PASSWORD: this.secret.secretValue.toString(),
DEBUG: '0',
DJANGO_SETTINGS_MODULE: 'backend.settings.base',
};

const container = taskDefinition.addContainer('backendContainer', {
image: this.image,
environment,
command: props.webCommand,
logging: ecs.LogDriver.awsLogs(
{
logRetention: logs.RetentionDays.ONE_DAY,
streamPrefix: 'BackendContainer',
},
),
});

container.addPortMappings({
Expand Down Expand Up @@ -125,6 +134,13 @@ export class DjangoCdk extends cdk.Construct {
securityGroups: [appSecurityGroup],
});

/**
* Health check for the application load balancer
*/
albfs.targetGroup.configureHealthCheck({
path: '/api/health-check/',
});

/**
* Allows the app security group to communicate with the database security group
*/
Expand Down
3 changes: 1 addition & 2 deletions src/integ.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack', { env });

new DjangoCdk(stack, 'Cdk-Sample-Lib', {
bucketName: 'my-django-cdk-static-files-bucket',
imageDirectory: './test/backend',
imageDirectory: './test/django-step-by-step/backend',
webCommand: [
'gunicorn',
'-t',
Expand Down
7 changes: 7 additions & 0 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// import * as ec2 from '@aws-cdk/aws-ec2';
import { ISecurityGroup } from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as logs from '@aws-cdk/aws-logs';
import * as cdk from '@aws-cdk/core';

export interface managementCommandTaskProps {
Expand Down Expand Up @@ -28,6 +29,12 @@ export class managementCommandTask extends cdk.Construct {
taskDefinition.addContainer(`TaskContainer${id}`, {
image: props.image,
command: props.command,
logging: ecs.LogDriver.awsLogs(
{
logRetention: logs.RetentionDays.ONE_DAY,
streamPrefix: `${id}Container`,
},
),
});
}
}
2 changes: 2 additions & 0 deletions src/vpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export class ApplicationVpc extends cdk.Construct {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
const vpc = new ec2.Vpc(scope, 'ApplicationVpc', {
maxAzs: 2,
natGateways: 1,
subnetConfiguration: [
{
cidrMask: 24,
Expand Down
1 change: 0 additions & 1 deletion test/djangoCdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test('create app with default bucket name', () => {
const stack = new cdk.Stack(app, 'MyStack', { env });

const djangoCdkProps: DjangoCdkProps = {
bucketName: 'my-bucket',
imageDirectory: './test/django-step-by-step/backend',
webCommand: ['gunicorn'],
};
Expand Down

0 comments on commit 45a76c0

Please sign in to comment.