Skip to content

Commit

Permalink
Attach log group to MWAA environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Melle committed Jul 10, 2024
1 parent 943b33c commit 29087ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/mwaa-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
aws_ec2 as ec2,
aws_s3 as s3,
aws_iam as iam,
aws_logs as logs,
aws_mwaa as mwaa,
} from "aws-cdk-lib";
import { Construct } from "constructs";
Expand All @@ -29,6 +30,11 @@ export class MwaaStack extends Stack {

const role = this.createRole(environmentName, bucket);

const logGroup = new logs.LogGroup(this, "LogGroup", {
retention: logs.RetentionDays.ONE_DAY,
removalPolicy: RemovalPolicy.DESTROY,
});

const vpc = new ec2.Vpc(this, "Vpc", {
maxAzs: 2,
natGateways: 1,
Expand All @@ -48,6 +54,7 @@ export class MwaaStack extends Stack {
vpc,
allowAllOutbound: true,
});

securityGroup.addIngressRule(securityGroup, ec2.Port.allTraffic());

new mwaa.CfnEnvironment(this, "MwaaEnvironment", {
Expand All @@ -68,7 +75,11 @@ export class MwaaStack extends Stack {
},
webserverAccessMode: "PUBLIC_ONLY",
loggingConfiguration: {
taskLogs: { enabled: true, logLevel: "INFO" },
taskLogs: {
cloudWatchLogGroupArn: logGroup.logGroupArn,
enabled: true,
logLevel: "INFO",
},
},
});

Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/mwaa-airflow.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,14 @@ exports[`Match MwaaStack with snapshot 1`] = `
},
"Type": "AWS::IAM::Role",
},
"LogGroupF5B46931": {
"DeletionPolicy": "Delete",
"Properties": {
"RetentionInDays": 1,
},
"Type": "AWS::Logs::LogGroup",
"UpdateReplacePolicy": "Delete",
},
"MwaaEnvironment": {
"Properties": {
"AirflowVersion": "2.9.2",
Expand All @@ -695,6 +703,12 @@ exports[`Match MwaaStack with snapshot 1`] = `
},
"LoggingConfiguration": {
"TaskLogs": {
"CloudWatchLogGroupArn": {
"Fn::GetAtt": [
"LogGroupF5B46931",
"Arn",
],
},
"Enabled": true,
"LogLevel": "INFO",
},
Expand Down

0 comments on commit 29087ad

Please sign in to comment.