@bitblit/ratchet-aws
Version:
Common tools for use with AWS browser and node
40 lines • 1.57 kB
JavaScript
import { RequireRatchet } from '@bitblit/ratchet-common/lang/require-ratchet';
import { Logger } from '@bitblit/ratchet-common/logger/logger';
import { StringRatchet } from '@bitblit/ratchet-common/lang/string-ratchet';
import { GetFunctionCommand, ListFunctionsCommand, } from '@aws-sdk/client-lambda';
export class LambdaUsedImageFinder {
lambda;
constructor(lambda) {
this.lambda = lambda;
RequireRatchet.notNullOrUndefined(lambda, 'lambda');
}
async findUsedImageUris() {
const rval = new Set();
const fns = await this.fetchFunctions();
Logger.info('Found %d functions', fns.length);
for (const fn of fns) {
if (fn.PackageType === 'Image') {
const out = await this.lambda.send(new GetFunctionCommand({ FunctionName: fn.FunctionName }));
if (out.Code.RepositoryType === 'ECR' && out.Code.ImageUri) {
rval.add(out.Code.ImageUri);
}
}
else {
Logger.info('Skipping zip packaged function: %s', fn.FunctionName);
}
}
return Array.from(rval);
}
async fetchFunctions() {
let rval = [];
const cmd = {};
let resp = null;
do {
resp = await this.lambda.send(new ListFunctionsCommand(cmd));
rval = rval.concat(resp.Functions);
cmd.Marker = resp.NextMarker;
} while (StringRatchet.trimToNull(cmd.Marker));
return rval;
}
}
//# sourceMappingURL=lambda-used-image-finder.js.map