Skip to content

Commit 9fd9f93

Browse files
authored
Merge pull request #65 from ServerlessLife/fix/64
fix: simplify naming of extensions and fix an issue that cause multiple architectures for node to cause the deploy to fail
2 parents 3eb723e + 7ca72ff commit 9fd9f93

File tree

2 files changed

+175
-68
lines changed

2 files changed

+175
-68
lines changed

src/ServerlessSpy.ts

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,13 @@ export class ServerlessSpy extends Construct {
420420
runtime: lambda.Runtime,
421421
architecture: lambda.Architecture
422422
): { layer: lambda.ILayerVersion; spyWrapperPath: string } | undefined {
423-
const layerKey = (r: lambda.Runtime, a: lambda.Architecture) =>
424-
`${r.toString()}_${a.name.toString()}`;
423+
const layerKey =
424+
`sspy_extension_${runtime.toString()}_${architecture.name.toString()}`.replace(
425+
/\./g,
426+
'_'
427+
);
425428

426-
let layer = this.layerMap[layerKey(runtime, architecture)];
429+
let layer = this.layerMap[layerKey];
427430
let spyWrapperPath = '/opt/spy-wrapper';
428431

429432
switch (runtime.name) {
@@ -432,30 +435,17 @@ export class ServerlessSpy extends Construct {
432435
case lambda.Runtime.PYTHON_3_10.name:
433436
case lambda.Runtime.PYTHON_3_11.name:
434437
case lambda.Runtime.PYTHON_3_12.name:
435-
const location = this.getLanguageExtensionAssetLocation('python');
436438
spyWrapperPath = '/opt/python/spy-wrapper';
437439
layer =
438440
layer ||
439-
new PythonLayerVersion(
440-
this,
441-
`PythonExtension${runtime.name
442-
.replace('python', '')
443-
.replace('.', '_')}`,
444-
{
445-
compatibleRuntimes: [runtime],
446-
compatibleArchitectures: [architecture],
447-
entry: location,
448-
bundling: {
449-
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY,
450-
// command: [
451-
// `cp ${path.join(
452-
// location.substring(0, location.lastIndexOf(path.sep)),
453-
// 'spy-wrapper/spy-wrapper'
454-
// )} /asset-output/python`,
455-
// ],
456-
},
457-
}
458-
);
441+
new PythonLayerVersion(this, layerKey, {
442+
compatibleRuntimes: [runtime],
443+
compatibleArchitectures: [architecture],
444+
entry: this.getLanguageExtensionAssetLocation('python'),
445+
bundling: {
446+
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY,
447+
},
448+
});
459449
break;
460450
case lambda.Runtime.NODEJS_12_X.name:
461451
case lambda.Runtime.NODEJS_14_X.name:
@@ -465,19 +455,8 @@ export class ServerlessSpy extends Construct {
465455
case lambda.Runtime.NODEJS_22_X.name:
466456
layer =
467457
layer ||
468-
new lambda.LayerVersion(this,
469-
`NodeExtension${runtime.name
470-
.replace('node', '')
471-
.replace('.', '_')}`,
472-
{
473-
compatibleRuntimes: [
474-
lambda.Runtime.NODEJS_12_X,
475-
lambda.Runtime.NODEJS_14_X,
476-
lambda.Runtime.NODEJS_16_X,
477-
lambda.Runtime.NODEJS_18_X,
478-
lambda.Runtime.NODEJS_20_X,
479-
lambda.Runtime.NODEJS_22_X,
480-
],
458+
new lambda.LayerVersion(this, layerKey, {
459+
compatibleRuntimes: [runtime],
481460
compatibleArchitectures: [architecture],
482461
code: lambda.Code.fromAsset(this.getExtensionAssetLocation()),
483462
});
@@ -487,9 +466,7 @@ export class ServerlessSpy extends Construct {
487466
return undefined;
488467
}
489468

490-
for (const compatibleRuntime of layer.compatibleRuntimes!) {
491-
this.layerMap[layerKey(compatibleRuntime, architecture)] = layer;
492-
}
469+
this.layerMap[layerKey] = layer;
493470
this.createdResourcesBySSpy.push(layer);
494471
return { layer, spyWrapperPath };
495472
}

test/cdk/test/__snapshots__/snsToSqs.test.ts.snap

Lines changed: 158 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)