diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.assets.json new file mode 100644 index 0000000000000..f088793003f6e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.assets.json @@ -0,0 +1,20 @@ +{ + "version": "32.0.0", + "files": { + "7db545e495a738edfcd36389d734d374090aa78c8532312439ddb90cfffdc1ef": { + "source": { + "path": "aws-cdk-subscriptionfilter-integ.template.json", + "packaging": "file" + }, + "destinations": { + "355939527584-us-east-1": { + "bucketName": "cdk-hnb659fds-assets-355939527584-us-east-1", + "objectKey": "7db545e495a738edfcd36389d734d374090aa78c8532312439ddb90cfffdc1ef.json", + "region": "us-east-1", + "assumeRoleArn": "arn:${AWS::Partition}:iam::355939527584:role/cdk-hnb659fds-file-publishing-role-355939527584-us-east-1" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.template.json new file mode 100644 index 0000000000000..ebbf4c57b3e94 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/aws-cdk-subscriptionfilter-integ.template.json @@ -0,0 +1,134 @@ +{ + "Resources": { + "LogGroupF5B46931": { + "Type": "AWS::Logs::LogGroup", + "Properties": { + "RetentionInDays": 731 + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "LogGroupSubscriptionCanInvokeLambdaE05AC235": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "Principal": "logs.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "LogGroupF5B46931", + "Arn" + ] + } + } + }, + "LogGroupSubscriptionE3573E29": { + "Type": "AWS::Logs::SubscriptionFilter", + "Properties": { + "DestinationArn": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "FilterName": "CustomSubscriptionFilterName", + "FilterPattern": "\"ERROR\" \"MainThread\"", + "LogGroupName": { + "Ref": "LogGroupF5B46931" + } + }, + "DependsOn": [ + "LogGroupSubscriptionCanInvokeLambdaE05AC235" + ] + }, + "FunctionServiceRole675BB04A": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Function76856677": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "foo" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionServiceRole675BB04A", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "FunctionServiceRole675BB04A" + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/cdk.out new file mode 100644 index 0000000000000..f0b901e7c06e5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"32.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integ.json new file mode 100644 index 0000000000000..894035b7c9314 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "32.0.0", + "testCases": { + "integ-test/DefaultTest": { + "stacks": [ + "aws-cdk-subscriptionfilter-integ" + ], + "assertionStack": "integ-test/DefaultTest/DeployAssert", + "assertionStackName": "integtestDefaultTestDeployAssert24D5C536" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json new file mode 100644 index 0000000000000..4b008a0cae838 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json @@ -0,0 +1,19 @@ +{ + "version": "32.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "integtestDefaultTestDeployAssert24D5C536.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/integtestDefaultTestDeployAssert24D5C536.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/manifest.json new file mode 100644 index 0000000000000..65838f5fcbc44 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/manifest.json @@ -0,0 +1,135 @@ +{ + "version": "32.0.0", + "artifacts": { + "aws-cdk-subscriptionfilter-integ.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-subscriptionfilter-integ.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-subscriptionfilter-integ": { + "type": "aws:cloudformation:stack", + "environment": "aws://355939527584/us-east-1", + "properties": { + "templateFile": "aws-cdk-subscriptionfilter-integ.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::355939527584:role/cdk-hnb659fds-deploy-role-355939527584-us-east-1", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::355939527584:role/cdk-hnb659fds-cfn-exec-role-355939527584-us-east-1", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-355939527584-us-east-1/7db545e495a738edfcd36389d734d374090aa78c8532312439ddb90cfffdc1ef.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-subscriptionfilter-integ.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::355939527584:role/cdk-hnb659fds-lookup-role-355939527584-us-east-1", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-cdk-subscriptionfilter-integ.assets" + ], + "metadata": { + "/aws-cdk-subscriptionfilter-integ/LogGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LogGroupF5B46931" + } + ], + "/aws-cdk-subscriptionfilter-integ/LogGroup/Subscription/CanInvokeLambda": [ + { + "type": "aws:cdk:logicalId", + "data": "LogGroupSubscriptionCanInvokeLambdaE05AC235" + } + ], + "/aws-cdk-subscriptionfilter-integ/LogGroup/Subscription/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LogGroupSubscriptionE3573E29" + } + ], + "/aws-cdk-subscriptionfilter-integ/Function/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "FunctionServiceRole675BB04A" + } + ], + "/aws-cdk-subscriptionfilter-integ/Function/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Function76856677" + } + ], + "/aws-cdk-subscriptionfilter-integ/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-subscriptionfilter-integ/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-subscriptionfilter-integ" + }, + "integtestDefaultTestDeployAssert24D5C536.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integtestDefaultTestDeployAssert24D5C536.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integtestDefaultTestDeployAssert24D5C536": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integtestDefaultTestDeployAssert24D5C536.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integtestDefaultTestDeployAssert24D5C536.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "integtestDefaultTestDeployAssert24D5C536.assets" + ], + "metadata": { + "/integ-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/tree.json new file mode 100644 index 0000000000000..098ac062564a3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.js.snapshot/tree.json @@ -0,0 +1,277 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-cdk-subscriptionfilter-integ": { + "id": "aws-cdk-subscriptionfilter-integ", + "path": "aws-cdk-subscriptionfilter-integ", + "children": { + "LogGroup": { + "id": "LogGroup", + "path": "aws-cdk-subscriptionfilter-integ/LogGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-subscriptionfilter-integ/LogGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", + "aws:cdk:cloudformation:props": { + "retentionInDays": 731 + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "Subscription": { + "id": "Subscription", + "path": "aws-cdk-subscriptionfilter-integ/LogGroup/Subscription", + "children": { + "CanInvokeLambda": { + "id": "CanInvokeLambda", + "path": "aws-cdk-subscriptionfilter-integ/LogGroup/Subscription/CanInvokeLambda", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "principal": "logs.amazonaws.com", + "sourceArn": { + "Fn::GetAtt": [ + "LogGroupF5B46931", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-subscriptionfilter-integ/LogGroup/Subscription/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::SubscriptionFilter", + "aws:cdk:cloudformation:props": { + "destinationArn": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "filterName": "CustomSubscriptionFilterName", + "filterPattern": "\"ERROR\" \"MainThread\"", + "logGroupName": { + "Ref": "LogGroupF5B46931" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "Function": { + "id": "Function", + "path": "aws-cdk-subscriptionfilter-integ/Function", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "aws-cdk-subscriptionfilter-integ/Function/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "aws-cdk-subscriptionfilter-integ/Function/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-subscriptionfilter-integ/Function/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-cdk-subscriptionfilter-integ/Function/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "foo" + }, + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "FunctionServiceRole675BB04A", + "Arn" + ] + }, + "runtime": "nodejs18.x" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-cdk-subscriptionfilter-integ/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-cdk-subscriptionfilter-integ/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "integ-test": { + "id": "integ-test", + "path": "integ-test", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "integ-test/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "integ-test/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "integ-test/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-test/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-test/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.69" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.ts new file mode 100644 index 0000000000000..047a5314a8f7f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.subscriptionfilter.ts @@ -0,0 +1,37 @@ +import { App, Stack, StackProps } from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { LogGroup, FilterPattern } from 'aws-cdk-lib/aws-logs'; +import { LambdaDestination } from 'aws-cdk-lib/aws-logs-destinations'; +import { Function, Code, Runtime } from 'aws-cdk-lib/aws-lambda'; + +class SubscriptionFilterIntegStack extends Stack { + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); + + const logGroup = new LogGroup(this, 'LogGroup'); + + const fn = new Function(this, 'Function', { + runtime: Runtime.NODEJS_18_X, + handler: 'index.handler', + code: Code.fromInline('foo'), + }); + + logGroup.addSubscriptionFilter('Subscription', { + destination: new LambdaDestination(fn), + filterPattern: FilterPattern.allTerms('ERROR', 'MainThread'), + filterName: 'CustomSubscriptionFilterName', + }); + } +} + +const app = new App(); +const testCase = new SubscriptionFilterIntegStack(app, 'aws-cdk-subscriptionfilter-integ', { + env: { + account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION, + }, +}); + +new IntegTest(app, 'integ-test', { + testCases: [testCase], +}); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-logs/README.md b/packages/aws-cdk-lib/aws-logs/README.md index 3f89ae6084e97..a4772aac170cb 100644 --- a/packages/aws-cdk-lib/aws-logs/README.md +++ b/packages/aws-cdk-lib/aws-logs/README.md @@ -116,6 +116,7 @@ new logs.SubscriptionFilter(this, 'Subscription', { logGroup, destination: new destinations.LambdaDestination(fn), filterPattern: logs.FilterPattern.allTerms("ERROR", "MainThread"), + filterName: 'ErrorInMainThread', }); ``` diff --git a/packages/aws-cdk-lib/aws-logs/lib/log-group.ts b/packages/aws-cdk-lib/aws-logs/lib/log-group.ts index 6dcda58ed48cb..f578d1234abd2 100644 --- a/packages/aws-cdk-lib/aws-logs/lib/log-group.ts +++ b/packages/aws-cdk-lib/aws-logs/lib/log-group.ts @@ -524,6 +524,13 @@ export interface SubscriptionFilterOptions { * Log events matching this pattern will be sent to the destination. */ readonly filterPattern: IFilterPattern; + + /** + * The name of the subscription filter. + * + * @default Automatically generated + */ + readonly filterName?: string; } /** diff --git a/packages/aws-cdk-lib/aws-logs/lib/subscription-filter.ts b/packages/aws-cdk-lib/aws-logs/lib/subscription-filter.ts index 5011006fa3133..bc2b18c719cc0 100644 --- a/packages/aws-cdk-lib/aws-logs/lib/subscription-filter.ts +++ b/packages/aws-cdk-lib/aws-logs/lib/subscription-filter.ts @@ -53,7 +53,9 @@ export interface SubscriptionFilterProps extends SubscriptionFilterOptions { */ export class SubscriptionFilter extends Resource { constructor(scope: Construct, id: string, props: SubscriptionFilterProps) { - super(scope, id); + super(scope, id, { + physicalName: props.filterName, + }); const destProps = props.destination.bind(this, props.logGroup); @@ -62,6 +64,7 @@ export class SubscriptionFilter extends Resource { destinationArn: destProps.arn, roleArn: destProps.role && destProps.role.roleArn, filterPattern: props.filterPattern.logPatternString, + filterName: this.physicalName, }); } } diff --git a/packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts b/packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts index a1d2fb092fabf..01621c1fe2f31 100644 --- a/packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts +++ b/packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts @@ -1,9 +1,10 @@ +import { Construct } from 'constructs'; import { Template } from '../../assertions'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; import { Bucket } from '../../aws-s3'; import { CfnParameter, Fn, RemovalPolicy, Stack } from '../../core'; -import { LogGroup, RetentionDays, DataProtectionPolicy, DataIdentifier } from '../lib'; +import { LogGroup, RetentionDays, DataProtectionPolicy, DataIdentifier, ILogGroup, ILogSubscriptionDestination, FilterPattern } from '../lib'; describe('log group', () => { test('set kms key when provided', () => { @@ -686,6 +687,29 @@ describe('log group', () => { }); }); +describe('subscription filter', () => { + test('add subscription filter with custom name', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const logGroup = new LogGroup(stack, 'LogGroup'); + logGroup.addSubscriptionFilter('Subscription', { + destination: new FakeDestination(), + filterPattern: FilterPattern.literal('some pattern'), + filterName: 'CustomSubscriptionFilterName', + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { + DestinationArn: 'arn:bogus', + FilterPattern: 'some pattern', + LogGroupName: { Ref: 'LogGroupF5B46931' }, + FilterName: 'CustomSubscriptionFilterName', + }); + }); +}); + function dataDrivenTests(cases: string[], body: (suffix: string) => void): void { for (let i = 0; i < cases.length; i++) { const args = cases[i]; // Need to capture inside loop for safe use inside closure. @@ -694,3 +718,11 @@ function dataDrivenTests(cases: string[], body: (suffix: string) => void): void }); } } + +class FakeDestination implements ILogSubscriptionDestination { + public bind(_scope: Construct, _sourceLogGroup: ILogGroup) { + return { + arn: 'arn:bogus', + }; + } +} \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-logs/test/subscriptionfilter.test.ts b/packages/aws-cdk-lib/aws-logs/test/subscriptionfilter.test.ts index 027916f393724..1b03241f7f4c1 100644 --- a/packages/aws-cdk-lib/aws-logs/test/subscriptionfilter.test.ts +++ b/packages/aws-cdk-lib/aws-logs/test/subscriptionfilter.test.ts @@ -23,6 +23,28 @@ describe('subscription filter', () => { LogGroupName: { Ref: 'LogGroupF5B46931' }, }); }); + + test('specifying custom name', () => { + // GIVEN + const stack = new Stack(); + const logGroup = new LogGroup(stack, 'LogGroup'); + + // WHEN + new SubscriptionFilter(stack, 'Subscription', { + logGroup, + destination: new FakeDestination(), + filterPattern: FilterPattern.literal('some pattern'), + filterName: 'CustomSubscriptionFilterName', + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { + DestinationArn: 'arn:bogus', + FilterPattern: 'some pattern', + LogGroupName: { Ref: 'LogGroupF5B46931' }, + FilterName: 'CustomSubscriptionFilterName', + }); + }); }); class FakeDestination implements ILogSubscriptionDestination {