Skip to content

Commit

Permalink
Skip handling of container image lambda functions
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpharvey committed Jan 26, 2024
1 parent 443c298 commit cf9e13a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface FunctionProperties {
TracingConfig?: { [key: string]: string };
FunctionName?: string;
Architectures?: [string];
PackageType?: string;
}

export const handler = async (event: InputEvent, _: any) => {
Expand Down
6 changes: 6 additions & 0 deletions serverless/src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export function findLambdas(resources: Resources, templateParameterValues: Param
}

const properties: FunctionProperties = resource.Properties;

if (properties.PackageType == "Image") {
log.debug(`Resource ${key} is an image based Lambda function, skipping...`);
return;
}

const runtime = useOrRef(properties.Runtime, templateParameterValues);
const architecture = useOrRef(properties.Architectures?.[0], templateParameterValues) ?? "x86_64";

Expand Down
14 changes: 13 additions & 1 deletion serverless/test/layer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
getNewLayers,
} from "../src/layer";

function mockFunctionResource(runtime: string | { Ref: string }, architectures?: string[]) {
function mockFunctionResource(runtime: string | { Ref: string }, architectures?: string[], packageType?: string) {
return {
Type: "AWS::Lambda::Function",
Properties: {
Handler: "app.handler",
Role: "role-arn",
Runtime: runtime,
Architectures: architectures,
...(packageType && { PackageType: packageType }), // set PackageType property if available
},
};
}
Expand Down Expand Up @@ -100,6 +101,17 @@ describe("findLambdas", () => {
}),
]);
});

it("skips lambdas that are image based", () => {
const resources = {
Python39Function: mockFunctionResource("python3.9", ["x86_64"]),
Python39ImageFunction: mockFunctionResource("python3.9", ["x86_64"], "Image"),
};
const lambdas = findLambdas(resources, {});
expect(lambdas).toEqual([
mockLambdaFunction("Python39Function", "python3.9", RuntimeType.PYTHON, "x86_64", ArchitectureType.x86_64),
]);
});
});

describe("applyLayers", () => {
Expand Down

0 comments on commit cf9e13a

Please sign in to comment.