From e4195103a2b241b4fff770f83740948f57a5b40b Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 18 Sep 2023 08:27:45 -0700 Subject: [PATCH] aws lambda support --- src/lambda.zig | 4 ++-- src/lambdabuild.zig | 1 + src/universal_lambda.zig | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lambda.zig b/src/lambda.zig index 6d7e262..71d260c 100644 --- a/src/lambda.zig +++ b/src/lambda.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); -const HandlerFn = *const fn (std.mem.Allocator, []const u8) anyerror![]const u8; +const HandlerFn = @import("universal_lambda.zig").HandlerFn; const log = std.log.scoped(.lambda); @@ -66,7 +66,7 @@ pub fn run(allocator: ?std.mem.Allocator, event_handler: HandlerFn) !void { // T // reasonable to report back const event = ev.?; defer ev.?.deinit(); - const event_response = event_handler(req_allocator, event.event_data) catch |err| { + const event_response = event_handler(req_allocator, event.event_data, .{}) catch |err| { event.reportError(@errorReturnTrace(), err, lambda_runtime_uri) catch unreachable; continue; }; diff --git a/src/lambdabuild.zig b/src/lambdabuild.zig index 28312b8..65234a3 100644 --- a/src/lambdabuild.zig +++ b/src/lambdabuild.zig @@ -126,6 +126,7 @@ pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile) !void // The architectures option was introduced in 2.2.43 released 2021-10-01 // We want to use arm64 here because it is both faster and cheaper for most // Amazon Linux 2 is the only arm64 supported option + // TODO: This should determine compilation target and use x86_64 if needed const not_found = "aws lambda create-function --architectures arm64 --runtime provided.al2 --function-name {s} --zip-file fileb://{s} --handler not_applicable {s} && touch {s}"; const not_found_fmt = try std.fmt.allocPrint(b.allocator, not_found, .{ function_name, function_zip, iam_role, function_name_file }); defer b.allocator.free(not_found_fmt); diff --git a/src/universal_lambda.zig b/src/universal_lambda.zig index 2e964e6..cc9926d 100644 --- a/src/universal_lambda.zig +++ b/src/universal_lambda.zig @@ -1,7 +1,7 @@ const std = @import("std"); const build_options = @import("build_options"); -const HandlerFn = *const fn (std.mem.Allocator, []const u8, Context) anyerror![]const u8; +pub const HandlerFn = *const fn (std.mem.Allocator, []const u8, Context) anyerror![]const u8; const log = std.log.scoped(.universal_lambda); @@ -10,6 +10,7 @@ pub const Context = struct {}; const runFn = blk: { switch (build_options.build_type) { + .awslambda => break :blk @import("lambda.zig").run, .standalone_server => break :blk runStandaloneServer, .exe_run => break :blk runExe, else => @compileError("Provider interface for " ++ @tagName(build_options.build_type) ++ " has not yet been implemented"),