This commit is contained in:
parent
685cb99f1d
commit
d29715a00e
5 changed files with 13 additions and 5 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
// Although this function looks imperative, note that its job is to
|
// Although this function looks imperative, note that its job is to
|
||||||
// declaratively construct a build graph that will be executed by an external
|
// declaratively construct a build graph that will be executed by an external
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
|
||||||
|
|
||||||
pub const HandlerFn = *const fn (std.mem.Allocator, []const u8) anyerror![]const u8;
|
pub const HandlerFn = *const fn (std.mem.Allocator, []const u8) anyerror![]const u8;
|
||||||
|
|
||||||
|
|
@ -64,11 +63,11 @@ pub fn run(allocator: ?std.mem.Allocator, event_handler: HandlerFn) !void { // T
|
||||||
const event = ev.?;
|
const event = ev.?;
|
||||||
defer ev.?.deinit();
|
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;
|
event.reportError(@errorReturnTrace(), err, lambda_runtime_uri) catch @panic("Error reporting error");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
event.postResponse(lambda_runtime_uri, event_response) catch |err| {
|
event.postResponse(lambda_runtime_uri, event_response) catch |err| {
|
||||||
event.reportError(@errorReturnTrace(), err, lambda_runtime_uri) catch unreachable;
|
event.reportError(@errorReturnTrace(), err, lambda_runtime_uri) catch @panic("Error reporting error");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,7 @@ fn loadEnvFile(
|
||||||
defer file.close();
|
defer file.close();
|
||||||
|
|
||||||
// Read entire file (env files are typically small)
|
// Read entire file (env files are typically small)
|
||||||
|
// SAFETY: set on read
|
||||||
var read_buffer: [4096]u8 = undefined;
|
var read_buffer: [4096]u8 = undefined;
|
||||||
var file_reader = file.reader(&read_buffer);
|
var file_reader = file.reader(&read_buffer);
|
||||||
const content = file_reader.interface.allocRemaining(allocator, std.Io.Limit.limited(64 * 1024)) catch |err| {
|
const content = file_reader.interface.allocRemaining(allocator, std.Io.Limit.limited(64 * 1024)) catch |err| {
|
||||||
|
|
@ -244,6 +245,7 @@ fn deployFunction(deploy_opts: DeployOptions, options: RunOptions) !void {
|
||||||
// Read the zip file and encode as base64
|
// Read the zip file and encode as base64
|
||||||
const zip_file = try std.fs.cwd().openFile(deploy_opts.zip_file, .{});
|
const zip_file = try std.fs.cwd().openFile(deploy_opts.zip_file, .{});
|
||||||
defer zip_file.close();
|
defer zip_file.close();
|
||||||
|
// SAFETY: set on read
|
||||||
var read_buffer: [4096]u8 = undefined;
|
var read_buffer: [4096]u8 = undefined;
|
||||||
var file_reader = zip_file.reader(&read_buffer);
|
var file_reader = zip_file.reader(&read_buffer);
|
||||||
const zip_data = try file_reader.interface.allocRemaining(options.allocator, std.Io.Limit.limited(50 * 1024 * 1024));
|
const zip_data = try file_reader.interface.allocRemaining(options.allocator, std.Io.Limit.limited(50 * 1024 * 1024));
|
||||||
|
|
@ -278,7 +280,9 @@ fn deployFunction(deploy_opts: DeployOptions, options: RunOptions) !void {
|
||||||
std.log.info("Attempting to create function: {s}", .{deploy_opts.function_name});
|
std.log.info("Attempting to create function: {s}", .{deploy_opts.function_name});
|
||||||
|
|
||||||
var create_diagnostics = aws.Diagnostics{
|
var create_diagnostics = aws.Diagnostics{
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_status = undefined,
|
.response_status = undefined,
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_body = undefined,
|
.response_body = undefined,
|
||||||
.allocator = options.allocator,
|
.allocator = options.allocator,
|
||||||
};
|
};
|
||||||
|
|
@ -464,6 +468,7 @@ fn addPermission(
|
||||||
const services = aws.Services(.{.lambda}){};
|
const services = aws.Services(.{.lambda}){};
|
||||||
|
|
||||||
// Generate statement ID from principal: "alexa-appkit.amazon.com" -> "allow-alexa-appkit-amazon-com"
|
// Generate statement ID from principal: "alexa-appkit.amazon.com" -> "allow-alexa-appkit-amazon-com"
|
||||||
|
// SAFETY: set on write
|
||||||
var statement_id_buf: [128]u8 = undefined;
|
var statement_id_buf: [128]u8 = undefined;
|
||||||
var statement_id_len: usize = 0;
|
var statement_id_len: usize = 0;
|
||||||
|
|
||||||
|
|
@ -484,7 +489,9 @@ fn addPermission(
|
||||||
std.log.info("Adding invoke permission for principal: {s}", .{principal});
|
std.log.info("Adding invoke permission for principal: {s}", .{principal});
|
||||||
|
|
||||||
var diagnostics = aws.Diagnostics{
|
var diagnostics = aws.Diagnostics{
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_status = undefined,
|
.response_status = undefined,
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_body = undefined,
|
.response_body = undefined,
|
||||||
.allocator = options.allocator,
|
.allocator = options.allocator,
|
||||||
};
|
};
|
||||||
|
|
@ -542,6 +549,7 @@ fn writeDeployOutput(
|
||||||
const file = try std.fs.cwd().createFile(output_path, .{});
|
const file = try std.fs.cwd().createFile(output_path, .{});
|
||||||
defer file.close();
|
defer file.close();
|
||||||
|
|
||||||
|
// SAFETY: set on write
|
||||||
var write_buffer: [4096]u8 = undefined;
|
var write_buffer: [4096]u8 = undefined;
|
||||||
var buffered = file.writer(&write_buffer);
|
var buffered = file.writer(&write_buffer);
|
||||||
const writer = &buffered.interface;
|
const writer = &buffered.interface;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,9 @@ pub fn getOrCreateRole(role_name: []const u8, options: RunOptions) ![]const u8 {
|
||||||
const services = aws.Services(.{.iam}){};
|
const services = aws.Services(.{.iam}){};
|
||||||
|
|
||||||
var diagnostics = aws.Diagnostics{
|
var diagnostics = aws.Diagnostics{
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_status = undefined,
|
.response_status = undefined,
|
||||||
|
// SAFETY: set by sdk on error
|
||||||
.response_body = undefined,
|
.response_body = undefined,
|
||||||
.allocator = options.allocator,
|
.allocator = options.allocator,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ pub fn main() !u8 {
|
||||||
|
|
||||||
run(allocator, &stdout_writer.interface, &stderr_writer.interface) catch |err| {
|
run(allocator, &stdout_writer.interface, &stderr_writer.interface) catch |err| {
|
||||||
stderr_writer.interface.print("Error: {}\n", .{err}) catch {};
|
stderr_writer.interface.print("Error: {}\n", .{err}) catch {};
|
||||||
stderr_writer.interface.flush() catch {};
|
try stderr_writer.interface.flush();
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
try stderr_writer.interface.flush();
|
try stderr_writer.interface.flush();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue