Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement CdkHandler for runtime version enforcement of Lambda handlers #27999

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
cc1ab88
initial work on handler framework
colifran Nov 14, 2023
c8510d2
latest runtime
colifran Nov 15, 2023
34b00c0
added code to determine latest runtime and added a way to check for d…
colifran Nov 15, 2023
e1f3df8
refactor
colifran Nov 15, 2023
34755a3
file name
colifran Nov 15, 2023
64480b8
file path
colifran Nov 15, 2023
d11caf3
refactor
colifran Nov 15, 2023
f40f232
refactor
colifran Nov 15, 2023
5c4c47c
refactor
colifran Nov 15, 2023
1fbe2c9
naming
colifran Nov 15, 2023
01147e8
refactored and stopped using semver for version compare
colifran Nov 16, 2023
7d738ee
export version compare
colifran Nov 16, 2023
765e854
base class
colifran Nov 16, 2023
a1929f5
runtime determiner utility class
colifran Nov 16, 2023
f7f8ff7
private constructor
colifran Nov 16, 2023
98a88c5
refactor of runtime determiner
colifran Nov 16, 2023
8650123
error messages
colifran Nov 16, 2023
3b8f205
testing and docstrings
colifran Nov 16, 2023
ec18a1c
added isDeprecated flag to deprecated runtimes and added more tests
colifran Nov 16, 2023
193c8b9
unit tests
colifran Nov 16, 2023
4c55149
update unit test
colifran Nov 16, 2023
cc09759
singleton unit tests and docstrings
colifran Nov 16, 2023
7bdb2f9
singleton unit tests
colifran Nov 16, 2023
e86afa5
added some deprecated runtime unit tests
colifran Nov 16, 2023
cd196b7
Merge branch 'main' into colifran/cdk-vended-handler-framework
colifran Nov 20, 2023
e23503f
remove exports from index
colifran Nov 17, 2023
0446133
update cdk code to cdk handler and add handler as a property
colifran Nov 20, 2023
7bc5738
unit tests
colifran Nov 20, 2023
04d5de8
renamed cdk-code.test to cdk-handler.test
colifran Nov 20, 2023
fea5616
update index
colifran Nov 20, 2023
39c4f3e
runtime unit tests
colifran Nov 20, 2023
72daf6a
cdk function integ test
colifran Nov 20, 2023
9ef7f31
reference path for types
colifran Nov 20, 2023
2eb901a
updated replica provider with new framework and changed integ test st…
colifran Nov 20, 2023
b144ff5
global snaps
colifran Nov 20, 2023
e61ff82
global replicas provisioned snaps
colifran Nov 20, 2023
cc52bdf
updated receipt to use cdk handler and cdk singleton function
colifran Nov 20, 2023
6fa5f4a
receipt snaps
colifran Nov 20, 2023
ac37074
refactored runtime determiner
colifran Nov 21, 2023
8c6c0ac
refactored runtime determiner and moved handler framework into its ow…
colifran Nov 21, 2023
8febdf1
renamed handler property to entrypoint
colifran Nov 21, 2023
32439cf
refactored runtime determiner and added content to readme
colifran Nov 21, 2023
31e43ab
readme
colifran Nov 21, 2023
bd62d07
default runtime docstring
colifran Nov 21, 2023
50ea546
Merge branch 'main' into colifran/cdk-vended-handler-framework
colifran Nov 27, 2023
a0c5d87
Merge branch 'main' into colifran/cdk-vended-handler-framework
colifran Nov 28, 2023
b1ec4d3
added initial code for CdkCustomResourceProvider
colifran Nov 27, 2023
abbf10a
custom resource provider base class
colifran Nov 28, 2023
d45a76c
cdk custom resource provider
colifran Nov 28, 2023
a5fd5b5
options interface
colifran Nov 28, 2023
8178135
reverted changes in edge function
colifran Nov 28, 2023
2ea9e37
refactored custom resource provider
colifran Nov 28, 2023
f0a4b61
wip
colifran Nov 28, 2023
0098580
wip
colifran Nov 28, 2023
490eda1
CdkCustomResourceProvider
colifran Nov 28, 2023
7f93955
refactored cdk handler, cdk function, and cdk singleton function. com…
colifran Nov 28, 2023
98601bf
cdk-handler tests
colifran Nov 28, 2023
fe7bd42
unit tests for cdk custom resource provider
colifran Nov 29, 2023
4ecd18e
merge conflicts
colifran Nov 29, 2023
fdaee2c
removed commented out code from edge function
colifran Nov 29, 2023
0b46310
updated aws custom resource provider and reverted changes in integ tests
colifran Nov 29, 2023
cd27fac
global replicas provisioned snaps
colifran Nov 29, 2023
4be3621
global snapsw
colifran Nov 29, 2023
428ae6e
snaps
colifran Nov 30, 2023
81b7796
handler path
colifran Nov 30, 2023
a68a854
custom resource props format
colifran Nov 30, 2023
ffa888d
refactor deprecated runtimes unit tests to use test.each
colifran Nov 30, 2023
fc02c0b
fixed cdk handler unit tests
colifran Nov 30, 2023
6b8542d
fixed cdk custom resource provider unit tests
colifran Nov 30, 2023
9ee148c
update aws custom resource to use nodejs18
colifran Nov 30, 2023
4856943
use code from asset in cdk handler
colifran Nov 30, 2023
3fa4aac
moved all framework files under handler-framework module
colifran Nov 30, 2023
7048170
readme
colifran Nov 30, 2023
437842f
mock provider
colifran Nov 30, 2023
8dff028
doc string
colifran Nov 30, 2023
d347d81
Merge branch 'main' into colifran/cdk-vended-handler-framework
colifran Dec 4, 2023
3d41daf
condensed framework PR to be only cdk handler and runtime determiner
colifran Dec 4, 2023
94b35e4
reverted changes in providers
colifran Dec 4, 2023
9382c59
reverted change to props in edge function
colifran Dec 4, 2023
cd8d58b
remove default entrypoint in constructor
colifran Dec 4, 2023
4f4d832
removed random characters at bottom of readme
colifran Dec 4, 2023
a4130a2
formatting
colifran Dec 4, 2023
efdef2e
removed unneeded props and attributes
colifran Dec 7, 2023
d7a23d1
code directory property
colifran Dec 7, 2023
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
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export interface LambdaRuntimeProps {
* @default false
*/
readonly supportsSnapStart?: boolean;

/**
* Whether this runtime is deprecated.
* @default false
*/
readonly isDeprecated?: boolean;
}

export enum RuntimeFamily {
Expand Down Expand Up @@ -324,11 +330,17 @@ export class Runtime {
*/
public readonly isVariable: boolean;

/**
*
*/
public readonly isDeprecated: boolean;

constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = {}) {
this.name = name;
this.supportsInlineCode = !!props.supportsInlineCode;
this.family = family;
this.isVariable = !!props.isVariable;
this.isDeprecated = props.isDeprecated ?? false;

const imageName = props.bundlingDockerImage ?? `public.ecr.aws/sam/build-${name}`;
this.bundlingDockerImage = DockerImage.fromRegistry(imageName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as semver from 'semver';
import { Construct } from 'constructs';
import { Function, FunctionOptions, Runtime } from '../../../aws-lambda';
import { CdkHandler } from './cdk-handler';
import { Lazy } from '../../../core';

/**
*
*/
export interface CdkFunctionProps extends FunctionOptions {
/**
*
*/
readonly cdkHandler: CdkHandler,
}

export class CdkFunction extends Function {
private static readonly DEFAULT_RUNTIME = Runtime.NODEJS_LATEST;

public constructor(scope: Construct, id: string, props: CdkFunctionProps) {
super(scope, id, {
runtime: Lazy.any(
{ produce: () => this.determineRuntime(props.cdkHandler.compatibleRuntimes) },
) as unknown as Runtime,
code: props.cdkHandler.code,
handler: props.cdkHandler.handler,
...props,
});
}

private determineRuntime(compatibleRuntimes: Runtime[]) {
const compatibleRuntimesLength = compatibleRuntimes.length;
if (compatibleRuntimesLength < 1) {
throw new Error('`cdkHandler` must specify at least 1 compatible runtime');
}

if (compatibleRuntimes.some(runtime => runtime.runtimeEquals(CdkFunction.DEFAULT_RUNTIME))) {
return CdkFunction.DEFAULT_RUNTIME;
}

const sliceStart = 'nodejs'.length;
let latestRuntime = compatibleRuntimes[0];
for (let idx = 1; idx < compatibleRuntimesLength; idx++) {
const runtime = compatibleRuntimes[idx];
if (semver.gte(runtime.name.slice(sliceStart), latestRuntime.name.slice(sliceStart))) {
latestRuntime = runtime;
}
}

if (latestRuntime.isDeprecated) {
throw new Error('Latest compatible runtime is deprecated');
}

return latestRuntime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Code, Runtime } from '../../../aws-lambda';

/**
*
*/
export interface CdkHandlerProps {
/**
*
*/
readonly compatibleRuntimes: Runtime[];

/**
*
*/
readonly handler: string;
}

export class CdkHandler {
/**
*
*/
public static fromAsset(path: string, props: CdkHandlerProps) {
return new CdkHandler(path, props);
}

/**
*
*/
public readonly code: Code;

/**
*
*/
public readonly handler: string;

/**
*
*/
public readonly compatibleRuntimes: Runtime[];

private constructor(path: string, props: CdkHandlerProps) {
this.code = Code.fromAsset(path);
this.handler = props.handler;
this.compatibleRuntimes = props.compatibleRuntimes;
}
}
Loading