@@ -587,29 +587,96 @@ const betterStackLambda = new aws.lambda.Function(
587587 }
588588) ;
589589
590- // CloudWatch subscription filter to forward logs to Better Stack
591- const betterStackSubscriptionFilter = new aws . cloudwatch . LogSubscriptionFilter (
592- "pathfinder-better-stack-subscription-filter" ,
590+ // CloudWatch subscription filters to forward ALL logs to Better Stack
591+ // 1. ECS Application logs
592+ const betterStackECSSubscriptionFilter =
593+ new aws . cloudwatch . LogSubscriptionFilter (
594+ "pathfinder-better-stack-ecs-subscription-filter" ,
595+ {
596+ logGroup : logGroup . name ,
597+ filterPattern : "" , // Forward all logs
598+ destinationArn : betterStackLambda . arn ,
599+ name : "logtail-aws-lambda-ecs-filter" ,
600+ }
601+ ) ;
602+
603+ // 2. RDS PostgreSQL logs
604+ const betterStackRDSSubscriptionFilter =
605+ new aws . cloudwatch . LogSubscriptionFilter (
606+ "pathfinder-better-stack-rds-subscription-filter" ,
607+ {
608+ logGroup : pulumi . interpolate `/aws/rds/instance/${ db . id } /postgresql` ,
609+ filterPattern : "" , // Forward all logs
610+ destinationArn : betterStackLambda . arn ,
611+ name : "logtail-aws-lambda-rds-filter" ,
612+ }
613+ ) ;
614+
615+ // 3. Better Stack Lambda function logs (for debugging the forwarder itself)
616+ const betterStackLambdaLogGroup = new aws . cloudwatch . LogGroup (
617+ "pathfinder-better-stack-lambda-logs" ,
593618 {
594- logGroup : logGroup . name ,
595- filterPattern : "" , // Forward all logs
596- destinationArn : betterStackLambda . arn ,
597- name : "logtail-aws-lambda-filter" ,
619+ name : pulumi . interpolate `/aws/lambda/${ betterStackLambda . name } ` ,
620+ retentionInDays : 7 ,
621+ tags : {
622+ ...commonTags ,
623+ Name : "pathfinder-better-stack-lambda-logs" ,
624+ Type : "lambda-logs" ,
625+ } ,
598626 }
599627) ;
600628
601- // Grant CloudWatch Logs permission to invoke the Lambda function
602- const betterStackLambdaPermission = new aws . lambda . Permission (
603- "pathfinder-better-stack-lambda-permission" ,
629+ const betterStackLambdaSubscriptionFilter =
630+ new aws . cloudwatch . LogSubscriptionFilter (
631+ "pathfinder-better-stack-lambda-subscription-filter" ,
632+ {
633+ logGroup : betterStackLambdaLogGroup . name ,
634+ filterPattern : "" , // Forward all logs
635+ destinationArn : betterStackLambda . arn ,
636+ name : "logtail-aws-lambda-self-filter" ,
637+ }
638+ ) ;
639+
640+ // Grant CloudWatch Logs permission to invoke the Lambda function from multiple sources
641+ const betterStackLambdaPermissionECS = new aws . lambda . Permission (
642+ "pathfinder-better-stack-lambda-permission-ecs" ,
604643 {
605- statementId : "AllowExecutionFromCloudWatchLogs " ,
644+ statementId : "AllowExecutionFromCloudWatchLogsECS " ,
606645 action : "lambda:InvokeFunction" ,
607646 function : betterStackLambda . name ,
608647 principal : "logs.amazonaws.com" ,
609648 sourceArn : pulumi . interpolate `${ logGroup . arn } :*` ,
610649 }
611650) ;
612651
652+ const callerIdentity = pulumi . output ( aws . getCallerIdentity ( { } ) ) ;
653+ const betterStackLambdaPermissionRDS = new aws . lambda . Permission (
654+ "pathfinder-better-stack-lambda-permission-rds" ,
655+ {
656+ statementId : "AllowExecutionFromCloudWatchLogsRDS" ,
657+ action : "lambda:InvokeFunction" ,
658+ function : betterStackLambda . name ,
659+ principal : "logs.amazonaws.com" ,
660+ sourceArn : pulumi
661+ . all ( [ aws . config . region , callerIdentity . accountId , db . id ] )
662+ . apply (
663+ ( [ region , accountId , dbId ] ) =>
664+ `arn:aws:logs:${ region } :${ accountId } :log-group:/aws/rds/instance/${ dbId } /postgresql:*`
665+ ) ,
666+ }
667+ ) ;
668+
669+ const betterStackLambdaPermissionSelf = new aws . lambda . Permission (
670+ "pathfinder-better-stack-lambda-permission-self" ,
671+ {
672+ statementId : "AllowExecutionFromCloudWatchLogsLambda" ,
673+ action : "lambda:InvokeFunction" ,
674+ function : betterStackLambda . name ,
675+ principal : "logs.amazonaws.com" ,
676+ sourceArn : pulumi . interpolate `${ betterStackLambdaLogGroup . arn } :*` ,
677+ }
678+ ) ;
679+
613680// ==========================================
614681// STACK OUTPUTS
615682// Values accessible after deployment
0 commit comments