From c8974c1ca2ca02b2543f762270065a730e5386f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Ampuero?= Date: Wed, 17 Apr 2024 11:34:16 -0400 Subject: [PATCH] Refactor AWS SDK usage and update Lambda permissions --- .../aws/customResources/resources/utils.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/plugins/aws/customResources/resources/utils.js b/lib/plugins/aws/customResources/resources/utils.js index 2a3d4dc9b87..810c0a6f945 100644 --- a/lib/plugins/aws/customResources/resources/utils.js +++ b/lib/plugins/aws/customResources/resources/utils.js @@ -1,6 +1,5 @@ 'use strict'; -const AWS = require('aws-sdk'); const https = require('https'); const url = require('url'); @@ -97,23 +96,11 @@ const MAX_AWS_REQUEST_TRY = (() => { return userValue >= 0 ? userValue : DEFAULT_MAX_AWS_REQUEST_TRY; })(); -const getServiceInstance = (nameInput) => { - let name; - let params = {}; - if (typeof nameInput === 'string') { - name = nameInput; - } else { - name = nameInput.name; - params = nameInput.params; - } - return new AWS[name](params); -}; +async function retryableAwsCall(awsApiFunc) { -async function awsRequest(service, method, ...args) { - const serviceInstance = getServiceInstance(service); const callAws = async (requestTry) => { try { - return await serviceInstance[method](...args).promise(); + return await awsApiFunc(); } catch (error) { if ( requestTry < MAX_AWS_REQUEST_TRY && @@ -136,5 +123,5 @@ module.exports = { getLambdaArn, handlerWrapper, wait, - awsRequest, + awsRequest: retryableAwsCall, };