diff --git a/.projen/deps.json b/.projen/deps.json index 2403de47b..bca6b6fa7 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -15,6 +15,10 @@ "version": "2.120.0-alpha.0", "type": "build" }, + { + "name": "@aws-sdk/client-cloudwatch", + "type": "build" + }, { "name": "@aws-sdk/client-codeartifact", "type": "build" diff --git a/.projen/tasks.json b/.projen/tasks.json index b318ffc5a..ef855a0ea 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -1201,13 +1201,13 @@ }, "steps": [ { - "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --dep=dev --filter=@aws-sdk/client-codeartifact,@aws-sdk/client-ecs,@aws-sdk/client-lambda,@aws-sdk/client-s3,@aws-sdk/client-sfn,@aws-sdk/client-sqs,@jsii/spec,@octokit/rest,@smithy/types,@smithy/util-retry,@smithy/util-stream,@types/aws-lambda,@types/fs-extra,@types/jest,@types/markdown-it,@types/markdown-it-emoji,@types/semver,@types/streamx,@types/tar-stream,@types/tough-cookie,@types/uuid,async-sema,aws-embedded-metrics,aws-sdk,aws-sdk-client-mock,aws-sdk-client-mock-jest,aws-sdk-mock,aws-xray-sdk-core,case,cdk-dia,cdk-watchful,cdklabs-projen-project-types,chalk,construct-hub-webapp,dotenv,esbuild,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-prettier,feed,fs-extra,glob,got,jest,jsii-diff,jsii-pacmak,JSONStream,markdown-it,markdown-it-emoji,nock,normalize-registry-metadata,prettier,projen,semver,spdx-license-list,streamcount,streamx,tar-stream,ts-node,uuid,yaml" + "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --dep=dev --filter=@aws-sdk/client-cloudwatch,@aws-sdk/client-codeartifact,@aws-sdk/client-ecs,@aws-sdk/client-lambda,@aws-sdk/client-s3,@aws-sdk/client-sfn,@aws-sdk/client-sqs,@jsii/spec,@octokit/rest,@smithy/types,@smithy/util-retry,@smithy/util-stream,@types/aws-lambda,@types/fs-extra,@types/jest,@types/markdown-it,@types/markdown-it-emoji,@types/semver,@types/streamx,@types/tar-stream,@types/tough-cookie,@types/uuid,async-sema,aws-embedded-metrics,aws-sdk,aws-sdk-client-mock,aws-sdk-client-mock-jest,aws-sdk-mock,aws-xray-sdk-core,case,cdk-dia,cdk-watchful,cdklabs-projen-project-types,chalk,construct-hub-webapp,dotenv,esbuild,eslint-config-prettier,eslint-import-resolver-typescript,eslint-plugin-import,eslint-plugin-prettier,feed,fs-extra,glob,got,jest,jsii-diff,jsii-pacmak,JSONStream,markdown-it,markdown-it-emoji,nock,normalize-registry-metadata,prettier,projen,semver,spdx-license-list,streamcount,streamx,tar-stream,ts-node,uuid,yaml" }, { "exec": "yarn install --check-files" }, { - "exec": "yarn upgrade @aws-cdk/aws-servicecatalogappregistry-alpha @aws-cdk/integ-runner @aws-cdk/integ-tests-alpha @aws-sdk/client-codeartifact @aws-sdk/client-ecs @aws-sdk/client-lambda @aws-sdk/client-s3 @aws-sdk/client-sfn @aws-sdk/client-sqs @jsii/spec @octokit/rest @smithy/types @smithy/util-retry @smithy/util-stream @types/aws-lambda @types/fs-extra @types/jest @types/markdown-it @types/markdown-it-emoji @types/node @types/semver @types/streamx @types/tar-stream @types/tough-cookie @types/uuid @typescript-eslint/eslint-plugin @typescript-eslint/parser async-sema aws-cdk-lib aws-cdk aws-embedded-metrics aws-sdk aws-sdk-client-mock aws-sdk-client-mock-jest aws-sdk-mock aws-xray-sdk-core case cdk-dia cdk-watchful cdklabs-projen-project-types chalk commit-and-tag-version construct-hub-webapp dotenv esbuild eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint feed fs-extra glob got jest jest-junit jsii-diff jsii-docgen jsii-pacmak jsii-rosetta jsii JSONStream markdown-it markdown-it-emoji nock normalize-registry-metadata prettier projen semver spdx-license-list streamcount streamx tar-stream ts-node typescript uuid yaml" + "exec": "yarn upgrade @aws-cdk/aws-servicecatalogappregistry-alpha @aws-cdk/integ-runner @aws-cdk/integ-tests-alpha @aws-sdk/client-cloudwatch @aws-sdk/client-codeartifact @aws-sdk/client-ecs @aws-sdk/client-lambda @aws-sdk/client-s3 @aws-sdk/client-sfn @aws-sdk/client-sqs @jsii/spec @octokit/rest @smithy/types @smithy/util-retry @smithy/util-stream @types/aws-lambda @types/fs-extra @types/jest @types/markdown-it @types/markdown-it-emoji @types/node @types/semver @types/streamx @types/tar-stream @types/tough-cookie @types/uuid @typescript-eslint/eslint-plugin @typescript-eslint/parser async-sema aws-cdk-lib aws-cdk aws-embedded-metrics aws-sdk aws-sdk-client-mock aws-sdk-client-mock-jest aws-sdk-mock aws-xray-sdk-core case cdk-dia cdk-watchful cdklabs-projen-project-types chalk commit-and-tag-version construct-hub-webapp dotenv esbuild eslint-config-prettier eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint feed fs-extra glob got jest jest-junit jsii-diff jsii-docgen jsii-pacmak jsii-rosetta jsii JSONStream markdown-it markdown-it-emoji nock normalize-registry-metadata prettier projen semver spdx-license-list streamcount streamx tar-stream ts-node typescript uuid yaml" }, { "exec": "npx projen" diff --git a/.projenrc.ts b/.projenrc.ts index 9ea5ee6ee..1237c0a5b 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -47,6 +47,7 @@ const project = new CdklabsConstructLibrary({ '@types/tough-cookie', '@types/uuid', cdkCli, + '@aws-sdk/client-cloudwatch', '@aws-sdk/client-codeartifact', '@aws-sdk/client-lambda', '@aws-sdk/client-s3', diff --git a/package.json b/package.json index 38f241b45..cc1941b66 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "@aws-cdk/aws-servicecatalogappregistry-alpha": "2.120.0-alpha.0", "@aws-cdk/integ-runner": "2.120.0-alpha.0", "@aws-cdk/integ-tests-alpha": "2.120.0-alpha.0", + "@aws-sdk/client-cloudwatch": "^3.650.0", "@aws-sdk/client-codeartifact": "^3.650.0", "@aws-sdk/client-ecs": "^3.650.0", "@aws-sdk/client-lambda": "^3.650.0", diff --git a/src/__tests__/__snapshots__/construct-hub.test.ts.snap b/src/__tests__/__snapshots__/construct-hub.test.ts.snap index d54eee582..d0ed10181 100644 --- a/src/__tests__/__snapshots__/construct-hub.test.ts.snap +++ b/src/__tests__/__snapshots__/construct-hub.test.ts.snap @@ -12462,7 +12462,7 @@ function handler(event) { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "0a3aa2907d0245d3c25a4929bfd034a9fa84b893ca2209de39684e757f4cc170.zip", + "S3Key": "47bb9ddd0b4fa8279b3fcf81236a3bccc1ca3cabdf7b63ab0ddbaa6b13d793a1.zip", }, "Description": "[ConstructHub/SQSDLQWidget] Is a custom CloudWatch widget handler", "Handler": "index.handler", @@ -25461,7 +25461,7 @@ function handler(event) { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "0a3aa2907d0245d3c25a4929bfd034a9fa84b893ca2209de39684e757f4cc170.zip", + "S3Key": "47bb9ddd0b4fa8279b3fcf81236a3bccc1ca3cabdf7b63ab0ddbaa6b13d793a1.zip", }, "Description": "[ConstructHub/SQSDLQWidget] Is a custom CloudWatch widget handler", "Handler": "index.handler", @@ -38032,7 +38032,7 @@ function handler(event) { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "0a3aa2907d0245d3c25a4929bfd034a9fa84b893ca2209de39684e757f4cc170.zip", + "S3Key": "47bb9ddd0b4fa8279b3fcf81236a3bccc1ca3cabdf7b63ab0ddbaa6b13d793a1.zip", }, "Description": "[ConstructHub/SQSDLQWidget] Is a custom CloudWatch widget handler", "Handler": "index.handler", @@ -50989,7 +50989,7 @@ function handler(event) { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "0a3aa2907d0245d3c25a4929bfd034a9fa84b893ca2209de39684e757f4cc170.zip", + "S3Key": "47bb9ddd0b4fa8279b3fcf81236a3bccc1ca3cabdf7b63ab0ddbaa6b13d793a1.zip", }, "Description": "[ConstructHub/SQSDLQWidget] Is a custom CloudWatch widget handler", "Handler": "index.handler", @@ -66846,7 +66846,7 @@ function handler(event) { "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", }, - "S3Key": "0a3aa2907d0245d3c25a4929bfd034a9fa84b893ca2209de39684e757f4cc170.zip", + "S3Key": "47bb9ddd0b4fa8279b3fcf81236a3bccc1ca3cabdf7b63ab0ddbaa6b13d793a1.zip", }, "Description": "[ConstructHub/SQSDLQWidget] Is a custom CloudWatch widget handler", "Handler": "index.handler", diff --git a/src/__tests__/backend/overview-dashboard/sqs-dlq-stats-widget-function.lambda.test.ts b/src/__tests__/backend/overview-dashboard/sqs-dlq-stats-widget-function.lambda.test.ts new file mode 100644 index 000000000..ef442a881 --- /dev/null +++ b/src/__tests__/backend/overview-dashboard/sqs-dlq-stats-widget-function.lambda.test.ts @@ -0,0 +1,78 @@ +import { + CloudWatchClient, + GetMetricDataCommand, +} from '@aws-sdk/client-cloudwatch'; +import { mockClient } from 'aws-sdk-client-mock'; + +import { + Event, + handler, +} from '../../../overview-dashboard/sqs-dlq-stats-widget-function.lambda'; + +test('build stats page', async () => { + const cloudwatchMock = mockClient(CloudWatchClient); + + const event: Event = { + description: 'foo', + key: 'bar', + widgetContext: { + params: { + queues: { + MyQueue: { + queueName: 'MyQueue', + name: 'bar', + reDriveFunctionArn: + 'arn:aws:lambda:us-east-2:123456789012:function:my-function', + }, + }, + nonEmptyQueueMessage: 'MyQueue', + }, + accountId: 'XXXXXXXXXXXX', + dashboardName: 'MyDashboard', + domain: 'us-east-1', + height: 6, + period: 300, + title: 'SomeTitle', + width: 6, + widgetId: 'abc', + linkCharts: false, + locale: 'en-US', + timezone: { + label: 'UTC', + offsetISO: '+0', + offsetInMinutes: 0, + }, + isAutoPeriod: true, + theme: 'dark', + timeRange: { + mode: 'relative', + start: 0, + end: 0, + relativeStart: 0, + zoom: { + start: 0, + end: 0, + }, + }, + forms: { all: {} }, + }, + }; + + cloudwatchMock.on(GetMetricDataCommand).resolves({ + MetricDataResults: [ + { + Id: 'm0', + Values: [1, 2, 3], + }, + ], + }); + + const response = await handler(event); + + expect(response).toEqual(`
MyQueue
Queue Name | Visible Messages | Action |
---|---|---|
bar | 1 | Goto Queue ReDrive |