-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify deployment steps #4
Comments
It seems like something like this: zip -yr lambda.zip bootstrap And then upload to AWS normal-ish as a custom lambda. |
So none of these work. I expect that I have library dependency issues. I don't expect ldc2 to work but probably gdc will work. Run 'ldd' against the output binary. We should get a list of the libraries needed. Then package up these libraries into a ./lib dir along with the zip. See what https://github.com/awslabs/aws-lambda-cpp#building-and-installing-the-runtime does. I checked and they package up a crap wad of stuff in terms of libraries. sigh . So ... either generate a binary that packages its dependencies (everything statically links), or generate a lib dir of dependencies and add an executable bootstrap script. It's possible gdc has all the dependencies already on the target host. I think what I'm missing is my bootstrap (shell script) is not executable. |
Here's the contents of the aws lambda cpp bootstrap:
|
Sort of stuck here. I think I need to try out the Lambda docker image and see what is missing. The use ldd on the libraries to see what is missing. Then maybe need to do something similar to what the C++ lambda does in terms of packaging .so files. |
So first step, add a file called bootstrap that is a bash script. We need this first line to make sure anything in our pipeline that isn't perfect will cause a failure: https://www.reddit.com/r/programming/comments/9ysjnu/safer_bash_scripts_with_set_euxo_pipefail/ Then we should set the AWS_EXECUTION_ENV. Since this is normally a reserved value, I think we can set anything here to indicate the lambda execution environment identifier.
The LAMBDA_TASK_ROOT is where our little sandbox is stuck handling execution of binaries. Anything we want to run or link to should be found in here. This is where lambda gets tricky when you are testing stuff locally. You can't execute things outside of this area. |
Now the trick with the above approach will be to package dependent libraries in LAMBDA_TASK__ROOT/lib. The CPP packager for lambda-cpp is pretty cool, but massively bloated too. According to their own docs, they have to package everything in std libc. And this will be true of any runtime that we create. It's especially true if you run something like a node or python lambda that includes some ridiculous package dependency that pulls in hundreds of MB of stuff. It's possible. |
Another weirdness in the lambda-cpp examples are that they don't actual parse the value of the function name the way we do in node or python. It just calls a main, and whatever is defined in main is run. We could implement this more flexible approach later, however, in the scheme of things, you actually want to package up the smallest amount of code possible. Why would you package multiple lambda functions that you might not be using? |
So here's what is needed in the lib folder potentially:
|
So of the above, I think we only don't need the linux-vdso.so.1. |
Ok, fixed up packaging. I don't see a clear reason for the error in the lambda, probably a deeper problem. The code actually runs fine locally. The packaging looks ok. I think I'm missing some logic on the lambda glue. My example actually has some garbage in it. All of the values that should get filled in from the environment (ARN, lambda function) all get filled in with some defaults. Fix that and I think this will work. |
I see the problem. I created a main app, but I don't actually call runHandler which has all of the lambda magik. |
Ok, that's it. Just need to move the "tester" code into unit tests. And then invoke runHandler(handler). |
This is the good news: a better result: lambd.layer.LambDException@source/layer.d(180): Failure to invoke AwsLambdaRuntimeAPI, reason: statusCode = 0??:? void lambd.layer.runHandler(std.json.JSONValue function(std.json.JSONValue, lambd.layer.LambdaContext)*) [0xd4df502b] |
So the problem at the moment is I have some bad curl usage. These are async calls. I need to rewrite the calls. The api is a bit funky with curl, there are a few high level requests, but they don't let you get at the details of the request/response. Fix that and I think this starts working. |
Seems that as I've switched build systems, and ldc version, and fixed the usage of curl, I am having library issues finding curl at runtime. I tired packaging curl libs but this isn't working. And compiling with --static directly didn't work. I think doing a static app is the way to go. I found this post on the forums:https://forum.dlang.org/post/udunaxcalnsrnzoomunq@forum.dlang.org Clearly the d forums is the only place to look. This is a little frustrating that there are almost no resources anywhere else, due to the fact that there are very few d posts on stack overflow. I'll try the approach mentioned in the post. Once I've got library issues and an example invoking, I need to fix any bugs in execution. |
Hmm, if I add a static target, I get these errors: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking |
So I posted the question here https://forum.dlang.org/post/jujyyiyiqcxmgfolduzf@forum.dlang.org The short answer is as expected. This is a weird area of phobos where it's probably not quite right, but it is as it is, and decisions were made to make libcurl an external library that must be linked in if used for statically built apps and libraries, and there is some special effort. Above and beyond my usual approach for doing things, use the libraries we have already, use LDD to find the libraries we need, or alternatively build in and link to the libraries we need, this feels like more effort than it is worth for getting to use libcurl. The best "fast" work around is to go with: https://github.com/adamdruppe/arsd/blob/master/http2.d I will seek to pull out the std.net.curl calls and switch to http2. Assuming it all builds in, I will fix up the build and packaging and integrate that one file. |
Looks like I will indeed need to ship openssl along with this library, which has its own challenges. |
Looks like I will indeed need to ship openssl along with this library, which has its own challenges. Here are the build issues. .dub/obj/lamb-d.o:package.d:function _D4arsd5http216SSL_library_initFZv: error: undefined reference to 'OPENSSL_init_ssl' |
I've got a way to build the openssl that should link with the http2.d from arsd. |
Ok, finally, got this stuff static linking without error (but with warning). Fixed up the external deps script. |
Otherwise it crashes. Not sure why, but would need to run this a bit locally or in a container to figure out. Anyway, do static for now.
Still have a problem with my bootstrap.
working:
|
That's sample output from my dummy bootstrap.d example |
done. |
So making a few notes, interestingly, someone released aws-lambda-d just yesterday. What is interesting is that one is a translation of aws-lambda C++. Which is cool. The library however, looks to depend on curl, which will present some issue when linking as I recall from getting this working. Another issue might be with the copyright, which is held by Amazon, but the code is under Apache. I think it's fine though. In any case, I think it's good for D there are 3 lambda runtimes, two that are modern and one that is a proof of concept from a few years back. |
Need to walk through a real deployment scenario. Make sure a simple HelloWorld example will work.
The text was updated successfully, but these errors were encountered: