forked from lobo/lambda-zig
avoid iam ops if iam role file is in install
This commit is contained in:
parent
06842d05b6
commit
8d7d14c894
11
build.zig
11
build.zig
|
@ -61,7 +61,8 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
// directory to be used later
|
||||
const iam_role_name_file = b.getInstallPath(exe.install_step.?.dest_dir, "iam_role_name");
|
||||
iam_role = try std.fmt.allocPrint(b.allocator, "--role $(cat {s})", .{iam_role_name_file});
|
||||
|
||||
// defer b.allocator.free(iam_role);
|
||||
if (!fileExists(iam_role_name_file)) {
|
||||
// Role get/creation command
|
||||
const ifstatement_fmt =
|
||||
\\ if aws iam get-role --role-name lambda_basic_execution 2>&1 |grep -q NoSuchEntity; then aws iam create-role --output text --query Role.Arn --role-name lambda_basic_execution --assume-role-policy-document '{
|
||||
|
@ -84,6 +85,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
defer b.allocator.free(ifstatement);
|
||||
iam_step.dependOn(&b.addSystemCommand(&.{ "/bin/sh", "-c", ifstatement }).step);
|
||||
}
|
||||
}
|
||||
const function_name = b.option([]const u8, "function-name", "Function name for Lambda [zig-fn]") orelse "zig-fn";
|
||||
const ifstatement = "if aws lambda get-function --function-name {s} 2>&1 |grep -q ResourceNotFoundException; then echo not found > /dev/null; {s}; else echo found > /dev/null; {s}; fi";
|
||||
// The architectures option was introduced in 2.2.43 released 2021-10-01
|
||||
|
@ -117,6 +119,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
const run_script =
|
||||
\\ f=$(mktemp) && \
|
||||
\\ logs=$(aws lambda invoke \
|
||||
\\ --invocation-type RequestResponse \
|
||||
\\ --function-name {s} \
|
||||
\\ --payload $(echo '{s}'|base64) \
|
||||
\\ --log-type Tail \
|
||||
|
@ -137,7 +140,11 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
}
|
||||
|
||||
fn fileExists(file_name: []const u8) bool {
|
||||
const file = std.fs.openFileAbsolute(file_name, .{}) catch return false;
|
||||
defer file.close();
|
||||
return true;
|
||||
}
|
||||
fn addArgs(allocator: *std.mem.Allocator, original: []const u8, args: [][]const u8) ![]const u8 {
|
||||
var rc = original;
|
||||
for (args) |arg| {
|
||||
|
|
Loading…
Reference in New Issue
Block a user