Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/infraDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import { Configuration } from './configuration.js';
import { AwsCredentials } from './awsCredentials.js';
import { getModuleDirname } from './getDirname.js';
import { Logger } from './logger.js';
import * as crypto from 'crypto';

let lambdaClient: LambdaClient | undefined;
let iamClient: IAMClient | undefined;

const inlinePolicyName = 'LambdaLiveDebuggerPolicy';
const layerName = 'LambdaLiveDebugger';
const lldWrapperPath = '/opt/lld-wrapper';
let layerDescription: string | undefined;

/**
* Policy document to attach to the Lambda role
Expand Down Expand Up @@ -118,7 +120,16 @@ async function findExistingLayerVersion() {
* @returns
*/
async function getLayerDescription() {
return `Lambda Live Debugger Layer version ${await getVersion()}`;
if (!layerDescription) {
layerDescription = `Lambda Live Debugger Layer version ${await getVersion()}`;
}

if ((await getVersion()) === '0.0.1') {
// add a random string to the description to make it unique
layerDescription = `Lambda Live Debugger Layer - development ${crypto.randomUUID()}`;
}

return layerDescription;
}

/**
Expand All @@ -131,20 +142,8 @@ async function deployLayer() {
// Check if the layer already exists
const existingLayer = await findExistingLayerVersion();
if (existingLayer && existingLayer.LayerVersionArn) {
// delete existing layer when developing
if ((await getVersion()) === '0.0.1') {
Logger.verbose(
'Deleting existing layer version, because it is a development mode.',
);
const deleteLayerVersionCommand = new DeleteLayerVersionCommand({
LayerName: layerName,
VersionNumber: existingLayer.Version,
});
await getLambdaClient().send(deleteLayerVersionCommand);
} else {
Logger.verbose(`${layerDescription} already deployed.`);
return existingLayer.LayerVersionArn;
}
Logger.verbose(`${layerDescription} already deployed.`);
return existingLayer.LayerVersionArn;
}

// check the ZIP
Expand Down
Loading