From Newsgroup: comp.lang.tcl
To answer my own question it is not possible with cookfs (if I
understood well what Konstantin trying to explain) but it can be done
with zipfs in TCL9. So, I took a stub at it and here all it takes to run
TCL scripts using AWS Lambda:
== aws-lambda-runtime ==
$ git clone
https://github.com/awslabs/aws-lambda-cpp.git
$ cd aws-lambda-cpp
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=~/lambda-install
$ make && make install
== bootstrap.cpp ==
#include <tcl.h>
#include <aws/lambda-runtime/runtime.h>
using namespace aws::lambda_runtime;
static Tcl_Interp *interp = NULL;
static invocation_response my_handler(invocation_request const& req)
{
if (req.payload.length() > 42) {
return invocation_response::failure("error message here"/*error_message*/,
"error type here"
/*error_type*/);
}
Tcl_EvalFile(interp, "//zipfs:/app/main.tcl");
return invocation_response::success(Tcl_GetStringResult(interp) /*payload*/,
"application/json" /*MIME
type*/);
}
int main(int argc, char *argv[]) {
TclZipfs_AppHook(&argc, &argv);
interp = Tcl_CreateInterp();
Tcl_Init(interp);
run_handler(my_handler);
Tcl_DeleteInterp(interp);
return 0;
}
== mkimg.tcl ==
set source_dir [file dirname [file normalize [info script]]]
set script_dir [file join $source_dir scripts]
for { set i 0 } { $i < $argc } { incr i } {
set arg [lindex $argv $i]
switch -exact -- $arg {
-o {
set output_file [lindex $argv [incr i]]
}
default {
puts stderr "Unknown argument: \"$arg\""
exit 1
}
}
}
if { ![info exists output_file] } {
puts stderr "No output file specified"
exit 1
}
if { [file exists bootstrap.vfs] } {
file delete -force bootstrap.vfs
}
if { [file exists $output_file] } {
file delete -force $output_file
}
file mkdir bootstrap.vfs
file copy [file join [zipfs root] app tcl_library] bootstrap.vfs
file copy [file join $script_dir main.tcl] bootstrap.vfs
file copy [file join [file dirname [info script]] bootstrap] bootstrap.vfs/bootstrap
zipfs mkzip $output_file bootstrap.vfs bootstrap.vfs
file attributes $output_file -permissions 0o0644
puts "Created: $output_file"
== Makefile ==
all:
g++ -std=c++11 -o bootstrap bootstrap.cpp -L/path/to/static/lib -ltcl9.0 -lz -lm -laws-lambda-runtime -lcurl -lssl -lcrypto -I/path/to/static/include -static
/path/to/static/bin/tclsh9.0 mkimg.tcl -o bootstrap.img
cat bootstrap.img >> bootstrap
zip bootstrap.zip bootstrap
== Trying it out with localstack ==
awslocal iam create-role --role-name myhellorole
--assume-role-policy-document {}
awslocal lambda create-function --function-name MyHelloFunction --role "arn:aws:iam::000000000000:role/myhellorole" --zip-file
fileb://bootstrap.zip --runtime provided.al2 --timeout 5 --memory-size
2048 --handler bootstrap
sleep 3
awslocal lambda invoke --function-name MyHelloFunction --log-type Tail /tmp/outfile
== Epilogue ==
I hope it helped. Took me a while to figure out the details.
--- Synchronet 3.20a-Linux NewsLink 1.114