Skip to content

Commit 8d82625

Browse files
Merge pull request #56 from ServerlessLife/python-layer-versions
fix: Python layer versions
2 parents c3dc4f8 + dc0899c commit 8d82625

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/ServerlessSpy.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,6 @@ export class ServerlessSpy extends Construct {
414414
const layerKey = (r: lambda.Runtime, a: lambda.Architecture) =>
415415
`${r.toString()}_${a.name.toString()}`;
416416

417-
console.log('RUNTIME: ', runtime);
418-
console.log('ARCHITECTURE: ', architecture);
419-
420417
let layer = this.layerMap[layerKey(runtime, architecture)];
421418
let spyWrapperPath = '/opt/spy-wrapper';
422419

@@ -430,20 +427,26 @@ export class ServerlessSpy extends Construct {
430427
spyWrapperPath = '/opt/python/spy-wrapper';
431428
layer =
432429
layer ||
433-
new PythonLayerVersion(this, 'PythonExtension', {
434-
compatibleRuntimes: [runtime],
435-
compatibleArchitectures: [architecture],
436-
entry: location,
437-
bundling: {
438-
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY,
439-
// command: [
440-
// `cp ${path.join(
441-
// location.substring(0, location.lastIndexOf(path.sep)),
442-
// 'spy-wrapper/spy-wrapper'
443-
// )} /asset-output/python`,
444-
// ],
445-
},
446-
});
430+
new PythonLayerVersion(
431+
this,
432+
`PythonExtension${runtime.name
433+
.replace('python', '')
434+
.replace('.', '_')}`,
435+
{
436+
compatibleRuntimes: [runtime],
437+
compatibleArchitectures: [architecture],
438+
entry: location,
439+
bundling: {
440+
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY,
441+
// command: [
442+
// `cp ${path.join(
443+
// location.substring(0, location.lastIndexOf(path.sep)),
444+
// 'spy-wrapper/spy-wrapper'
445+
// )} /asset-output/python`,
446+
// ],
447+
},
448+
}
449+
);
447450
break;
448451
case lambda.Runtime.NODEJS_12_X.name:
449452
case lambda.Runtime.NODEJS_14_X.name:

test/cdk/src/pythonLambdaStack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class PythonLambdaStack extends Stack {
2323
const func3 = new lambda.Function(this, 'MyLambdaThatFails', {
2424
memorySize: 512,
2525
timeout: Duration.seconds(5),
26-
runtime: lambda.Runtime.PYTHON_3_9,
26+
runtime: lambda.Runtime.PYTHON_3_11, // use a different version
2727
handler: 'lambdaFail.handler',
2828
architecture: Architecture.X86_64,
2929
code: lambda.Code.fromAsset(path.join(__dirname, '../functions/python/')),

0 commit comments

Comments
 (0)