Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/hot-toys-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@notation/aws.iac": minor
"@notation/aws": minor
---

Support alternative runtimes
8 changes: 8 additions & 0 deletions examples/lambda-external/external/lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import json

def handler(event, context):
print("event", event)
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello, world!'})
}
7 changes: 6 additions & 1 deletion examples/lambda-external/infra/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { api, router } from "@notation/aws/api-gateway";
import { externalJsLambda, externalZipLambda } from "./lambda";
import {
externalJsLambda,
externalZipLambda,
externalPyLambda,
} from "./lambda";

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

helloRouter.get("/hello1", externalJsLambda);
helloRouter.get("/hello2", externalZipLambda);
helloRouter.get("/hello3", externalPyLambda);
10 changes: 10 additions & 0 deletions examples/lambda-external/infra/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ export const externalZipLambda = lambda({
path: "external/lambda.zip",
},
});

export const externalPyLambda = lambda({
id: "external-py",
handler: "handler",
code: {
type: "file",
path: "external/lambda.py",
},
runtime: "python3.12",
});
8 changes: 8 additions & 0 deletions packages/aws.iac/src/resources/lambda/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
Runtime: {
valueType: z.enum([
"dotnet6",
"dotnet8",
"dotnetcore1.0",
"dotnetcore2.0",
"dotnetcore2.1",
Expand All @@ -205,6 +206,7 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
"nodejs16.x",
"nodejs18.x",
"nodejs20.x",
"nodejs22.x",
"nodejs4.3",
"nodejs4.3-edge",
"nodejs6.10",
Expand All @@ -216,13 +218,15 @@ const lambdaFunctionSchema = lambdaFunction.defineSchema({
"python3.10",
"python3.11",
"python3.12",
"python3.13",
"python3.6",
"python3.7",
"python3.8",
"python3.9",
"ruby2.5",
"ruby2.7",
"ruby3.2",
"ruby3.3",
]),
propertyType: "param",
presence: "optional",
Expand Down Expand Up @@ -381,3 +385,7 @@ export const LambdaFunction = lambdaFunctionSchema
}));

export type LambdaFunctionInstance = InstanceType<typeof LambdaFunction>;

export type LambdaFunctionConfig = ConstructorParameters<
typeof LambdaFunction
>[0]["config"];
6 changes: 4 additions & 2 deletions packages/aws/src/lambda/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ type LambdaConfig = {
type: "file" | "zip";
path: string;
};
runtime?: aws.lambda.LambdaFunctionConfig["Runtime"];
};

export const lambda = (config: LambdaConfig) => {
export const lambda = (config: LambdaConfig): aws.AwsResourceGroup => {
const functionGroup = new aws.AwsResourceGroup("Lambda", { config });
const filePath = config.code.path;

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

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

const lambdaResource = functionGroup.add(
new aws.lambda.LambdaFunction({
id: lambdaId,
config: {
FunctionName: lambdaId,
Handler: `${fileName}.${config.handler}`,
Runtime: "nodejs18.x",
Runtime: runtime,
// todo: make this configurable and remove it as a default
ReservedConcurrentExecutions: 1,
},
Expand Down