2024-08-27 23:29:43 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const aws = @import("aws").aws;
|
2024-08-27 23:43:16 +00:00
|
|
|
const Region = @import("Region.zig");
|
2024-08-27 23:29:43 +00:00
|
|
|
const Invoke = @This();
|
|
|
|
|
|
|
|
step: std.Build.Step,
|
|
|
|
options: Options,
|
|
|
|
|
|
|
|
const base_id: std.Build.Step.Id = .custom;
|
|
|
|
|
|
|
|
pub const Options = struct {
|
|
|
|
/// Function name to invoke
|
|
|
|
name: []const u8,
|
|
|
|
|
|
|
|
/// Payload to send to the function
|
|
|
|
payload: []const u8,
|
|
|
|
|
|
|
|
/// Region for deployment
|
2024-08-27 23:43:16 +00:00
|
|
|
region: *Region,
|
2024-08-27 23:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pub fn create(owner: *std.Build, options: Options) *Invoke {
|
|
|
|
const name = owner.dupe(options.name);
|
|
|
|
const step_name = owner.fmt("{s} {s}{s}", .{
|
|
|
|
"aws lambda",
|
|
|
|
"invoke",
|
|
|
|
name,
|
|
|
|
});
|
|
|
|
const self = owner.allocator.create(Invoke) catch @panic("OOM");
|
|
|
|
self.* = .{
|
|
|
|
.step = std.Build.Step.init(.{
|
|
|
|
.id = base_id,
|
|
|
|
.name = step_name,
|
|
|
|
.owner = owner,
|
|
|
|
.makeFn = make,
|
|
|
|
}),
|
|
|
|
.options = options,
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: *std.Build.Step, node: std.Progress.Node) anyerror!void {
|
|
|
|
_ = node;
|
|
|
|
const self: *Invoke = @fieldParentPtr("step", step);
|
|
|
|
|
|
|
|
var client = aws.Client.init(self.step.owner.allocator, .{});
|
|
|
|
defer client.deinit();
|
|
|
|
const services = aws.Services(.{.lambda}){};
|
|
|
|
|
|
|
|
const options = aws.Options{
|
|
|
|
.client = client,
|
2024-08-27 23:43:16 +00:00
|
|
|
.region = try self.options.region.region(),
|
2024-08-27 23:29:43 +00:00
|
|
|
};
|
|
|
|
const call = try aws.Request(services.lambda.invoke).call(.{
|
|
|
|
.function_name = self.options.name,
|
|
|
|
.payload = self.options.payload,
|
|
|
|
.log_type = "Tail",
|
|
|
|
.invocation_type = "RequestResponse",
|
|
|
|
}, options);
|
|
|
|
defer call.deinit();
|
|
|
|
std.debug.print("{?s}\n", .{call.response.payload});
|
|
|
|
}
|