Skip to content

Commit

Permalink
Refactor AWS SDK usage and update Lambda permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tampueroc committed Apr 17, 2024
1 parent 03854a6 commit c8974c1
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions 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');

Expand Down Expand Up @@ -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 &&
Expand All @@ -136,5 +123,5 @@ module.exports = {
getLambdaArn,
handlerWrapper,
wait,
awsRequest,
awsRequest: retryableAwsCall,
};

0 comments on commit c8974c1

Please sign in to comment.