diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets.json new file mode 100644 index 0000000000000..2372b822099ba --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.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-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.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-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.assets.json new file mode 100644 index 0000000000000..93e694b2f20de --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "4e1c8f560b3bd32ad0758c6b7d04153c21111750f33dcfff05c52796bc71f9de": { + "source": { + "path": "LambdaAlarmActionIntegrationTestStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "4e1c8f560b3bd32ad0758c6b7d04153c21111750f33dcfff05c52796bc71f9de.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-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.template.json new file mode 100644 index 0000000000000..4ed772d3969f5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStack.template.json @@ -0,0 +1,259 @@ +{ + "Resources": { + "inAlarmLambdaServiceRole970DE64C": { + "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" + ] + ] + } + ] + } + }, + "inAlarmLambda0920D101": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" + }, + "FunctionName": "inAlarmLambda", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "inAlarmLambdaServiceRole970DE64C", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "inAlarmLambdaServiceRole970DE64C" + ] + }, + "Alarm7103F465": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ActionsEnabled": true, + "AlarmActions": [ + { + "Ref": "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b" + }, + { + "Ref": "alarmLambdaAliasaliasName41B27313" + }, + { + "Fn::GetAtt": [ + "alarmLambda131DB691", + "Arn" + ] + } + ], + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "FunctionName", + "Value": { + "Ref": "inAlarmLambda0920D101" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "Errors", + "Namespace": "AWS/Lambda", + "Period": 60, + "Statistic": "Sum", + "Threshold": 1, + "TreatMissingData": "notBreaching" + } + }, + "alarmLambdaServiceRoleCDAABB9D": { + "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" + ] + ] + } + ] + } + }, + "alarmLambda131DB691": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" + }, + "FunctionName": "alarmLambda", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "alarmLambdaServiceRoleCDAABB9D", + "Arn" + ] + }, + "Runtime": "nodejs18.x" + }, + "DependsOn": [ + "alarmLambdaServiceRoleCDAABB9D" + ] + }, + "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b": { + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "alarmLambda131DB691" + } + } + }, + "alarmLambdaCurrentVersionAlarmPermissionFEBD056F": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b" + }, + "Principal": "lambda.alarms.cloudwatch.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + }, + "SourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + }, + "alarmLambdaAliasaliasName41B27313": { + "Type": "AWS::Lambda::Alias", + "Properties": { + "FunctionName": { + "Ref": "alarmLambda131DB691" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b", + "Version" + ] + }, + "Name": "aliasName" + } + }, + "alarmLambdaAliasaliasNameAlarmPermission64A91652": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "alarmLambdaAliasaliasName41B27313" + }, + "Principal": "lambda.alarms.cloudwatch.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + }, + "SourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + }, + "alarmLambdaAlarmPermission43E41C89": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "alarmLambda131DB691", + "Arn" + ] + }, + "Principal": "lambda.alarms.cloudwatch.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + }, + "SourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + } + }, + "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-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/integ.json new file mode 100644 index 0000000000000..0d675b8e2e251 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "LambdaAlarmActionIntegrationTest/DefaultTest": { + "stacks": [ + "LambdaAlarmActionIntegrationTestStack" + ], + "assertionStack": "LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert", + "assertionStackName": "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/manifest.json new file mode 100644 index 0000000000000..f7d89d600b988 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/manifest.json @@ -0,0 +1,200 @@ +{ + "version": "36.0.0", + "artifacts": { + "LambdaAlarmActionIntegrationTestStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "LambdaAlarmActionIntegrationTestStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "LambdaAlarmActionIntegrationTestStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "LambdaAlarmActionIntegrationTestStack.template.json", + "terminationProtection": false, + "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}/4e1c8f560b3bd32ad0758c6b7d04153c21111750f33dcfff05c52796bc71f9de.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "LambdaAlarmActionIntegrationTestStack.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": [ + "LambdaAlarmActionIntegrationTestStack.assets" + ], + "metadata": { + "/LambdaAlarmActionIntegrationTestStack/inAlarmLambda/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "inAlarmLambdaServiceRole970DE64C" + } + ], + "/LambdaAlarmActionIntegrationTestStack/inAlarmLambda/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "inAlarmLambda0920D101" + } + ], + "/LambdaAlarmActionIntegrationTestStack/Alarm/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm7103F465" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda": [ + { + "type": "aws:cdk:warning", + "data": "AWS Lambda has changed their authorization strategy, which may cause client invocations using the 'Qualifier' parameter of the lambda function to fail with Access Denied errors.\nIf you are using a lambda Version or Alias, make sure to call 'grantInvoke' or 'addPermission' on the Version or Alias, not the underlying Function\nSee: https://github.com/aws/aws-cdk/issues/19273 [ack: @aws-cdk/aws-lambda:addPermissionsToVersionOrAlias]" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaServiceRoleCDAABB9D" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambda131DB691" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/CurrentVersion/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/CurrentVersion/AlarmPermission": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaCurrentVersionAlarmPermissionFEBD056F" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaAliasaliasName41B27313" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName/AlarmPermission": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaAliasaliasNameAlarmPermission64A91652" + } + ], + "/LambdaAlarmActionIntegrationTestStack/alarmLambda/AlarmPermission": [ + { + "type": "aws:cdk:logicalId", + "data": "alarmLambdaAlarmPermission43E41C89" + } + ], + "/LambdaAlarmActionIntegrationTestStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/LambdaAlarmActionIntegrationTestStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ], + "AlarmCurrentVersionAlarmPermission22DB4772": [ + { + "type": "aws:cdk:logicalId", + "data": "AlarmCurrentVersionAlarmPermission22DB4772", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } + ], + "AlarmAliasaliasNameAlarmPermission3887D390": [ + { + "type": "aws:cdk:logicalId", + "data": "AlarmAliasaliasNameAlarmPermission3887D390", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } + ], + "AlarmalarmLambdaAlarmPermission5CAF3DE7": [ + { + "type": "aws:cdk:logicalId", + "data": "AlarmalarmLambdaAlarmPermission5CAF3DE7", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } + ] + }, + "displayName": "LambdaAlarmActionIntegrationTestStack" + }, + "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.template.json", + "terminationProtection": false, + "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": [ + "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.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": [ + "LambdaAlarmActionIntegrationTestDefaultTestDeployAssertF9F882E5.assets" + ], + "metadata": { + "/LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "LambdaAlarmActionIntegrationTest/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-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/tree.json new file mode 100644 index 0000000000000..622364ad86c22 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.js.snapshot/tree.json @@ -0,0 +1,490 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "LambdaAlarmActionIntegrationTestStack": { + "id": "LambdaAlarmActionIntegrationTestStack", + "path": "LambdaAlarmActionIntegrationTestStack", + "children": { + "inAlarmLambda": { + "id": "inAlarmLambda", + "path": "LambdaAlarmActionIntegrationTestStack/inAlarmLambda", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "LambdaAlarmActionIntegrationTestStack/inAlarmLambda/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "LambdaAlarmActionIntegrationTestStack/inAlarmLambda/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/inAlarmLambda/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": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/inAlarmLambda/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" + }, + "functionName": "inAlarmLambda", + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "inAlarmLambdaServiceRole970DE64C", + "Arn" + ] + }, + "runtime": "nodejs18.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Function", + "version": "0.0.0" + } + }, + "Alarm": { + "id": "Alarm", + "path": "LambdaAlarmActionIntegrationTestStack/Alarm", + "children": { + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/Alarm/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "actionsEnabled": true, + "alarmActions": [ + { + "Ref": "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b" + }, + { + "Ref": "alarmLambdaAliasaliasName41B27313" + }, + { + "Fn::GetAtt": [ + "alarmLambda131DB691", + "Arn" + ] + } + ], + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "FunctionName", + "value": { + "Ref": "inAlarmLambda0920D101" + } + } + ], + "evaluationPeriods": 1, + "metricName": "Errors", + "namespace": "AWS/Lambda", + "period": 60, + "statistic": "Sum", + "threshold": 1, + "treatMissingData": "notBreaching" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "alarmLambda": { + "id": "alarmLambda", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/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": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" + }, + "functionName": "alarmLambda", + "handler": "index.handler", + "role": { + "Fn::GetAtt": [ + "alarmLambdaServiceRoleCDAABB9D", + "Arn" + ] + }, + "runtime": "nodejs18.x" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", + "version": "0.0.0" + } + }, + "CurrentVersion": { + "id": "CurrentVersion", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/CurrentVersion", + "children": { + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/CurrentVersion/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Version", + "aws:cdk:cloudformation:props": { + "functionName": { + "Ref": "alarmLambda131DB691" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnVersion", + "version": "0.0.0" + } + }, + "AlarmPermission": { + "id": "AlarmPermission", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/CurrentVersion/AlarmPermission", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Ref": "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b" + }, + "principal": "lambda.alarms.cloudwatch.amazonaws.com", + "sourceAccount": { + "Ref": "AWS::AccountId" + }, + "sourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Version", + "version": "0.0.0" + } + }, + "AliasaliasName": { + "id": "AliasaliasName", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName", + "children": { + "Resource": { + "id": "Resource", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Alias", + "aws:cdk:cloudformation:props": { + "functionName": { + "Ref": "alarmLambda131DB691" + }, + "functionVersion": { + "Fn::GetAtt": [ + "alarmLambdaCurrentVersionBDCE825C61967a018dfe55c69152d31b6e7ab40b", + "Version" + ] + }, + "name": "aliasName" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnAlias", + "version": "0.0.0" + } + }, + "ScalingRole": { + "id": "ScalingRole", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName/ScalingRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "AlarmPermission": { + "id": "AlarmPermission", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/AliasaliasName/AlarmPermission", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Ref": "alarmLambdaAliasaliasName41B27313" + }, + "principal": "lambda.alarms.cloudwatch.amazonaws.com", + "sourceAccount": { + "Ref": "AWS::AccountId" + }, + "sourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Alias", + "version": "0.0.0" + } + }, + "AlarmPermission": { + "id": "AlarmPermission", + "path": "LambdaAlarmActionIntegrationTestStack/alarmLambda/AlarmPermission", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Permission", + "aws:cdk:cloudformation:props": { + "action": "lambda:InvokeFunction", + "functionName": { + "Fn::GetAtt": [ + "alarmLambda131DB691", + "Arn" + ] + }, + "principal": "lambda.alarms.cloudwatch.amazonaws.com", + "sourceAccount": { + "Ref": "AWS::AccountId" + }, + "sourceArn": { + "Fn::GetAtt": [ + "Alarm7103F465", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.CfnPermission", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_lambda.Function", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "LambdaAlarmActionIntegrationTestStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "LambdaAlarmActionIntegrationTestStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "LambdaAlarmActionIntegrationTest": { + "id": "LambdaAlarmActionIntegrationTest", + "path": "LambdaAlarmActionIntegrationTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "LambdaAlarmActionIntegrationTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "LambdaAlarmActionIntegrationTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "LambdaAlarmActionIntegrationTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "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.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.ts new file mode 100644 index 0000000000000..25fa92a34464d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch-actions/test/integ.lambda-alarm-action.ts @@ -0,0 +1,55 @@ +import { App, Stack, StackProps, Duration } from 'aws-cdk-lib'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; +import { STANDARD_NODEJS_RUNTIME } from '../../config'; +import * as cloudwatchActions from 'aws-cdk-lib/aws-cloudwatch-actions'; + +class LambdaAlarmActionIntegrationTestStack extends Stack { + + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); + const inAlarmLambda = new lambda.Function(this, 'inAlarmLambda', { + functionName: 'inAlarmLambda', + runtime: STANDARD_NODEJS_RUNTIME, + handler: 'index.handler', + code: lambda.Code.fromInline(`exports.handler = ${handler.toString()}`), + }); + const alarm = new cloudwatch.Alarm(this, 'Alarm', { + comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD, + threshold: 1, + evaluationPeriods: 1, + metric: inAlarmLambda.metricErrors({ period: Duration.minutes(1) }), + actionsEnabled: true, + treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING, + }); + + const alarmLambda = new lambda.Function(this, 'alarmLambda', { + functionName: 'alarmLambda', + runtime: STANDARD_NODEJS_RUNTIME, + handler: 'index.handler', + code: lambda.Code.fromInline(`exports.handler = ${handler.toString()}`), + }); + const version = alarmLambda.currentVersion; + const aliasName = alarmLambda.addAlias('aliasName'); + alarm.addAlarmAction(new cloudwatchActions.LambdaAction(version)); + alarm.addAlarmAction(new cloudwatchActions.LambdaAction(aliasName)); + alarm.addAlarmAction(new cloudwatchActions.LambdaAction(alarmLambda)); + } +} + +const app = new App(); + +const stack = new LambdaAlarmActionIntegrationTestStack(app, 'LambdaAlarmActionIntegrationTestStack'); + +new integ.IntegTest(app, 'LambdaAlarmActionIntegrationTest', { + testCases: [stack], +}); + +app.synth(); + +/* eslint-disable no-console */ +function handler(event: any, _context: any, callback: any) { + console.log(JSON.stringify(event, undefined, 2)); + return callback(); +} \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-cloudwatch-actions/README.md b/packages/aws-cdk-lib/aws-cloudwatch-actions/README.md index 5da3f83ebcab3..d7bcb9ef651c5 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch-actions/README.md +++ b/packages/aws-cdk-lib/aws-cloudwatch-actions/README.md @@ -40,4 +40,30 @@ alarm.addAlarmAction( ); ``` +## Lambda Action Example + +```ts +import * as lambda from 'aws-cdk-lib/aws-lambda' +declare const alarm: cloudwatch.Alarm; +declare const fn: lambda.Function; +declare const alias: lambda.Alias; +declare const version: lambda.Version; + +// Attach a Lambda Function when alarm triggers +alarm.addAlarmAction( + new actions.LambdaAction(fn) +); + +// Attach a Lambda Function Alias when alarm triggers +alarm.addAlarmAction( + new actions.LambdaAction(alias) +); + +// Attach a Lambda Function version when alarm triggers +alarm.addAlarmAction( + new actions.LambdaAction(version) +); + +``` + See `aws-cdk-lib/aws-cloudwatch` for more information. diff --git a/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/index.ts b/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/index.ts index 191da008b23a9..32e159bb4e918 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/index.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/index.ts @@ -3,3 +3,4 @@ export * from './autoscaling'; export * from './sns'; export * from './ec2'; export * from './ssm'; +export * from './lambda'; \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/lambda.ts b/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/lambda.ts new file mode 100644 index 0000000000000..f754b60b3f1a5 --- /dev/null +++ b/packages/aws-cdk-lib/aws-cloudwatch-actions/lib/lambda.ts @@ -0,0 +1,35 @@ +import { Construct } from 'constructs'; +import * as cloudwatch from '../../aws-cloudwatch'; +import * as iam from '../../aws-iam'; +import * as lambda from '../../aws-lambda'; +import { Stack } from '../../core'; + +/** + * Use a Lambda action as an Alarm action + */ +export class LambdaAction implements cloudwatch.IAlarmAction { + private lambdaFunction: lambda.IAlias | lambda.IVersion | lambda.IFunction + constructor( + lambdaFunction: lambda.IAlias | lambda.IVersion | lambda.IFunction, + ) { + this.lambdaFunction = lambdaFunction; + } + + /** + * Returns an alarm action configuration to use a Lambda action as an alarm action. + * + * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html + */ + bind(_scope: Construct, _alarm: cloudwatch.IAlarm): cloudwatch.AlarmActionConfig { + this.lambdaFunction.addPermission('AlarmPermission', { + sourceAccount: Stack.of(_scope).account, + action: 'lambda:InvokeFunction', + sourceArn: _alarm.alarmArn, + principal: new iam.ServicePrincipal('lambda.alarms.cloudwatch.amazonaws.com'), + }); + + return { + alarmActionArn: this.lambdaFunction.functionArn, + }; + } +} diff --git a/packages/aws-cdk-lib/aws-cloudwatch-actions/test/lambda.test.ts b/packages/aws-cdk-lib/aws-cloudwatch-actions/test/lambda.test.ts new file mode 100644 index 0000000000000..03e71b40b0cbb --- /dev/null +++ b/packages/aws-cdk-lib/aws-cloudwatch-actions/test/lambda.test.ts @@ -0,0 +1,113 @@ +import { Template } from '../../assertions'; +import * as cloudwatch from '../../aws-cloudwatch'; +import * as lambda from '../../aws-lambda'; +import { Stack } from '../../core'; +import * as actions from '../lib/index'; + +test('can use lambda as alarm action', () => { + // GIVEN + const stack = new Stack(); + const alarm = new cloudwatch.Alarm(stack, 'Alarm', { + metric: new cloudwatch.Metric({ + namespace: 'AWS', + metricName: 'Test', + }), + evaluationPeriods: 3, + threshold: 100, + }); + + // WHEN + const alarmLambda = new lambda.Function(stack, 'alarmLambda', { + runtime: lambda.Runtime.PYTHON_3_12, + functionName: 'alarmLambda', + code: lambda.Code.fromInline(` +def handler(event, context): + print('event:', event) + print('.............................................') + print('context:', context)`), + handler: 'index.handler', + }); + alarm.addAlarmAction(new actions.LambdaAction(alarmLambda)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { + AlarmActions: [ + { + 'Fn::GetAtt': [ + 'alarmLambda131DB691', + 'Arn', + ], + }, + ], + }); +}); + +test('can use lambda alias as alarm action', () => { + // GIVEN + const stack = new Stack(); + const alarm = new cloudwatch.Alarm(stack, 'Alarm', { + metric: new cloudwatch.Metric({ + namespace: 'AWS', + metricName: 'Test', + }), + evaluationPeriods: 3, + threshold: 100, + }); + + // WHEN + const alarmLambda = new lambda.Function(stack, 'alarmLambda', { + runtime: lambda.Runtime.PYTHON_3_12, + functionName: 'alarmLambda', + code: lambda.Code.fromInline(` +def handler(event, context): + print('event:', event) + print('.............................................') + print('context:', context)`), + handler: 'index.handler', + }); + const aliasName = alarmLambda.addAlias('aliasName'); + alarm.addAlarmAction(new actions.LambdaAction(aliasName)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { + AlarmActions: [ + { + Ref: 'alarmLambdaAliasaliasName41B27313', + }, + ], + }); +}); + +test('can use lambda version as alarm action', () => { + // GIVEN + const stack = new Stack(); + const alarm = new cloudwatch.Alarm(stack, 'Alarm', { + metric: new cloudwatch.Metric({ namespace: 'AWS', metricName: 'Test' }), + evaluationPeriods: 3, + threshold: 100, + }); + + // WHEN + const alarmLambda = new lambda.Function(stack, 'alarmLambda', { + runtime: lambda.Runtime.PYTHON_3_12, + functionName: 'alarmLambda', + code: lambda.Code.fromInline(` +def handler(event, context): + print('event:', event) + print('.............................................') + print('context:', context)`), + handler: 'index.handler', + }); + const version = alarmLambda.currentVersion; + alarm.addAlarmAction(new actions.LambdaAction(version)); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { + AlarmActions: [ + { + Ref: 'alarmLambdaCurrentVersionBDCE825Cf5e98d107ecb420808f3d9421127310e', + }, + ], + }); +}); +