From 44416b0f07e066ee984e0e19c7d4f75a7e0190b1 Mon Sep 17 00:00:00 2001 From: Jose Amoroso <142433457+jose-clickup@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:32:42 -0500 Subject: [PATCH] chore: refactor lib for single region deployment (#6) --- API.md | 25 -------- ...service-quotas-metric-publisher.monitor.ts | 57 ++++++++----------- src/service-quotas-metric-publisher.ts | 8 --- test/integ.service-quotas-metric-publisher.ts | 1 - .../HelperMonitorBaseline.assets.json | 10 ++-- .../HelperMonitorBaseline.template.json | 2 +- .../MonitorBaselineSevicesQuotas.assets.json | 10 ++-- ...MonitorBaselineSevicesQuotas.template.json | 5 +- .../index.js | 2 - .../index.js | 2 + .../index.js | 3 +- ...efaultTestDeployAssert946684A0.assets.json | 4 +- ...aultTestDeployAssert946684A0.template.json | 2 +- .../manifest.json | 12 +--- .../tree.json | 7 +-- ...ce-quotas-metric-publisher.monitor.test.ts | 10 +--- test/service-quotas-metric-publisher.test.ts | 1 - test/utils/get-service-quotas-metrics.ts | 1 - 18 files changed, 50 insertions(+), 112 deletions(-) delete mode 100644 test/integ.service-quotas-metric-publisher.ts.snapshot/asset.022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1/index.js create mode 100644 test/integ.service-quotas-metric-publisher.ts.snapshot/asset.1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee/index.js rename test/integ.service-quotas-metric-publisher.ts.snapshot/{asset.bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63 => asset.b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186}/index.js (99%) diff --git a/API.md b/API.md index faedb76..76395b7 100644 --- a/API.md +++ b/API.md @@ -141,7 +141,6 @@ Any object. | cwNamespace | string | *No description.* | | handler | aws-cdk-lib.aws_lambda_nodejs.NodejsFunction | *No description.* | | publishFrequency | number | *No description.* | -| regionsToMonitor | string[] | *No description.* | | rule | aws-cdk-lib.aws_events.Rule | *No description.* | | serviceQuotas | IServiceQuota[] | *No description.* | @@ -189,16 +188,6 @@ public readonly publishFrequency: number; --- -##### `regionsToMonitor`Required - -```typescript -public readonly regionsToMonitor: string[]; -``` - -- *Type:* string[] - ---- - ##### `rule`Required ```typescript @@ -239,7 +228,6 @@ const serviceQuotasMetricPublisherProps: ServiceQuotasMetricPublisherProps = { . | cloudwatchLogsRetention | aws-cdk-lib.aws_logs.RetentionDays | How long to retain logs published to CloudWatch logs. | | cwNamespace | string | The CloudWatch namespace to publish metrics to. | | publishFrequency | number | Time intervals that Lambda will be triggered to publish metric in CloudWatch. | -| regionsToMonitor | string[] | The list of regions to monitor the quotas. | | serviceQuotas | IServiceQuota[] | The list of service quotas to monitor. | --- @@ -283,19 +271,6 @@ Time intervals that Lambda will be triggered to publish metric in CloudWatch. --- -##### `regionsToMonitor`Optional - -```typescript -public readonly regionsToMonitor: string[]; -``` - -- *Type:* string[] -- *Default:* ['us-east-1'] - -The list of regions to monitor the quotas. - ---- - ##### `serviceQuotas`Optional ```typescript diff --git a/src/service-quotas-metric-publisher.monitor.ts b/src/service-quotas-metric-publisher.monitor.ts index 40cf506..fb5fd11 100644 --- a/src/service-quotas-metric-publisher.monitor.ts +++ b/src/service-quotas-metric-publisher.monitor.ts @@ -20,7 +20,6 @@ import { IServiceQuota } from './service-quotas-metric-publisher'; interface ServiceQuotaApplied extends IServiceQuota { quotaName: string | undefined; value: number | undefined; - region: string | undefined; } /** @@ -37,44 +36,35 @@ export const monitor = async () => { throw new Error('SERVICE_QUOTAS_LIST environment variable not set'); } - if (!process.env.REGIONS_TO_MONITOR) { - throw new Error('REGIONS_TO_MONITOR environment variable not set'); - } - const cwNamespace: string = process.env.CW_NAMESPACE; const serviceQuotas: IServiceQuota[] = JSON.parse(process.env.SERVICE_QUOTAS_LIST); - const regionsToMonitor: string[] = JSON.parse(process.env.REGIONS_TO_MONITOR); // Call the getServiceQuota API to get the information about the quota const servicesQuotasApplied: ServiceQuotaApplied[] = []; - for (const region of regionsToMonitor) { - console.log(`Getting service quotas for region ${region}`); - const servicequotas = new ServiceQuotasClient({ region }); - for (const serviceQuota of serviceQuotas) { - console.log(`Getting service quota for ${serviceQuota.serviceCode} - ${serviceQuota.quotaCode}`); - const params: GetServiceQuotaCommandInput = { - ServiceCode: serviceQuota.serviceCode, - QuotaCode: serviceQuota.quotaCode, - }; - const command = new GetServiceQuotaCommand(params); - const data = await servicequotas.send(command); - if (!data.Quota) { - console.error(`No quota found for ${serviceQuota.serviceCode} - ${serviceQuota.quotaCode}`); - continue; - } - console.log( - `Successfully called getServiceQuota for ${serviceQuota.serviceCode} - ${ - serviceQuota.quotaCode - }.\n Data: ${JSON.stringify(data)}`, - ); - servicesQuotasApplied.push({ - serviceCode: data.Quota?.ServiceCode as String, - quotaName: data.Quota?.QuotaName as String, - quotaCode: data.Quota?.QuotaCode as String, - value: data.Quota?.Value, - region: region, - }); + const servicequotas = new ServiceQuotasClient(); + for (const serviceQuota of serviceQuotas) { + console.log(`Getting service quota for ${serviceQuota.serviceCode} - ${serviceQuota.quotaCode}`); + const params: GetServiceQuotaCommandInput = { + ServiceCode: serviceQuota.serviceCode, + QuotaCode: serviceQuota.quotaCode, + }; + const command = new GetServiceQuotaCommand(params); + const data = await servicequotas.send(command); + if (!data.Quota || Object.keys(data.Quota).length === 0) { + console.error(`No quota found for ${serviceQuota.serviceCode} - ${serviceQuota.quotaCode}`); + continue; } + console.log( + `Successfully called getServiceQuota for ${serviceQuota.serviceCode} - ${ + serviceQuota.quotaCode + }.\n Data: ${JSON.stringify(data)}`, + ); + servicesQuotasApplied.push({ + serviceCode: data.Quota?.ServiceCode as String, + quotaName: data.Quota?.QuotaName as String, + quotaCode: data.Quota?.QuotaCode as String, + value: data.Quota?.Value, + }); } // Publish the metric data to CloudWatch const cloudwatch = new CloudWatchClient(); @@ -83,7 +73,6 @@ export const monitor = async () => { { Name: 'QuotaCode', Value: serviceQuota.quotaCode }, { Name: 'QuotaName', Value: serviceQuota.quotaName }, { Name: 'ServiceCode', Value: serviceQuota.serviceCode }, - { Name: 'AwsRegion', Value: serviceQuota.region }, ]; const metricData: MetricDatum[] = [ { diff --git a/src/service-quotas-metric-publisher.ts b/src/service-quotas-metric-publisher.ts index 994cd45..857a592 100644 --- a/src/service-quotas-metric-publisher.ts +++ b/src/service-quotas-metric-publisher.ts @@ -36,11 +36,6 @@ export interface ServiceQuotasMetricPublisherProps { * @default ServiceQuotas[] */ readonly serviceQuotas?: IServiceQuota[]; - /** - * The list of regions to monitor the quotas. - * @default ['us-east-1'] - */ - readonly regionsToMonitor?: string[]; } /** @@ -48,7 +43,6 @@ export interface ServiceQuotasMetricPublisherProps { */ export class ServiceQuotasMetricPublisher extends Construct { readonly publishFrequency: number; - readonly regionsToMonitor: string[]; readonly handler: aws_lambda_nodejs.NodejsFunction; readonly rule: aws_events.Rule; readonly cwNamespace: string; @@ -64,7 +58,6 @@ export class ServiceQuotasMetricPublisher extends Construct { constructor(scope: Construct, id: Namer, props: ServiceQuotasMetricPublisherProps) { super(scope, id.pascal); this.publishFrequency = props.publishFrequency ?? 1; - this.regionsToMonitor = props.regionsToMonitor ?? ['us-east-1']; this.serviceQuotas = props.serviceQuotas ?? []; this.cwNamespace = props.cwNamespace ?? 'AWS/ServiceQuotaLimit'; const myConstruct = this; @@ -105,7 +98,6 @@ export class ServiceQuotasMetricPublisher extends Construct { this.handler.addEnvironment('CW_NAMESPACE', props.cwNamespace ?? this.cwNamespace); this.handler.addEnvironment('SERVICE_QUOTAS_LIST', JSON.stringify(this.serviceQuotas)); - this.handler.addEnvironment('REGIONS_TO_MONITOR', JSON.stringify(props.regionsToMonitor ?? this.regionsToMonitor)); this.rule = new aws_events.Rule(this, 'rule', { schedule: aws_events.Schedule.rate(Duration.minutes(this.publishFrequency)), }); diff --git a/test/integ.service-quotas-metric-publisher.ts b/test/integ.service-quotas-metric-publisher.ts index 05fdcb6..df91980 100644 --- a/test/integ.service-quotas-metric-publisher.ts +++ b/test/integ.service-quotas-metric-publisher.ts @@ -15,7 +15,6 @@ export class BaselineStack extends Stack { super(scope, id.pascal, props); this.lambdaFunction = new ServiceQuotasMetricPublisher(this, id, { publishFrequency: 1, - regionsToMonitor: ['us-west-2'], cwNamespace: 'AWS/ServiceQuotaLimit', serviceQuotas: [ { diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.assets.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.assets.json index 5ea0aae..0edba07 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.assets.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.assets.json @@ -1,21 +1,21 @@ { "version": "34.0.0", "files": { - "bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63": { + "b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186": { "source": { - "path": "asset.bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63", + "path": "asset.b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186", "packaging": "zip" }, "destinations": { "425845004253-us-west-2": { "bucketName": "cdk-hnb659fds-assets-425845004253-us-west-2", - "objectKey": "bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63.zip", + "objectKey": "b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186.zip", "region": "us-west-2", "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-file-publishing-role-425845004253-us-west-2" } } }, - "aac3d47de5229cb9dfb516ae5d8b3fe42131eff66a86e195003d9297ec00ca58": { + "03c0679af00a26f3425b2d00c1ffb9c5ea048318e58a154fa62514470b891f9c": { "source": { "path": "HelperMonitorBaseline.template.json", "packaging": "file" @@ -23,7 +23,7 @@ "destinations": { "425845004253-us-west-2": { "bucketName": "cdk-hnb659fds-assets-425845004253-us-west-2", - "objectKey": "aac3d47de5229cb9dfb516ae5d8b3fe42131eff66a86e195003d9297ec00ca58.json", + "objectKey": "03c0679af00a26f3425b2d00c1ffb9c5ea048318e58a154fa62514470b891f9c.json", "region": "us-west-2", "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-file-publishing-role-425845004253-us-west-2" } diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.template.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.template.json index f6f3126..3bbc29b 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.template.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/HelperMonitorBaseline.template.json @@ -57,7 +57,7 @@ "Properties": { "Code": { "S3Bucket": "cdk-hnb659fds-assets-425845004253-us-west-2", - "S3Key": "bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63.zip" + "S3Key": "b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186.zip" }, "Environment": { "Variables": { diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.assets.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.assets.json index 8359c25..f572fac 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.assets.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.assets.json @@ -1,15 +1,15 @@ { "version": "34.0.0", "files": { - "022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1": { + "1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee": { "source": { - "path": "asset.022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1", + "path": "asset.1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee", "packaging": "zip" }, "destinations": { "425845004253-us-west-2": { "bucketName": "cdk-hnb659fds-assets-425845004253-us-west-2", - "objectKey": "022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1.zip", + "objectKey": "1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee.zip", "region": "us-west-2", "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-file-publishing-role-425845004253-us-west-2" } @@ -29,7 +29,7 @@ } } }, - "651ca547119600e3824c1d17e56a2c2fef0664b0b05a2744b30611f3df6fa524": { + "a0d393c8bae6105b34d2d9b8ed4d015ed1b6f5deb7fc769cf902b4cbc5664c10": { "source": { "path": "MonitorBaselineSevicesQuotas.template.json", "packaging": "file" @@ -37,7 +37,7 @@ "destinations": { "425845004253-us-west-2": { "bucketName": "cdk-hnb659fds-assets-425845004253-us-west-2", - "objectKey": "651ca547119600e3824c1d17e56a2c2fef0664b0b05a2744b30611f3df6fa524.json", + "objectKey": "a0d393c8bae6105b34d2d9b8ed4d015ed1b6f5deb7fc769cf902b4cbc5664c10.json", "region": "us-west-2", "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-file-publishing-role-425845004253-us-west-2" } diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.template.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.template.json index b0cddd8..d27bae9 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.template.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/MonitorBaselineSevicesQuotas.template.json @@ -73,14 +73,13 @@ "Properties": { "Code": { "S3Bucket": "cdk-hnb659fds-assets-425845004253-us-west-2", - "S3Key": "022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1.zip" + "S3Key": "1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee.zip" }, "Environment": { "Variables": { "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1", "CW_NAMESPACE": "AWS/ServiceQuotaLimit", - "SERVICE_QUOTAS_LIST": "[{\"serviceCode\":\"elasticloadbalancing\",\"quotaCode\":\"L-7E6692B2\"}]", - "REGIONS_TO_MONITOR": "[\"us-west-2\"]" + "SERVICE_QUOTAS_LIST": "[{\"serviceCode\":\"elasticloadbalancing\",\"quotaCode\":\"L-7E6692B2\"}]" } }, "Handler": "index.monitor", diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1/index.js b/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1/index.js deleted file mode 100644 index 3d11829..0000000 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var N=(e,o)=>{for(var s in o)l(e,s,{get:o[s],enumerable:!0})},f=(e,o,s,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of C(o))!S.call(e,r)&&r!==s&&l(e,r,{get:()=>o[r],enumerable:!(n=p(o,r))||n.enumerable});return e};var Q=e=>f(l({},"__esModule",{value:!0}),e);var I={};N(I,{monitor:()=>g});module.exports=Q(I);var c=require("@aws-sdk/client-cloudwatch"),u=require("@aws-sdk/client-service-quotas"),g=async()=>{try{if(!process.env.CW_NAMESPACE)throw new Error("CW_NAMESPACE environment variable not set");if(!process.env.SERVICE_QUOTAS_LIST)throw new Error("SERVICE_QUOTAS_LIST environment variable not set");if(!process.env.REGIONS_TO_MONITOR)throw new Error("REGIONS_TO_MONITOR environment variable not set");let e=process.env.CW_NAMESPACE,o=JSON.parse(process.env.SERVICE_QUOTAS_LIST),s=JSON.parse(process.env.REGIONS_TO_MONITOR),n=[];for(let a of s){console.log(`Getting service quotas for region ${a}`);let v=new u.ServiceQuotasClient({region:a});for(let t of o){console.log(`Getting service quota for ${t.serviceCode} - ${t.quotaCode}`);let m={ServiceCode:t.serviceCode,QuotaCode:t.quotaCode},d=new u.GetServiceQuotaCommand(m),i=await v.send(d);console.log(`Successfully called getServiceQuota for ${t.serviceCode} - ${t.quotaCode}. - Data: ${JSON.stringify(i)}`),n.push({serviceCode:t.serviceCode,quotaCode:t.quotaCode,quotaName:i.Quota?.QuotaName,value:i.Quota?.Value,region:a})}}let r=new c.CloudWatchClient;for(let a of n){let t=[{MetricName:"ServiceQuotasApplied",Dimensions:[{Name:"QuotaCode",Value:a.quotaCode},{Name:"QuotaName",Value:a.quotaName},{Name:"ServiceCode",Value:a.serviceCode},{Name:"AwsRegion",Value:a.region}],Unit:"Count",Value:a.value}],m={Namespace:e,MetricData:t},d=new c.PutMetricDataCommand(m),i=await r.send(d);console.log(`Successfully pushed metric data to namespace ${e} - ${JSON.stringify(i)}`)}return n.length===0?console.log("No results to publish"):console.log("Successfully pushed metric data"),{servicesQuotasApplied:n}}catch(e){throw console.error(e),e}};0&&(module.exports={monitor}); diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee/index.js b/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee/index.js new file mode 100644 index 0000000..fe313fa --- /dev/null +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee/index.js @@ -0,0 +1,2 @@ +"use strict";var m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var Q=(e,t)=>{for(var a in t)m(e,a,{get:t[a],enumerable:!0})},f=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of S(t))!p.call(e,n)&&n!==a&&m(e,n,{get:()=>t[n],enumerable:!(s=C(t,n))||s.enumerable});return e};var N=e=>f(m({},"__esModule",{value:!0}),e);var A={};Q(A,{monitor:()=>g});module.exports=N(A);var c=require("@aws-sdk/client-cloudwatch"),i=require("@aws-sdk/client-service-quotas"),g=async()=>{try{if(!process.env.CW_NAMESPACE)throw new Error("CW_NAMESPACE environment variable not set");if(!process.env.SERVICE_QUOTAS_LIST)throw new Error("SERVICE_QUOTAS_LIST environment variable not set");let e=process.env.CW_NAMESPACE,t=JSON.parse(process.env.SERVICE_QUOTAS_LIST),a=[],s=new i.ServiceQuotasClient;for(let o of t){console.log(`Getting service quota for ${o.serviceCode} - ${o.quotaCode}`);let d={ServiceCode:o.serviceCode,QuotaCode:o.quotaCode},u=new i.GetServiceQuotaCommand(d),r=await s.send(u);if(!r.Quota||Object.keys(r.Quota).length===0){console.error(`No quota found for ${o.serviceCode} - ${o.quotaCode}`);continue}console.log(`Successfully called getServiceQuota for ${o.serviceCode} - ${o.quotaCode}. + Data: ${JSON.stringify(r)}`),a.push({serviceCode:r.Quota?.ServiceCode,quotaName:r.Quota?.QuotaName,quotaCode:r.Quota?.QuotaCode,value:r.Quota?.Value})}let n=new c.CloudWatchClient;for(let o of a){let u=[{MetricName:"ServiceQuotasApplied",Dimensions:[{Name:"QuotaCode",Value:o.quotaCode},{Name:"QuotaName",Value:o.quotaName},{Name:"ServiceCode",Value:o.serviceCode}],Unit:"Count",Value:o.value}],r={Namespace:e,MetricData:u},l=new c.PutMetricDataCommand(r),v=await n.send(l);console.log(`Successfully pushed metric data to namespace ${e} - ${JSON.stringify(v)}`)}return a.length===0?console.log("No results to publish"):console.log("Successfully pushed metric data"),{servicesQuotasApplied:a}}catch(e){throw console.error(e),e}};0&&(module.exports={monitor}); diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63/index.js b/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186/index.js similarity index 99% rename from test/integ.service-quotas-metric-publisher.ts.snapshot/asset.bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63/index.js rename to test/integ.service-quotas-metric-publisher.ts.snapshot/asset.b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186/index.js index df41803..fa21feb 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63/index.js +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/asset.b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186/index.js @@ -28752,8 +28752,7 @@ exports.handler = async () => { Dimensions: [ { Name: "QuotaCode", Value: "L-7E6692B2" }, { Name: "QuotaName", Value: "Targets per Application Load Balancer" }, - { Name: "ServiceCode", Value: "elasticloadbalancing" }, - { Name: "AwsRegion", Value: "us-west-2" } + { Name: "ServiceCode", Value: "elasticloadbalancing" } ] }, Period: 60, diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.assets.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.assets.json index e7218a6..425c24f 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.assets.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.assets.json @@ -14,7 +14,7 @@ } } }, - "f25d15dfaccdf36c7e0c1efd2f7bd451f9a10403fb5d76028ba0b25f11636ada": { + "168b0e5dd9293011f12fc167ece44e961755d0b0505eb749f4e2a0dea0491ffb": { "source": { "path": "integDefaultTestDeployAssert946684A0.template.json", "packaging": "file" @@ -22,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "f25d15dfaccdf36c7e0c1efd2f7bd451f9a10403fb5d76028ba0b25f11636ada.json", + "objectKey": "168b0e5dd9293011f12fc167ece44e961755d0b0505eb749f4e2a0dea0491ffb.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.template.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.template.json index bb5f473..a6cd8cc 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.template.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/integDefaultTestDeployAssert946684A0.template.json @@ -20,7 +20,7 @@ "outputPaths": [ "Payload.body.message" ], - "salt": "1702184856324" + "salt": "1704386003296" }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/manifest.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/manifest.json index eede623..5cfa623 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/manifest.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-deploy-role-425845004253-us-west-2", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-cfn-exec-role-425845004253-us-west-2", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-425845004253-us-west-2/651ca547119600e3824c1d17e56a2c2fef0664b0b05a2744b30611f3df6fa524.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-425845004253-us-west-2/a0d393c8bae6105b34d2d9b8ed4d015ed1b6f5deb7fc769cf902b4cbc5664c10.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -34,12 +34,6 @@ "MonitorBaselineSevicesQuotas.assets" ], "metadata": { - "/MonitorBaselineSevicesQuotas/MonitorBaselineSevicesQuotas": [ - { - "type": "aws:cdk:warning", - "data": "When using NODEJS_LATEST the runtime version may change as new runtimes are released, this may affect the availability of packages shipped with the environment. Ensure that any external dependencies are available through layers or specify a specific runtime version. [ack: @aws-cdk/aws-lambda-nodejs:variableRuntimeExternals]" - } - ], "/MonitorBaselineSevicesQuotas/MonitorBaselineSevicesQuotas/monitor/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -126,7 +120,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-deploy-role-425845004253-us-west-2", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::425845004253:role/cdk-hnb659fds-cfn-exec-role-425845004253-us-west-2", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-425845004253-us-west-2/aac3d47de5229cb9dfb516ae5d8b3fe42131eff66a86e195003d9297ec00ca58.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-425845004253-us-west-2/03c0679af00a26f3425b2d00c1ffb9c5ea048318e58a154fa62514470b891f9c.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -192,7 +186,7 @@ "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}/f25d15dfaccdf36c7e0c1efd2f7bd451f9a10403fb5d76028ba0b25f11636ada.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/168b0e5dd9293011f12fc167ece44e961755d0b0505eb749f4e2a0dea0491ffb.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/test/integ.service-quotas-metric-publisher.ts.snapshot/tree.json b/test/integ.service-quotas-metric-publisher.ts.snapshot/tree.json index a05895e..40acbbd 100644 --- a/test/integ.service-quotas-metric-publisher.ts.snapshot/tree.json +++ b/test/integ.service-quotas-metric-publisher.ts.snapshot/tree.json @@ -162,14 +162,13 @@ "aws:cdk:cloudformation:props": { "code": { "s3Bucket": "cdk-hnb659fds-assets-425845004253-us-west-2", - "s3Key": "022bca39f4e853a1dd8e2da7a597acf779a4939f2377dbc56bb20da26bb9e3b1.zip" + "s3Key": "1a0598cc05b30d5f960a82f8e85e49a2525978dfe949e09bb5414f0d91c53cee.zip" }, "environment": { "variables": { "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1", "CW_NAMESPACE": "AWS/ServiceQuotaLimit", - "SERVICE_QUOTAS_LIST": "[{\"serviceCode\":\"elasticloadbalancing\",\"quotaCode\":\"L-7E6692B2\"}]", - "REGIONS_TO_MONITOR": "[\"us-west-2\"]" + "SERVICE_QUOTAS_LIST": "[{\"serviceCode\":\"elasticloadbalancing\",\"quotaCode\":\"L-7E6692B2\"}]" } }, "handler": "index.monitor", @@ -593,7 +592,7 @@ "aws:cdk:cloudformation:props": { "code": { "s3Bucket": "cdk-hnb659fds-assets-425845004253-us-west-2", - "s3Key": "bd4479eeabd60939d305de637c84482dd0f2cb69729428a7372da67784eb3c63.zip" + "s3Key": "b5ae93b59b14215a5db218f1bbf46b72944e9fa6d91538a1022fcf9c61910186.zip" }, "environment": { "variables": { diff --git a/test/service-quotas-metric-publisher.monitor.test.ts b/test/service-quotas-metric-publisher.monitor.test.ts index bb6d887..5a4880f 100644 --- a/test/service-quotas-metric-publisher.monitor.test.ts +++ b/test/service-quotas-metric-publisher.monitor.test.ts @@ -15,7 +15,6 @@ describe('monitor', () => { beforeEach(() => { process.env.CW_NAMESPACE = 'test-namespace'; process.env.SERVICE_QUOTAS_LIST = JSON.stringify([{ serviceCode: 's3', quotaCode: 'L-ABCD1234' }]); - process.env.REGIONS_TO_MONITOR = JSON.stringify(['us-west-2']); cloudWatchMock.on(PutMetricDataCommand).resolves({}); serviceQuotaMock .on(GetServiceQuotaCommand) @@ -31,7 +30,6 @@ describe('monitor', () => { quotaCode: 'L-ABCD1234', quotaName: 'Bucket Limit', value: 1000, - region: 'us-west-2', }, ], }); @@ -47,13 +45,9 @@ describe('monitor', () => { await expect(monitor()).rejects.toThrow('SERVICE_QUOTAS_LIST environment variable not set'); }); - it('should throw an error if REGIONS_TO_MONITOR environment variable is not set', async () => { - delete process.env.REGIONS_TO_MONITOR; - await expect(monitor()).rejects.toThrow('REGIONS_TO_MONITOR environment variable not set'); - }); - it('should log "No results to publish" if there are no results', async () => { - process.env.REGIONS_TO_MONITOR = JSON.stringify([]); + serviceQuotaMock.reset(); + serviceQuotaMock.on(GetServiceQuotaCommand).resolves({ Quota: {} }); const consoleSpy = jest.spyOn(console, 'log').mockImplementation(); const result = await monitor(); expect(result).toEqual({ servicesQuotasApplied: [] }); diff --git a/test/service-quotas-metric-publisher.test.ts b/test/service-quotas-metric-publisher.test.ts index ce912b2..5c3ab2a 100644 --- a/test/service-quotas-metric-publisher.test.ts +++ b/test/service-quotas-metric-publisher.test.ts @@ -17,7 +17,6 @@ let defaultServiceQuotasMetricPublisherProps: ServiceQuotasMetricPublisherProps quotaCode: 'L-7E6692B2', }, ], - regionsToMonitor: ['us-west-2'], }; let serviceQuotasMetricPublisher: ServiceQuotasMetricPublisher; diff --git a/test/utils/get-service-quotas-metrics.ts b/test/utils/get-service-quotas-metrics.ts index 343e50f..7b2d860 100644 --- a/test/utils/get-service-quotas-metrics.ts +++ b/test/utils/get-service-quotas-metrics.ts @@ -39,7 +39,6 @@ exports.handler = async () => { { Name: 'QuotaCode', Value: 'L-7E6692B2' }, { Name: 'QuotaName', Value: 'Targets per Application Load Balancer' }, { Name: 'ServiceCode', Value: 'elasticloadbalancing' }, - { Name: 'AwsRegion', Value: 'us-west-2' }, ], }, Period: 60,