Skip to content

Commit 5dcb935

Browse files
authored
Support all lambda runtimes (#23)
* Support alternative runtimes * Add changeset * Replace hard-coded type
1 parent 3d1b4bb commit 5dcb935

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

.changeset/hot-toys-fly.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@notation/aws.iac": minor
3+
"@notation/aws": minor
4+
---
5+
6+
Support alternative runtimes
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import json
2+
3+
def handler(event, context):
4+
print("event", event)
5+
return {
6+
'statusCode': 200,
7+
'body': json.dumps({'message': 'Hello, world!'})
8+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { api, router } from "@notation/aws/api-gateway";
2-
import { externalJsLambda, externalZipLambda } from "./lambda";
2+
import {
3+
externalJsLambda,
4+
externalZipLambda,
5+
externalPyLambda,
6+
} from "./lambda";
37

48
const helloApi = api({ name: "hello-api" });
59
const helloRouter = router(helloApi);
610

711
helloRouter.get("/hello1", externalJsLambda);
812
helloRouter.get("/hello2", externalZipLambda);
13+
helloRouter.get("/hello3", externalPyLambda);

examples/lambda-external/infra/lambda.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ export const externalZipLambda = lambda({
1717
path: "external/lambda.zip",
1818
},
1919
});
20+
21+
export const externalPyLambda = lambda({
22+
id: "external-py",
23+
handler: "handler",
24+
code: {
25+
type: "file",
26+
path: "external/lambda.py",
27+
},
28+
runtime: "python3.12",
29+
});

packages/aws.iac/src/resources/lambda/lambda.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
188188
Runtime: {
189189
valueType: z.enum([
190190
"dotnet6",
191+
"dotnet8",
191192
"dotnetcore1.0",
192193
"dotnetcore2.0",
193194
"dotnetcore2.1",
@@ -205,6 +206,7 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
205206
"nodejs16.x",
206207
"nodejs18.x",
207208
"nodejs20.x",
209+
"nodejs22.x",
208210
"nodejs4.3",
209211
"nodejs4.3-edge",
210212
"nodejs6.10",
@@ -216,13 +218,15 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
216218
"python3.10",
217219
"python3.11",
218220
"python3.12",
221+
"python3.13",
219222
"python3.6",
220223
"python3.7",
221224
"python3.8",
222225
"python3.9",
223226
"ruby2.5",
224227
"ruby2.7",
225228
"ruby3.2",
229+
"ruby3.3",
226230
]),
227231
propertyType: "param",
228232
presence: "optional",
@@ -381,3 +385,7 @@ export const LambdaFunction = lambdaFunctionSchema
381385
}));
382386

383387
export type LambdaFunctionInstance = InstanceType<typeof LambdaFunction>;
388+
389+
export type LambdaFunctionConfig = ConstructorParameters<
390+
typeof LambdaFunction
391+
>[0]["config"];

packages/aws/src/lambda/lambda.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ type LambdaConfig = {
1010
type: "file" | "zip";
1111
path: string;
1212
};
13+
runtime?: aws.lambda.LambdaFunctionConfig["Runtime"];
1314
};
1415

15-
export const lambda = (config: LambdaConfig) => {
16+
export const lambda = (config: LambdaConfig): aws.AwsResourceGroup => {
1617
const functionGroup = new aws.AwsResourceGroup("Lambda", { config });
1718
const filePath = config.code.path;
1819

@@ -63,14 +64,15 @@ export const lambda = (config: LambdaConfig) => {
6364
);
6465

6566
const fileName = path.parse(filePath).name;
67+
const runtime = config.runtime || "nodejs22.x";
6668

6769
const lambdaResource = functionGroup.add(
6870
new aws.lambda.LambdaFunction({
6971
id: lambdaId,
7072
config: {
7173
FunctionName: lambdaId,
7274
Handler: `${fileName}.${config.handler}`,
73-
Runtime: "nodejs18.x",
75+
Runtime: runtime,
7476
// todo: make this configurable and remove it as a default
7577
ReservedConcurrentExecutions: 1,
7678
},

0 commit comments

Comments
 (0)