From e6e4a45c5f7116e298c83b4c7ece2ed18b12274e Mon Sep 17 00:00:00 2001 From: Victor Yan Date: Fri, 19 Jan 2024 13:55:38 -0500 Subject: [PATCH] Fix cannot find module 'aws-sdk' on custom config rule lambdas --- .../ec2-instance-profile-permissions.zip | Bin 1335 -> 1345 bytes .../config-rules/ec2-instance-profile.zip | Bin 987 -> 1007 bytes .../ec2-instance-profile-permissions/index.js | 34 +++++++++--------- .../src/ec2-instance-profile/index.js | 14 ++++---- .../src/ssm-patching-role-tags/index.js | 34 +++++++++--------- .../config-rules/ssm-patching-role-tags.zip | Bin 1261 -> 1299 bytes 6 files changed, 39 insertions(+), 43 deletions(-) diff --git a/reference-artifacts/config-rules/ec2-instance-profile-permissions.zip b/reference-artifacts/config-rules/ec2-instance-profile-permissions.zip index 237170a4fe751215a1bf43e94a8c938c9a73bb41..ed1502774f60fdcf5a172b7959b051460bd5a2e8 100644 GIT binary patch literal 1345 zcmV-H1-|-FO9KQH000080Gw_!SedsbOq&D%0QC?600;ma0BLSyWq2-Xb5&Fc00Ric zs$~eps%3R}3jhHG_yGU_1QY-O0Nq#JZz4Akf6rerMb+)1l1PUV(`bQm+r zbq}Vg9&JgS63tL-C^j3yBRIenNcv~WB=tL=$WEQB=x0w zYI3@3bLOLDCOVi-Z*PW!UvEeEv(bF=`)oLxqvB_8@W;I0zZu;1`!f+!?+a?sr$k7t zf;9q*sYEfN_B@1T%0mMhe7d!vplMB?bQhk_!2D2XA&AAwe;B4piw(@un8H#>2-h@x zWPAlv5wnm{1w?Ctrx9oY=pH2MLaOi}&!)&zqMRf?>r zxhr)fhCL;cY*d@4;+ASE6@2>!-t)n;F4+?NA4=^2i*rXf+K-C7efR)X372RpkHlO_ z0Q6dlou$V}N+Er3#Pk}o+i64zwnvbuo4+ztG$v9R(wnH?jMv!BZhNojnrgnLZSLFjon9F|7Or|#s!Sxlb4=EP z;Um&ylk_c7ud!%;({1BqND`zGHQL?M=zw#ftxOFADUNf|gZt-;t#+j>t=-v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bQQ^zA^dk9^L-T?fJHQDs|0r{B7}5mL{4u z=HCjF_O+Pq+O=)zw)RQiW(Due*Z=49Aj4?x{i}_OR;_#E(D3^w*TEm9)3df{6&?5# zlXoC~nUsM6nCTdnG=f-&tjP+=nrPWFz?+o~q>d2? N{eW~gFk3S)0071=!^i*t literal 987 zcmWIWW@Zs#-~hs}B^f~sQ1F+70VtxtkeQc~TA`O!92&yQz<&LuYr;(+2GOMz+zgB? zq7NO*Sk6>47j6wZm?vc@u=lg5@XAw7F6KdfA(jD$8nqfZR#bH?dQic>VN-T~u0D(F zpX%e;(^4A+LblF1V4R}~FRwR-!${OMK~i1d4x^c&R)1FH?mAy5u>2*L=IrOQWFLCFF_mpk zTpd;MxlyY1^FEb*3(hJmpQ(Fzmang~No3CPSE8xhdmMJzWIeO9ULj`l%zZ=Vir-Ug zG-sSLIUaY#O6B#VyftTqBh;U2ZrLn3%Yq{>7<#t{oL2L{{QrZl|Oi`P~s=;Bwwr0?Z0pQ5l}FFIxo7y-e_C) ztOIv8-sta67UzE}-@lo|_istR^wqgHU!DDKCHIB>@pGfVfPggXy)%2BbKHt`o9Lv> z%&p`5STusw)r&cc>)P6n)4yMCU8`<))G9vtz>S1+-*^PwLjuzNxCWlNt$QrPkn5k~ z-2)fbs<1y~i85lI=$gq(BwSQb`SYegdz0$Xv-@{` zIluId1^@*MvS$DQ diff --git a/reference-artifacts/config-rules/src/ec2-instance-profile-permissions/index.js b/reference-artifacts/config-rules/src/ec2-instance-profile-permissions/index.js index 2d4e26e12..351cde6de 100644 --- a/reference-artifacts/config-rules/src/ec2-instance-profile-permissions/index.js +++ b/reference-artifacts/config-rules/src/ec2-instance-profile-permissions/index.js @@ -1,7 +1,5 @@ -const AWS = require('aws-sdk'); -AWS.config.logger = console; - -const config = new AWS.ConfigService(); +const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service"); +const client = new ConfigServiceClient(); const APPLICABLE_RESOURCES = ['AWS::IAM::Role']; @@ -28,20 +26,20 @@ exports.handler = async function (event, context) { console.debug(`Evaluation`); console.debug(JSON.stringify(evaluation, null, 2)); - await config - .putEvaluations({ - ResultToken: event.resultToken, - Evaluations: [ - { - ComplianceResourceId: configurationItem.resourceId, - ComplianceResourceType: configurationItem.resourceType, - ComplianceType: evaluation.complianceType, - OrderingTimestamp: configurationItem.configurationItemCaptureTime, - Annotation: evaluation.annotation, - }, - ], - }) - .promise(); + const payload = { + ResultToken: event.resultToken, + Evaluations: [ + { + ComplianceResourceId: configurationItem.resourceId, + ComplianceResourceType: configurationItem.resourceType, + ComplianceType: evaluation.complianceType, + OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime), + Annotation: evaluation.annotation, + }, + ], + }; + const putEvaluationsCommand = new PutEvaluationsCommand(payload); + await client.send(putEvaluationsCommand); }; async function evaluateCompliance(props) { diff --git a/reference-artifacts/config-rules/src/ec2-instance-profile/index.js b/reference-artifacts/config-rules/src/ec2-instance-profile/index.js index 19557740b..2075d4b42 100644 --- a/reference-artifacts/config-rules/src/ec2-instance-profile/index.js +++ b/reference-artifacts/config-rules/src/ec2-instance-profile/index.js @@ -1,7 +1,5 @@ -const AWS = require('aws-sdk'); -AWS.config.logger = console; - -const config = new AWS.ConfigService(); +const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service"); +const client = new ConfigServiceClient(); const APPLICABLE_RESOURCES = ['AWS::EC2::Instance']; @@ -23,18 +21,20 @@ exports.handler = async function(event, context) { console.debug(`Evaluation`); console.debug(JSON.stringify(evaluation, null, 2)); - await config.putEvaluations({ + const payload = { ResultToken: event.resultToken, Evaluations: [ { ComplianceResourceId: configurationItem.resourceId, ComplianceResourceType: configurationItem.resourceType, ComplianceType: evaluation.complianceType, - OrderingTimestamp: configurationItem.configurationItemCaptureTime, + OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime), Annotation: evaluation.annotation, }, ], - }).promise(); + }; + const putEvaluationsCommand = new PutEvaluationsCommand(payload); + await client.send(putEvaluationsCommand); }; async function evaluateCompliance(props) { diff --git a/reference-artifacts/config-rules/src/ssm-patching-role-tags/index.js b/reference-artifacts/config-rules/src/ssm-patching-role-tags/index.js index 8c21046f6..efb271787 100644 --- a/reference-artifacts/config-rules/src/ssm-patching-role-tags/index.js +++ b/reference-artifacts/config-rules/src/ssm-patching-role-tags/index.js @@ -1,7 +1,5 @@ -const AWS = require('aws-sdk'); -AWS.config.logger = console; - -const config = new AWS.ConfigService(); +const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service"); +const client = new ConfigServiceClient(); const APPLICABLE_RESOURCES = ['AWS::IAM::Role']; @@ -29,20 +27,20 @@ exports.handler = async function (event, context) { console.debug(`Evaluation`); console.debug(JSON.stringify(evaluation, null, 2)); - await config - .putEvaluations({ - ResultToken: event.resultToken, - Evaluations: [ - { - ComplianceResourceId: configurationItem.resourceId, - ComplianceResourceType: configurationItem.resourceType, - ComplianceType: evaluation.complianceType, - OrderingTimestamp: configurationItem.configurationItemCaptureTime, - Annotation: evaluation.annotation, - }, - ], - }) - .promise(); + const payload = { + ResultToken: event.resultToken, + Evaluations: [ + { + ComplianceResourceId: configurationItem.resourceId, + ComplianceResourceType: configurationItem.resourceType, + ComplianceType: evaluation.complianceType, + OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime), + Annotation: evaluation.annotation, + }, + ], + }; + const putEvaluationsCommand = new PutEvaluationsCommand(payload); + await client.send(putEvaluationsCommand); }; async function evaluateCompliance(props) { diff --git a/reference-artifacts/config-rules/ssm-patching-role-tags.zip b/reference-artifacts/config-rules/ssm-patching-role-tags.zip index 85b4c2dec7d157a95f7a7f30a81bb82447f9192c..c85fe76415d6b72d5f079143f24f4d0d480e40c4 100644 GIT binary patch delta 1265 zcmV@6aWAK2mnHDGgz_K*T-!H004Fm000O88~|x=6o!m4F^!m4F;cnbgl1o!~}00a~O007lj+iv4F5Pi>AOpV1#MjaLCqXQRp9Y3Vq zIEm$=4~s?2mBzMUSyD;LiQ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