From 3d9647173605743bbe19d012b0eceff42e8f6834 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 13 Oct 2023 16:22:40 +0100 Subject: [PATCH] add logging --- .../interactive-tilemaker.test.ts.snap | 107 ++++++++++++++++++ lib/interactive-tilemaker.ts | 2 + 2 files changed, 109 insertions(+) diff --git a/lib/__snapshots__/interactive-tilemaker.test.ts.snap b/lib/__snapshots__/interactive-tilemaker.test.ts.snap index 8a8ec60..5954834 100644 --- a/lib/__snapshots__/interactive-tilemaker.test.ts.snap +++ b/lib/__snapshots__/interactive-tilemaker.test.ts.snap @@ -147,11 +147,29 @@ exports[`The InteractiveTilemaker stack matches the snapshot 1`] = ` { "Essential": true, "Image": "hello-world", + "LogConfiguration": { + "LogDriver": "awslogs", + "Options": { + "awslogs-group": { + "Ref": "TileMakerTaskHelloWorldContainerLogGroup15B4BEFA", + }, + "awslogs-region": { + "Ref": "AWS::Region", + }, + "awslogs-stream-prefix": "tile-maker/hello-world", + }, + }, "Memory": 2048, "Name": "HelloWorldContainer", }, ], "Cpu": "1024", + "ExecutionRoleArn": { + "Fn::GetAtt": [ + "TileMakerTaskExecutionRole9653D5DB", + "Arn", + ], + }, "Family": "InteractiveTilemakerTileMakerTask12DC9A80", "Memory": "2048", "NetworkMode": "awsvpc", @@ -189,6 +207,95 @@ exports[`The InteractiveTilemaker stack matches the snapshot 1`] = ` }, "Type": "AWS::ECS::TaskDefinition", }, + "TileMakerTaskExecutionRole9653D5DB": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Tags": [ + { + "Key": "gu:cdk:version", + "Value": "TEST", + }, + { + "Key": "gu:repo", + "Value": "guardian/interactive-tilemaker", + }, + { + "Key": "Stack", + "Value": "interactives", + }, + { + "Key": "Stage", + "Value": "TEST", + }, + ], + }, + "Type": "AWS::IAM::Role", + }, + "TileMakerTaskExecutionRoleDefaultPolicy10BD4468": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents", + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "TileMakerTaskHelloWorldContainerLogGroup15B4BEFA", + "Arn", + ], + }, + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "TileMakerTaskExecutionRoleDefaultPolicy10BD4468", + "Roles": [ + { + "Ref": "TileMakerTaskExecutionRole9653D5DB", + }, + ], + }, + "Type": "AWS::IAM::Policy", + }, + "TileMakerTaskHelloWorldContainerLogGroup15B4BEFA": { + "DeletionPolicy": "Retain", + "Properties": { + "Tags": [ + { + "Key": "gu:cdk:version", + "Value": "TEST", + }, + { + "Key": "gu:repo", + "Value": "guardian/interactive-tilemaker", + }, + { + "Key": "Stack", + "Value": "interactives", + }, + { + "Key": "Stage", + "Value": "TEST", + }, + ], + }, + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + }, "TileMakerTaskTaskRole4911CC8F": { "Properties": { "AssumeRolePolicyDocument": { diff --git a/lib/interactive-tilemaker.ts b/lib/interactive-tilemaker.ts index 0c07143..81ba18a 100644 --- a/lib/interactive-tilemaker.ts +++ b/lib/interactive-tilemaker.ts @@ -8,6 +8,7 @@ import { ContainerImage, CpuArchitecture, FargateService, + LogDriver, OperatingSystemFamily, TaskDefinition, } from 'aws-cdk-lib/aws-ecs'; @@ -47,6 +48,7 @@ export class InteractiveTilemaker extends GuStack { task.addContainer('HelloWorldContainer', { image: ContainerImage.fromRegistry('hello-world'), memoryLimitMiB: 2048, + logging: LogDriver.awsLogs({streamPrefix: "tile-maker/hello-world"}) }); new FargateService(this, 'TileMakerService', {