awslabs / aws-lambda-cpp Goto Github PK
View Code? Open in Web Editor NEWC++ implementation of the AWS Lambda runtime
License: Apache License 2.0
C++ implementation of the AWS Lambda runtime
License: Apache License 2.0
As per https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-to-al2/ are there any known issues with using this runtime in the new environment?
Hello!
I am trying to pass a base64-encoded image as a payload to a handler. Everything works fine for small images (say 4kb), however, for larger images (60kb, yet still below the limit) I always get "Process exited before completing request" error.
I've made tests with a simple function that just returns the payload:
using namespace aws::lambda_runtime;
invocation_response handler(invocation_request const &request)
{
return invocation_response::success(request.payload, "application/json");
}
int main(int argc, char *argv[])
{
run_handler(handler);
return 0;
}
I've checked the CloudWatch logs:
13:10:04 START RequestId: a6f64093-b2da-4cfd-80e1-2993b0b2d618 Version: $LATEST
13:10:04 [DEBUG] [1567429804774] LAMBDA_RUNTIME CURL DBG: Closing connection 1
13:10:04 [DEBUG] [1567429804774] LAMBDA_RUNTIME Completed request to http://127.0.0.1:9001/2018-06-01/runtime/invocation/next
13:10:04 [DEBUG] [1567429804774] LAMBDA_RUNTIME CURL returned error code 56 - Failure when receiving data from the peer
13:10:04 [ERROR] [1567429804774] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
13:10:04 [DEBUG] [1567429804774] LAMBDA_RUNTIME Making request to http://127.0.0.1:9001/2018-06-01/runtime/invocation/next
13:10:04 [DEBUG] [1567429804774] LAMBDA_RUNTIME CURL DBG: Hostname in DNS cache was stale, zapped
13:10:04 [DEBUG] [1567429804775] LAMBDA_RUNTIME CURL DBG: Trying 127.0.0.1...
13:10:04 [DEBUG] [1567429804775] LAMBDA_RUNTIME CURL DBG: TCP_NODELAY set
13:10:04 [DEBUG] [1567429804775] LAMBDA_RUNTIME CURL DBG: Connected to 127.0.0.1 (127.0.0.1) port 9001 (#2)
13:10:04 [DEBUG] [1567429804775] LAMBDA_RUNTIME CURL DBG: GET /2018-06-01/runtime/invocation/next HTTP/1.1
13:10:04 Host: 127.0.0.1:9001
13:10:04 Accept: */*
13:10:04
13:10:04 END RequestId: a6f64093-b2da-4cfd-80e1-2993b0b2d618
13:10:04 REPORT RequestId: a6f64093-b2da-4cfd-80e1-2993b0b2d618 Duration: 38.23 ms Billed Duration: 100 ms Memory Size: 3008 MB Max Memory Used: 45 MB XRAY TraceId: -5d6d14ac-af92232da896727996439756 SegmentId: 377737ff72691de0 Sampled: true
13:10:04 RequestId: a6f64093-b2da-4cfd-80e1-2993b0b2d618 Process exited before completing request
13:10:04 [INFO] [1567429804963] LAMBDA_RUNTIME Initializing the C++ Lambda Runtime version 0.2.4
13:10:04 [DEBUG] [1567429804963] LAMBDA_RUNTIME LAMBDA_SERVER_ADDRESS defined in environment as: 127.0.0.1:9001
13:10:04 [DEBUG] [1567429804978] LAMBDA_RUNTIME Making request to http://127.0.0.1:9001/2018-06-01/runtime/invocation/next
13:10:04 [DEBUG] [1567429804978] LAMBDA_RUNTIME CURL DBG: Trying 127.0.0.1...
13:10:04 [DEBUG] [1567429804978] LAMBDA_RUNTIME CURL DBG: TCP_NODELAY set
13:10:04 [DEBUG] [1567429804978] LAMBDA_RUNTIME CURL DBG: Connected to 127.0.0.1 (127.0.0.1) port 9001 (#0)
13:10:04 [DEBUG] [1567429804978] LAMBDA_RUNTIME CURL DBG: GET /2018-06-01/runtime/invocation/next HTTP/1.1
13:10:04 Host: 127.0.0.1:9001
13:10:04 Accept: */*
It looks like the request to /2018-06-01/runtime/invocation/next somehow kills the runtime.
From my tests this happens for payloads larger than 7759 bytes. Slightly bigger payloads sometimes get through, which is even more confusing. Maybe some timeout somewhere?
Do you have any idea why this might happen? Or some suggestions how I could dig deeper?
[My apologies if this is the wrong repo, but I figure there's at least a 40% chance that the problem is here....]
I've got an AWS API Gateway method which invokes a Lambda function. When I deploy a new copy of my Lambda code, I frequently end up in a state where, when I make a request to my method, my Lambda handler routine doesn't actually execute -- instead, the Lambda runtime errors out (and then restarts my code).
Here's what I see in CloudWatch:
Lambda function invocation starting.
Verbosity: 5
Lambda function calling Lambda runtime.
START RequestId: 2cd76704-130c-11e9-a15c-2300d7fc7d3a Version: $LATEST
[ERROR] [1546927863202] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
END RequestId: 2cd76704-130c-11e9-a15c-2300d7fc7d3a
REPORT RequestId: 2cd76704-130c-11e9-a15c-2300d7fc7d3a Init Duration: 159.08 ms Duration: 34.51 ms Billed Duration: 200 ms Memory Size: 256 MB Max Memory Used: 35 MB
RequestId: 2cd76704-130c-11e9-a15c-2300d7fc7d3a Process exited before completing request
Lambda function invocation starting.
Verbosity: 5
Lambda function calling Lambda runtime.
The lines preceding START
are from my main()
routine (the Verbosity
line comes from an initialization function it calls). The line just before START
is the last line in my main()
routine before the call to lambda_runtime::run_handler()
. My handler function is never called.
(I have seen lots of examples where the runtime does not error out after the Failed to get next invocation
message and execution then enters my handler; but, for the last couple of hours, I haven't had such joy.)
The CloudWatch log for the API Gateway mentions this:
Endpoint response body before transformations:
{ "errorMessage": "RequestId: 2cd76704-130c-11e9-a15c-2300d7fc7d3a Process exited before completing request" }
As long as I keep lobbing requests at it, I keep getting the same results. However, if I update the Lambda code, sometimes it will start working normally again. Then, with a subsequent update, it goes back into this tailspin again.
Any suggestions? (I don't think the issue is in my code, because what I do before control reaches the Lambda runtime is pretty innocuous, and after that my code never gets executed as far as I can tell.)
Thanks!
While trying to install this on ubuntu 18.04 it required installing the packages libcurl4-openssl-dev and zip
I suggest adding them to the readme.
When I test my Lambda function via the "Test" button on the AWS Lambda "console" web page, I get the following in the log:
START RequestId: 87a9968e-0f96-11e9-9807-e18356b5372b Version: $LATEST
/bin/bash: relocation error: lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
END RequestId: 87a9968e-0f96-11e9-9807-e18356b5372b
If I unpack my .zip
file locally, the tail of the output looks like this:
inflating: [...]
finishing deferred symbolic links:
lib/libm.so.6 -> libm-2.23.so
[...]
lib/libc.so.6 -> libc-2.23.so
[...]
lib/ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.23.so
[...]
lib/libnss_dns.so.2 -> libnss_dns-2.23.so
I note that of all the symlinks it creates, only the one for ld-linux-x86-64.so.2
contains a full, absolute path.
I'm gonna guess that it's because, on my system, /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
is itself a symlink (to /lib/x86_64-linux-gnu/ld-2.23.so
), and so the packager is getting the symlink file where it should be following the symlink to the actual file...with the result that my Lambda is actually referencing the underlying system's library instead of the one that it's supposed to have brought with it in the bundle.
(I'm building on Linux ip-172-31-27-38 4.4.0-1070-aws #80-Ubuntu SMP Thu Oct 4 13:56:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
.)
Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)
gunnar@Aspen:/mnt/c/Users/gunna$ cd /mnt/c/Dev/Couloir/Research/aws/HelloCMake
gunnar@Aspen:/mnt/c/Dev/Couloir/Research/aws/HelloCMake$ cd build
gunnar@Aspen:/mnt/c/Dev/Couloir/Research/aws/HelloCMake/build$ ls
gunnar@Aspen:/mnt/c/Dev/Couloir/Research/aws/HelloCMake/build$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/lambda-install
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Dev/Couloir/Research/aws/HelloCMake/build
gunnar@Aspen:/mnt/c/Dev/Couloir/Research/aws/HelloCMake/build$ make
[100%] Built target demo
gunnar@Aspen:/mnt/c/Dev/Couloir/Research/aws/HelloCMake/build$ make aws-lambda-package-demo
[100%] Built target demo
make[3]: /mnt/c/Dev/Couloir/Research/aws/aws-lambda-cpp/build/packager: Command not found
make[3]: *** [CMakeFiles/aws-lambda-package-demo.dir/build.make:57: CMakeFiles/aws-lambda-package-demo] Error 127
make[2]: *** [CMakeFiles/Makefile2:77: CMakeFiles/aws-lambda-package-demo.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/aws-lambda-package-demo.dir/rule] Error 2
make: *** [Makefile:118: aws-lambda-package-demo] Error 2
You can use C++11 or later. Plain C, C++98 and C++03 can work but require you to write a shim. Will add examples on how to do that if there's enough interest.
Can you give guidance (or an example) of this shim layer for C99?
When I run the make aws-lambda-package-hello command. I see this error.
Ubuntu 16.04
CMakeFiles/aws-lambda-package-hello.dir/build.make:57: recipe for target 'CMakeFiles/aws-lambda-package-hello' failed
make[3]: *** [CMakeFiles/aws-lambda-package-hello] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/aws-lambda-package-hello.dir/all' failed
make[2]: *** [CMakeFiles/aws-lambda-package-hello.dir/all] Error 2
CMakeFiles/Makefile2:74: recipe for target 'CMakeFiles/aws-lambda-package-hello.dir/rule' failed
make[1]: *** [CMakeFiles/aws-lambda-package-hello.dir/rule] Error 2
Makefile:118: recipe for target 'aws-lambda-package-hello' failed
make: *** [aws-lambda-package-hello] Error 2
I am trying to follow instructions for a hello world c++ lambda function using instructions in :
https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/
I was able to build it before, but from the latest git repository, I get these errors:
$ make aws-lambda-package-hello
[100%] Built target hello
CMakeFiles/aws-lambda-package-hello.dir/build.make:57: recipe for target 'CMakeFiles/aws-lambda-package-hello' failed
make[3]: *** [CMakeFiles/aws-lambda-package-hello] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/aws-lambda-package-hello.dir/all' failed
make[2]: *** [CMakeFiles/aws-lambda-package-hello.dir/all] Error 2
CMakeFiles/Makefile2:111: recipe for target 'CMakeFiles/aws-lambda-package-hello.dir/rule' failed
make[1]: *** [CMakeFiles/aws-lambda-package-hello.dir/rule] Error 2
Makefile:131: recipe for target 'aws-lambda-package-hello' failed
Your help is appreciated.
Thanks
Kiran
On Ubuntu 18.04, when I follow the steps in https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/ the lambda fails to run with the log:
START RequestId: 8ea03c41-6ca2-4e5a-b63c-d3461c8a777c Version: $LATEST
/var/task/bootstrap: line 4: /var/task/lib/: Is a directory
/var/task/bootstrap: line 4: exec: /var/task/lib/: cannot execute: Is a directory
END RequestId: 8ea03c41-6ca2-4e5a-b63c-d3461c8a777c
REPORT RequestId: 8ea03c41-6ca2-4e5a-b63c-d3461c8a777c Duration: 153.26 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 12 MB
When I replace $PKG_LD
at
aws-lambda-cpp/packaging/packager
Line 141 in 1dccd2a
ld-linux-x86-64.so.2
, the lambda runs successfully.
When I move the if block at line 116 to line 112, it works for me:
aws-lambda-cpp/packaging/packager
Lines 113 to 121 in 1dccd2a
I am trying to add g++
inside AWS Lambda C++ custom runtime
.
Now g++
requires .so
(shared libraries) files as well as .a
(static libraries).
For this, I installed g++ inside chroot directory (directory gpp
) on the Amazon Linux machine.
Now, I created another directory that has bin
, usr
, lib
, and lib64
directories (taken from chroot directory). I created a zip of this directory, uploaded to s3 (as it is more than 50MB), and created a Lambda layer using this zip directory.
Now, after adding this layer
in the lambda
function, I am trying to run.
execl("/opt/usr/bin/g++48", "/opt/usr/bin/g++48", "-Wall", "/tmp/hello.cpp","-o", "/tmp/hello.o",
"-I/opt/gpp3/usr/include/", (char *) 0)
Using the above g++
is able to find shared libraries
as well as header files
but it is not able to find the static library.
/usr/bin/ld: cannot find /usr/lib64/libc_nonshared.a
collect2: error: ld returned 1 exit status
libc_nonshared.a
exists inside /opt/gpp3/usr/lib64/
but it is searching in /usr/lib64/
.
I tried providing full path in g++ command as -L/opt/gpp3/usr/lib64/libc_nonshared.a
and
-L/opt/gpp3/usr/lib64/libc_nonshared
and -L/opt/gpp3/usr/lib64/
But none of them works. Any help is deeply appreciated.
I am following the instructions from README.md
to build the demo.zip
on Fedora 31 (x86_64
), i.e., I am not running custom code yet (besides renaming the binary). Unfortunately, I am getting the following error when calling the function.
/var/task/bin/incoming-mail: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /var/task/lib/libstdc++.so.6)
As it turns out, the packager
script gets the list of shared objects for glibc
from rpm
.
$ cat /etc/fedora-release
Fedora release 31 (Thirty One)
$ rpm --query --list glibc | sed -E '/\.so$|\.so\.[0-9]+$/!d'
/lib64/ld-2.30.so
/lib64/ld-linux-x86-64.so.2
/lib64/libBrokenLocale-2.30.so
/lib64/libBrokenLocale.so.1
/lib64/libSegFault.so
/lib64/libanl-2.30.so
/lib64/libanl.so.1
/lib64/libc-2.30.so
/lib64/libc.so.6
[...]
/usr/lib64/audit/sotruss-lib.so
/usr/lib64/gconv/ANSI_X3.110.so
[...]
/lib/ld-2.30.so
/lib/ld-linux.so.2
/lib/libBrokenLocale-2.30.so
/lib/libBrokenLocale.so.1
/lib/libSegFault.so
/lib/libanl-2.30.so
/lib/libanl.so.1
/lib/libc-2.30.so
/lib/libc.so.6
[...]
/usr/lib/audit/sotruss-lib.so
/usr/lib/gconv/ANSI_X3.110.so
[...]
This list includes 64-bit and 32-bit versions of glibc
's shared objects.
I unpacked the resutling zip-file and it indeed contains 32-bit libraries.
$ unzip path/to/demo.zip
$ cd lib/
$ for i in * ; do file ${i} ; done | awk '{ print $1 $3 }'
[...]
libc-2.30.so:32-bit
[...]
libdl-2.30.so:32-bit
[...]
libgcc_s.so.1:64-bit
[...]
To omit all 32-bit libraries, one can omit all shared objects that are in directories containing the string lib/
.
diff --git a/packaging/packager b/packaging/packager
index 32b2db0..497d0ae 100755
--- a/packaging/packager
+++ b/packaging/packager
@@ -74,7 +74,7 @@ function package_libc_via_dpkg() {
function package_libc_via_rpm() {
if type rpm > /dev/null 2>&1; then
if [[ $(rpm --query --list glibc | wc -l) -gt 1 ]]; then
- rpm --query --list glibc | sed -E '/\.so$|\.so\.[0-9]+$/!d'
+ rpm --query --list glibc | sed -E '/\.so$|\.so\.[0-9]+$/!d' | grep -Pv 'lib/'
fi
fi
}
I don't want to assess if this is an acceptable solution, but I confirmed that the Lambda function from a newly packaged demo.zip
works as expected.
$ aws lambda invoke --function-name demo --payload '{"answer":42}' output.txt
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
That would be useful for logging
As following the sdk sample all the way till the following steps:
$ cmake3 .. -DBUILD_ONLY=s3 -DBUILD_SHARED_LIBS=OFF -DENABLE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/out
-- TARGET_ARCH not specified; inferring host OS to be platform compilation target
-- Building AWS libraries as static objects
-- Generating linux build config
-- Building project version: 1.7.20
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ec2-user/aws-sdk-cpp/build/.deps
[ 33%] Built target AwsCCommon
[ 66%] Built target AwsChecksums
[100%] Built target AwsCEventStream
-- Third-party dependencies are installed at: ~/out
-- Zlib include directory: /usr/include
-- Zlib library: /usr/lib64/libz.so
-- Encryption: Openssl
-- Openssl include directory: /usr/include
-- Openssl library: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so
-- Http client: Curl
-- Curl include directory: /usr/include
-- Curl library: /usr/lib64/libcurl.so
-- Considering s3
-- Updating version info to 1.7.20
-- Custom memory management disabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ec2-user/aws-sdk-cpp/build
$ make && make install
Scanning dependencies of target aws-cpp-sdk-core
[ 1%] Building CXX object aws-cpp-sdk-core/CMakeFiles/aws-cpp-sdk-core.dir/ub_core.cpp.o
[ 2%] Linking CXX static library libaws-cpp-sdk-core.a
[ 37%] Built target aws-cpp-sdk-core
Scanning dependencies of target aws-cpp-sdk-s3
[ 39%] Building CXX object aws-cpp-sdk-s3/CMakeFiles/aws-cpp-sdk-s3.dir/ub_S3.cpp.o
Then it stuck here and after a while it returns the following:
g++64: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See http://bugzilla.redhat.com/bugzilla for instructions.
make[2]: *** [aws-cpp-sdk-s3/CMakeFiles/aws-cpp-sdk-s3.dir/ub_S3.cpp.o] Error 4
make[1]: *** [aws-cpp-sdk-s3/CMakeFiles/aws-cpp-sdk-s3.dir/all] Error 2
make: *** [all] Error 2
I've tried to install RDS sdk instead - because this is what in my plan - through replacing -DBUILD_ONLY=s3
by -DBUILD_ONLY=rds
, but unfortunalty got same results, also stucked at:
[ 40%] Building CXX object aws-cpp-sdk-rds/CMakeFiles/aws-cpp-sdk-rds.dir/ub_RDS.cpp.o
I'm following the instructions for creating a lambda package using AWS SDK C++ and S3 from:
https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/
My OS is Docker FROM ubuntu:18.04
, and my C++ SDK version is 1.7.224.
With a previous C++ SDK version (1.7.210), It worked flawlessly. Now, I get:
[100%] Linking CXX executable XXX
/usr/bin/ld: cannot find -laws-c-event-stream
/usr/bin/ld: cannot find -laws-checksums
/usr/bin/ld: cannot find -laws-c-common
collect2: error: ld returned 1 exit status
make[2]: *** [XXX] Error 1
CMakeFiles/XXX.dir/build.make:140: recipe for target 'XXX' failed
Why? Should I change any cmake instructions, which haven't been updated in the link above?
Update: the problem appears with 1.7.212
While running make && make install on centos 7 I received this kind of error
docker run --rm -v /home/centos/php-lambda-layer:/opt/layer lambci/lambda:build-nodejs8.10 /opt/layer/build.sh
/bin/bash: /opt/layer/build.sh: Permission denied
make: *** [php71.zip] Error 126
Hey there.
I tried to build aws-lambda-cpp on my Ubuntu 20.4 machine but got the following errors:
In file included from /home/erik/Projects/tuk/aws-lambda-cpp/src/backward.cpp:26:0:
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h: In member function โvoid backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::find_in_section(bfd_vma, bfd_vma, backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::bfd_fileobject&, asection*, backward::TraceResolverLinuxImpl<backward::trace_resolver_tag::libbfd>::find_sym_result&)โ:
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1235:14: error: โbfd_get_section_flagsโ was not declared in this scope
if ((bfd_get_section_flags(fobj.handle.get(), section) & SEC_ALLOC) == 0)
^~~~~~~~~~~~~~~~~~~~~
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1235:14: note: suggested alternative: โbfd_set_section_flagsโ
if ((bfd_get_section_flags(fobj.handle.get(), section) & SEC_ALLOC) == 0)
^~~~~~~~~~~~~~~~~~~~~
bfd_set_section_flags
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1238:28: error: โbfd_get_section_vmaโ was not declared in this scope
bfd_vma sec_addr = bfd_get_section_vma(fobj.handle.get(), section);
^~~~~~~~~~~~~~~~~~~
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1238:28: note: suggested alternative: โbfd_set_section_vmaโ
bfd_vma sec_addr = bfd_get_section_vma(fobj.handle.get(), section);
^~~~~~~~~~~~~~~~~~~
bfd_set_section_vma
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1239:30: error: โbfd_get_section_sizeโ was not declared in this scope
bfd_size_type size = bfd_get_section_size(section);
^~~~~~~~~~~~~~~~~~~~
/home/erik/Projects/tuk/aws-lambda-cpp/src/backward.h:1239:30: note: suggested alternative: โbfd_set_section_sizeโ
bfd_size_type size = bfd_get_section_size(section);
^~~~~~~~~~~~~~~~~~~~
bfd_set_section_size
make[2]: *** [CMakeFiles/aws-lambda-runtime.dir/build.make:89: CMakeFiles/aws-lambda-runtime.dir/src/backward.cpp.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/aws-lambda-runtime.dir/all] Fehler 2
make: *** [Makefile:130: all] Fehler 2
CMake: 3.16.3
GCC: 9.3.0
Distro: Ubuntu 20.4.
As far as I can tell, libbfd exists:
$ locate libbfd
/snap/gnome-3-34-1804/24/usr/lib/x86_64-linux-gnu/libbfd-2.30-system.so
/snap/gnome-3-34-1804/33/usr/lib/x86_64-linux-gnu/libbfd-2.30-system.so
/usr/lib/x86_64-linux-gnu/libbfd-2.34-system.so
/usr/lib/x86_64-linux-gnu/libbfd.a
/usr/lib/x86_64-linux-gnu/libbfd.so
I know it might not have something to do with runtime code. I ported some working code to lambda, it works fine (able to download file from s3) but crashes with the following error:
terminate called after throwing an instance of 'std::length_error'
basic_string::_M_create what(): basic_string::_M_create
Hello,
Just wondering if I could get some clarification on how the cpp lambda runtime works, namely the logging aspect.
Using your S3 example as a basis, I tried creating my own "Hello world" lambda function:
#include <aws/lambda-runtime/runtime.h>
#include <aws/core/Aws.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
#include <aws/core/utils/logging/LogLevel.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/core/platform/Environment.h>
using namespace aws::lambda_runtime;
char const TAG[] = "lambda logger";
invocation_response my_handler(invocation_request const& request)
{
AWS_LOGSTREAM_INFO(TAG, "Some test logging");
return invocation_response::success("Lambda ran successfully", "application/json");
}
std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
{
return [] {
return Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
"console_logger", Aws::Utils::Logging::LogLevel::Trace);
};
}
int main() {
// Set and initalise api options
Aws::SDKOptions options;
// Initialise logging
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
options.loggingOptions.logger_create_fn = GetConsoleLoggerFactory();
Aws::InitAPI(options);
{
run_handler(my_handler);
}
Aws::ShutdownAPI(options);
return 0;
}
I didn't go down the CMake route as I'm not overly familiar with it, but just created my own Makefile with the relevant library links etc. Managed to compile it, upload it and run it both remotely and from within the Lambda UI no problem.
However, I couldn't manage to get any log output from the my_handler method
As a test, commented out run_handler(my_handler), added some AWS_LOGSTREAM_INFO() calls in the codeblock after the InitAPI, compiled and ran the cpp binary locally and the logging worked as expected.
After much head-scratching, googling and trying various things, I tried adding the AWS_LOGSTREAM_FLUSH() function after the AWS_LOGSTREAM_INFO() call in the my_handler function and finally started getting output.
I'm just wondering why flushing the buffer is required here, when you didn't use it in your S3 example and it didn't seemed to be needed when I ran the cpp binary from the command-line using the aws logging libraries?
Apologies if it is a silly question. I'm more familiar with Java than C++, but was trying lambda with the Java runtime and found the cold-start very slow and was looking for a faster alternative.
Any help would be greatly appreciated.
I get the following when I attempt to make the runtime:
~/aws-lambda-cpp/release$ make
Scanning dependencies of target aws-lambda-runtime
[ 20%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/logging.cpp.o
[ 40%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/runtime.cpp.o
/home/owe043/aws-lambda-cpp/src/runtime.cpp:321:13: error: format specifies type 'long' but the argument has type 'std::__1::chrono::duration<long long, std::__1::ratio<1, 1000> >::rep'
(aka 'long long') [-Werror,-Wformat]
req.get_time_remaining().count());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
CMakeFiles/aws-lambda-runtime.dir/build.make:75: recipe for target 'CMakeFiles/aws-lambda-runtime.dir/src/runtime.cpp.o' failed
make[2]: *** [CMakeFiles/aws-lambda-runtime.dir/src/runtime.cpp.o] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/aws-lambda-runtime.dir/all' failed
make[1]: *** [CMakeFiles/aws-lambda-runtime.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Steps up to that were:
git clone https://github.com/awslabs/aws-lambda-cpp.git
cd aws-lambda-cpp/
mkdir release
cd release/
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=~/aws-lambda-out
make
clang is;
$ clang --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /software/clang/bin
$ echo $CXXFLAGS
-stdlib=libc++
Using Ubuntu 16.04.
Note the following change resolves the compilation error:
diff --git a/src/runtime.cpp b/src/runtime.cpp
index 0af68b2..dc966be 100644
--- a/src/runtime.cpp
+++ b/src/runtime.cpp
@@ -318,7 +318,7 @@ runtime::next_outcome runtime::get_next()
LOG_TAG,
"Received payload: %s\nTime remaining: %ld",
req.payload.c_str(),
- req.get_time_remaining().count());
+ static_cast<long>(req.get_time_remaining().count()));
}
return next_outcome(req);
}
I found a problem with the packager script on Ubunu 18.0.4 LTS.
Ubuntu has rpm tool installed from several packages, so when the packager runs there is error 1 happens on make.
For this line libc_libs+=$(package_libc_via_rpm)
Above call to the function gives empty, so array with data += empy
give Error 1. Hope you fix it soon.
I've been in contact with the AWS support to get help with setting up a simple AWS Lambda function with JSON inputs/outputs received/send via API Gateway. The support officer lacked the required C++ expertise and could only find three examples, one being extremely simple and the other ones pretty advanced. For both us this, this was insufficient to figure out how to define the required handler function that handles the input/output of the C++ Lambda's. Hence the support officer suggested to open an issue here and ask you (as C++ Runtime developers) to perhaps create a few additional examples. The C++ equivalents of the NodeJS code used in the API Gateway + Lambda tutorials would e.g. be great:
These are a bit more elaborate as the Hello World example in the C++ Runtime Blog (https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/)
but still very simple to understand and hence informative. Great to explain how to receive inputs, use the C++ SDK to parse the JSON, get the inputs, return a serialized JSON or error code, etc.
Would something like this be possible?
grokmachine@Dendis-MacBook-Pro ๎ฐ ๏ผ ~/research/konvergen/aws-lambda-cpp/examples/s3_build ๎ฐ ๏ ๏ฆ master ๏ ๎ฐ make
Scanning dependencies of target encoder
[ 50%] Building CXX object CMakeFiles/encoder.dir/main.cpp.o
/Users/grokmachine/research/konvergen/aws-lambda-cpp/examples/s3/main.cpp:30:15: error: no matching constructor for initialization of
'Aws::Utils::Json::JsonValue'
JsonValue json(req.payload);
^ ~~~~~~~~~~~
/usr/local/include/aws/core/utils/json/JsonSerializer.h:50:17: note: candidate constructor not viable: no known conversion from 'const
basic_string<[2 * ...], allocator<char>>' to 'const basic_string<[2 * ...], Aws::Allocator<char>>' for 1st argument
JsonValue(const Aws::String& value);
^
/usr/local/include/aws/core/utils/json/JsonSerializer.h:55:17: note: candidate constructor not viable: no known conversion from
'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to 'Aws::IStream &' (aka
'basic_istream<char, std::char_traits<char> > &') for 1st argument
JsonValue(Aws::IStream& istream);
^
/usr/local/include/aws/core/utils/json/JsonSerializer.h:61:17: note: candidate constructor not viable: no known conversion from
'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to 'const Aws::Utils::Json::JsonValue' for
1st argument
JsonValue(const JsonValue& value);
^
/usr/local/include/aws/core/utils/json/JsonSerializer.h:67:17: note: candidate constructor not viable: no known conversion from
'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to 'Aws::Utils::Json::JsonValue' for 1st
argument
JsonValue(JsonValue&& value);
^
/usr/local/include/aws/core/utils/json/JsonSerializer.h:218:17: note: candidate constructor not viable: no known conversion from
'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') to 'cJSON *' for 1st argument
JsonValue(cJSON* value);
^
/usr/local/include/aws/core/utils/json/JsonSerializer.h:45:17: note: candidate constructor not viable: requires 0 arguments, but 1 was
provided
JsonValue();
^
/Users/grokmachine/research/konvergen/aws-lambda-cpp/examples/s3/main.cpp:53:41: error: no viable conversion from 'basic_string<[2 * ...],
Aws::Allocator<char>>' to 'const basic_string<[2 * ...], allocator<char>>'
return invocation_response::success(base64_encoded_file, "application/base64");
^~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:793:5: note: candidate
constructor not viable: no known conversion from 'Aws::String' (aka 'basic_string<char, std::char_traits<char>, Aws::Allocator<char>
>') to 'const std::__1::basic_string<char> &' for 1st argument
basic_string(const basic_string& __str);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:798:5: note: candidate
constructor not viable: no known conversion from 'Aws::String' (aka 'basic_string<char, std::char_traits<char>, Aws::Allocator<char>
>') to 'std::__1::basic_string<char> &&' for 1st argument
basic_string(basic_string&& __str)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:811:5: note: candidate
constructor template not viable: no known conversion from 'Aws::String' (aka 'basic_string<char, std::char_traits<char>,
Aws::Allocator<char> >') to 'const char *' for 1st argument
basic_string(const _CharT* __s) {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:861:5: note: candidate
constructor not viable: no known conversion from 'Aws::String' (aka 'basic_string<char, std::char_traits<char>, Aws::Allocator<char>
>') to 'initializer_list<char>' for 1st argument
basic_string(initializer_list<_CharT> __il);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:869:5: note: candidate function
operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
^
/usr/local/include/aws/lambda-runtime/runtime.h:94:59: note: passing argument to parameter 'payload' here
static invocation_response success(std::string const& payload, std::string const& content_type);
^
/Users/grokmachine/research/konvergen/aws-lambda-cpp/examples/s3/main.cpp:126:16: error: no viable conversion from returned value of type
'const basic_string<[2 * ...], Aws::Allocator<char>>' to function return type 'basic_string<[2 * ...], allocator<char>>'
return outcome.GetError().GetMessage();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:793:5: note: candidate
constructor not viable: no known conversion from 'const Aws::String' (aka 'const basic_string<char, std::char_traits<char>,
Aws::Allocator<char> >') to 'const std::__1::basic_string<char> &' for 1st argument
basic_string(const basic_string& __str);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:798:5: note: candidate
constructor not viable: no known conversion from 'const Aws::String' (aka 'const basic_string<char, std::char_traits<char>,
Aws::Allocator<char> >') to 'std::__1::basic_string<char> &&' for 1st argument
basic_string(basic_string&& __str)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:811:5: note: candidate
constructor template not viable: no known conversion from 'const Aws::String' (aka 'const basic_string<char, std::char_traits<char>,
Aws::Allocator<char> >') to 'const char *' for 1st argument
basic_string(const _CharT* __s) {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:861:5: note: candidate
constructor not viable: no known conversion from 'const Aws::String' (aka 'const basic_string<char, std::char_traits<char>,
Aws::Allocator<char> >') to 'initializer_list<char>' for 1st argument
basic_string(initializer_list<_CharT> __il);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:869:5: note: candidate function
operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
^
3 errors generated.
make[2]: *** [CMakeFiles/encoder.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/encoder.dir/all] Error 2
make: *** [all] Error 2
03:22:53
REPORT RequestId: 89894b68-4c17-4ea6-b6e6-91bca83ae5b1 Duration: 1023.33 ms Billed Duration: 1100 ms Memory Size: 3008 MB Max Memory Used: 43 MB
๏
03:22:53
RequestId: 89894b68-4c17-4ea6-b6e6-91bca83ae5b1 Error: Runtime exited with error: signal: segmentation fault (core dumped) Runtime.ExitError
Hello,
Fantastic sdk and very much needed.
Recently I followed the basic tutorial and run a simple C++ program on aws lambda.
However, it has a 50/50 chance of success, which is very confusing.
It is a simple program with little usage of dynamic memory allocation and only printf and std::string is used from the standard library.
When it failed, it returns
{
"errorMessage": "RequestId: da9a1e36-07cb-45a2-9e4e-db2f80288d11 Process exited before completing request"
}
The printf marks I put there indicates the code went through just fine but it failed to get out of the handler function.
What can be the issue?
Thank you.
Given that the location of the CA bundle is likely to be problem (given the philosophy here of enabling people to build their Lambda function on their own Linux distribution), it seems like someone here with the appropriate pull could get the good folks over at aws-sdk-cpp to tweak their code to automatically look in the right place if it can't find the bundle in the expected place.
Just sayin'.... ;-)
Thanks!
LambCi, just vacuuming the binaries from a live AWS Lambda instance, is a bit of a hack.
Is there any repository to pull AWS Lambda instance dynamic/static libraries from directly to remove the Docker repo dependency on builds? Bring your own libc isn't enough. Openssl etc have had breaking changes too.
When running the following code we are attempting to get the AWS_LOGSTREAM_TRACE to show-up in the cloudwatch log instance to no avail. The odd part is when we invoke the lambda multiple times in quick succession it does write a log with the trace in it.
We modified the code in your S3 example to just print to the log but we didn't include all of our functions in this post. We are having issues logging with the s3 example as well.
cmake . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=~/install
aws lambda create-function --function-name lambda-demo --role arn:aws:iam::<redacted>:role/lambda-demo --runtime provided --timeout 15 --memory-size 128 --handler demo --zip-file fileb://memoryreader.zip
std::string open_and_read_file(
Aws::S3::S3Client const& client,
Aws::String const& bucket,
Aws::String const& key
);
std::string get_memory_consumption();
char const TAG[] = "LAMBDA_ALLOC";
static invocation_response my_handler(invocation_request const& req, Aws::S3::S3Client const& client)
{
using namespace Aws::Utils::Json;
JsonValue json(req.payload);
if (!json.WasParseSuccessful()) {
return invocation_response::failure("Failed to parse input JSON", "InvalidJSON");
}
auto v = json.View();
get_memory_consumption();
AWS_LOGSTREAM_TRACE(TAG, "Hello-World!");
if (!v.ValueExists("s3bucket") || !v.ValueExists("s3key") ||
!v.GetObject("s3bucket").IsString() || !v.GetObject("s3key").IsString()) {
return invocation_response::failure("Missing input value s3buckets or 3key " , "InvalidJSON");
}
if (v.ValueExists("s3bucket") || v.ValueExists("s3key") ||
v.GetObject("s3bucket").IsString() || v.GetObject("s3key").IsString()) {
std::string toReturn = get_memory_consumption();
return invocation_response::success(toReturn, "application/json");
}
return invocation_response::failure("failure", "DownloadFailure");
}
std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
{
return [] {
return Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
"console_logger", Aws::Utils::Logging::LogLevel::Trace);
};
}
int main()
{
using namespace Aws;
SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
options.loggingOptions.logger_create_fn = GetConsoleLoggerFactory();
InitAPI(options);
{
Client::ClientConfiguration config;
config.region = Aws::Environment::GetEnv("AWS_REGION");
config.caFile = "/etc/pki/tls/certs/ca-bundle.crt";
auto credentialsProvider = Aws::MakeShared<Aws::Auth::EnvironmentAWSCredentialsProvider>(TAG);
S3::S3Client client(credentialsProvider, config);
auto handler_fn = [&client](aws::lambda_runtime::invocation_request const& req) {
return my_handler(req, client);
};
run_handler(handler_fn);
}
ShutdownAPI(options);
return 0;
}
LogLevel::Trace
to LogLevel::Debug
and any values in betweenAWS_LOGSTREAM_TRACE
to AWS_LOGSTREAM_FATAL
and any values in betweenBest,
Christian
I have successfully used Cloud9 to install my environment. Now I try to set this up using docker (amazonlinux:2018.03) and the cmake step in aws-lambda-cpp fails. I also tried adding -DCMAKE_AR=/usr/bin/ar
to explicitly name the ar path, but no change in output.
I'm not sure what's going on here.
Step 14/28 : WORKDIR /root
---> Running in 62e038ee7611
Removing intermediate container 62e038ee7611
---> 6bb1f711a657
Step 15/28 : RUN git clone https://github.com/awslabs/aws-lambda-cpp.git
---> Running in cc53b8bf9788
Cloning into 'aws-lambda-cpp'...
Removing intermediate container cc53b8bf9788
---> 7052cc1a2356
Step 16/28 : WORKDIR /root/aws-lambda-cpp
---> Running in 1b4d1b67055c
Removing intermediate container 1b4d1b67055c
---> 6f23226d2f2a
Step 17/28 : RUN mkdir build
---> Running in 76bdb4732952
Removing intermediate container 76bdb4732952
---> add60227f309
Step 18/28 : WORKDIR /root/aws-lambda-cpp/build
---> Running in bbb6d3250132
Removing intermediate container bbb6d3250132
---> 12f42a5ea1ec
Step 19/28 : RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=~/out
---> Running in 6d4d0b6d135c
-- The CXX compiler identification is GNU 6.4.1
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at CMakeLists.txt:30 (message):
Link-time optimization (LTO) is not supported: Change Dir:
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin
Run Build Command(s):/usr/bin/gmake && /usr/local/bin/cmake
-S/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/src
-B/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin
--check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin/CMakeFiles
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin/CMakeFiles/progress.marks
/usr/bin/gmake -f CMakeFiles/Makefile2 all
gmake[1]: Entering directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
/usr/bin/gmake -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/depend
gmake[2]: Entering directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
cd /root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin &&
/usr/local/bin/cmake -E cmake_depends "Unix Makefiles"
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/src
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/src
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin/CMakeFiles/foo.dir/DependInfo.cmake
Scanning dependencies of target foo
gmake[2]: Leaving directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
/usr/bin/gmake -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/build
gmake[2]: Entering directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
[ 25%] Building CXX object CMakeFiles/foo.dir/foo.cpp.o
/usr/bin/c++ -flto -fno-fat-lto-objects -o CMakeFiles/foo.dir/foo.cpp.o -c
/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/src/foo.cpp
[ 50%] Linking CXX static library libfoo.a
/usr/local/bin/cmake -P CMakeFiles/foo.dir/cmake_clean_target.cmake
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt
--verbose=1
"CMAKE_CXX_COMPILER_AR-NOTFOUND" cr libfoo.a CMakeFiles/foo.dir/foo.cpp.o
Error running link command: No such file or directory
gmake[2]: *** [libfoo.a] Error 2
gmake[2]: Leaving directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
gmake[1]: *** [CMakeFiles/foo.dir/all] Error 2
gmake[1]: Leaving directory
`/root/aws-lambda-cpp/build/CMakeFiles/_CMakeLTOTest-CXX/bin'
gmake: *** [all] Error 2
-- Found CURL: /usr/lib64/libcurl.so (found version "7.61.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /root/aws-lambda-cpp/build
Removing intermediate container 6d4d0b6d135c
---> 2786def63b3c
Step 20/28 : RUN make && make install
---> Running in 8104a61d145a
Scanning dependencies of target aws-lambda-runtime
[ 20%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/logging.cpp.o
[ 40%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/runtime.cpp.o
[ 60%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/backward.cpp.o
[ 80%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/version.cpp.o
[100%] Linking CXX static library libaws-lambda-runtime.a
[100%] Built target aws-lambda-runtime
[100%] Built target aws-lambda-runtime
Install the project...
-- Install configuration: "Release"
-- Installing: /root/out/include/aws/http/response.h
-- Installing: /root/out/include/aws/lambda-runtime/runtime.h
-- Installing: /root/out/include/aws/lambda-runtime/version.h
-- Installing: /root/out/include/aws/lambda-runtime/outcome.h
-- Installing: /root/out/include/aws/logging/logging.h
-- Installing: /root/out/lib64/libaws-lambda-runtime.a
-- Installing: /root/out/lib/aws-lambda-runtime/cmake/aws-lambda-runtime-targets.cmake
-- Installing: /root/out/lib/aws-lambda-runtime/cmake/aws-lambda-runtime-targets-release.cmake
-- Installing: /root/out/lib/aws-lambda-runtime/cmake/aws-lambda-runtime-config.cmake
-- Installing: /root/out/lib/aws-lambda-runtime/cmake/aws-lambda-runtime-config-version.cmake
-- Installing: /root/out/lib/aws-lambda-runtime/cmake/packager
Removing intermediate container 8104a61d145a
---> 63d47fb03f38
Hi,
I went through the example in the documentation. Everything goes fine, except when I enter the command "make aws-lambda-package-demo", which gives me this error:
`[100%] Built target demo
Scanning dependencies of target aws-lambda-package-demo
Failed to identify, locate or package the loader. Please file an issue on Github!
make[3]: *** [CMakeFiles/aws-lambda-package-demo.dir/build.make:57: CMakeFiles/aws-lambda-package-demo] Error 1
make[2]: *** [CMakeFiles/Makefile2:104: CMakeFiles/aws-lambda-package-demo.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/aws-lambda-package-demo.dir/rule] Error 2
make: *** [Makefile:131: aws-lambda-package-demo] Error 2
`
I'm running on Manjaro Linux 5.4.2 and have all the required dependencies installed.
Thank you!
I do development for a variety of targets (mostly Docker-based). I do my actual deployment builds on Ubuntu, but it's been really handy to be able to do test builds in my local environment which is Mac OS X.
I just started setting up a new development environment, and I pulled fresh aws-lambda-cpp
sources, and, I'm sad to report, they no longer build on OS X. The last time I pulled the code for aws-lambda-cpp
was in March, and they built fine then. That was prior to the v0.2.0 changes for stack trace support.
I realize that that OS X is not quite Linux (i.e., it's Darwin, which I believe is a BSD derivative), and that aws-lambda-cpp
is targeted at Linux. But, it would be really nice if I could at least build locally.
Looking at the aws-lambda-cpp
source, I see what look like provisions for Darwin in include/backward.h
, but they don't seem to be being used. Here's what I get when I try to build the current aws-lambda-cpp
commit:
[ 20%] Building CXX object CMakeFiles/aws-lambda-runtime.dir/src/backward.cpp.o
In file included from /Users/webb/URSA/aws-lambda-cpp/src/backward.cpp:26:
/Users/webb/URSA/aws-lambda-cpp/include/backward.h:188:22: fatal error:
'link.h' file not found
# include <link.h>
^~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/aws-lambda-runtime.dir/src/backward.cpp.o] Error 1
make[1]: *** [CMakeFiles/aws-lambda-runtime.dir/all] Error 2
make: *** [all] Error 2
I presume that this is because the compiler is being forced down the Linux path by line 46.
Commenting that line out and allowing the file to auto-detect the platform allows my build on OS X to get far enough to hit a complaint about converting size_t
to an int
in the invocation of backtrace_symbols()
in TraceResolverDarwinImpl<>::load_stacktrace()
.
If I add the same typecast there which was added to TraceResolverLinuxImpl<>::load_stacktrace()
, then the build completes.
Was there a reason for forcing the compilation down the Linux path? (E.g., does the auto-detection code not work reliably?) If not, would you be willing to accept a change to allow the code to build on OS X? (The two changes are trivial -- I could submit a pull request if you don't want to do them by hand.)
Hello Lambda team,
I have written a benchmark in C++. An equivalent of Lambda CPU Cost. It is written in C++ 17 and uses parallel execution models.
I wanted to check before creating the struts, what are the issues regarding creating C++ 17 binaries deploying on Lambda.
I recently hit this issue when working on the PR with examples for lambda.
Basically, cp command here:
/home/dpoliaru/aws-lambda/lib/aws-lambda-runtime/cmake/packager:line 139
... 139 cp --no-dereference "$i" "$PKG_DIR/lib" ...
fails with:
cp: cannot create symbolic link 'tmp/lib/libBrokenLocale.so.1': Operation not permitted
And the zip archive is not created. I simply followed intro to cpp-runtime examples.
Finally, I managed to build the archive by ommitng symbolic links being copied to tmp/lib
Here is the diff:
Post recommends using Amazon Linux, but I already had an ubuntu 19.10 vm, so decided to try it on this machine.
Please let me know whether this is an issue or I'm just missing something....
I have created an Amazon Linux 2 environment for Windows 10 WSLS using https://github.com/yosukes-dev/AmazonWSL
The environment appears fine and I successfully ran through most of the instructions on https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/
I have gcc version 7.3.1 20180712, cmake3 version 3.13.1, GNU Make 3.82
I successfully compiled the aws-lambda runtime.
Now I want to complete the last part of the sample Lambda C++ function (step 4)
The cmake3 runs without errors
-bash-4.2# cmake3 .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/out
-- The CXX compiler identification is GNU 7.3.1
-- Check for working CXX compiler: /usr/bin/gcc
-- Check for working CXX compiler: /usr/bin/gcc -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CURL: /usr/lib64/libcurl.so (found version "7.61.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/aws-lambda-cpp/build/hello-cpp-world/build
But the make shows lots of errors.
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
CMakeFiles/hello.dir/main.cpp.o: In function void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) [clone .isra.19]': main.cpp:(.text+0x51): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_create(unsigned long&, unsigned long)'
CMakeFiles/hello.dir/main.cpp.o: In function my_handler(aws::lambda_runtime::invocation_request const&)': main.cpp:(.text+0xe0): undefined reference to
operator delete(void*)'
main.cpp:(.text+0xf4): undefined reference to operator delete(void*)' main.cpp:(.text+0x114): undefined reference to
operator delete(void*)'
main.cpp:(.text+0x132): undefined reference to `operator delete(void*)'
...
Are there more up to date instructions for the page https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/
Thank you
I have a lambda function that is performs a simulation. I have an input that controls the number of simulation paths and the time taken increases linearly in the number of paths. For 2000 paths my simulation takes 35 seconds.
$ time aws lambda invoke --function-name "calculate" --payload "$(cat lambda-fail-0.json)" out.txt ; cat out.txt
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
real 0m35.258s
user 0m0.376s
sys 0m0.084s
If I double the number of simulation paths, I expected for the invocation to take about 70 seconds. I get a timeout:
$ time aws lambda invoke --function-name "calculate" --payload "$(cat lambda-fail-0.json)" out.txt ; cat out.txt
Read timeout on endpoint URL: "https://lambda.ap-southeast-2.amazonaws.com/2015-03-31/functions/gen_MC_calculate_compound/invocations"
real 5m12.670s
user 0m0.489s
sys 0m0.094s
Any advice on what is going wrong and how to further diagnose the issue would be greatly appreciated.
I am running all my tests inside an ubuntu:18.04 docker machine. I have succeeded building and running the simple C++ example from the Readme.md only returning some text.
When trying to build the s3 example (inside a newly created build directory in examples/s3)
I am getting the message below
# cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install
CMake Warning at CMakeLists.txt:6 (find_package):
By not providing "FindAWSSDK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "AWSSDK", but
CMake did not find one.
Could not find a package configuration file provided by "AWSSDK" with any
of the following names:
AWSSDKConfig.cmake
awssdk-config.cmake
Add the installation prefix of "AWSSDK" to CMAKE_PREFIX_PATH or set
"AWSSDK_DIR" to a directory containing one of the above files. If "AWSSDK"
provides a separate development package or SDK, be sure it has been
installed.
I also can't find most of the .h files in the include. Does I have to install something ?
#include <aws/core/utils/logging/LogLevel.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/core/platform/Environment.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
aws-lambda-cpp builds using the previous version of CMakeList.txt with:
target_link_libraries(${PROJECT_NAME} PRIVATE ${CURL_LIBRARIES})
And produces errors using the newly release version with:
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
The output for the second version is:
-- Configuring done
CMake Error at CMakeLists.txt:13 (add_library):
Target "aws-lambda-runtime" links to target "CURL::libcurl" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:13 (add_library):
Target "aws-lambda-runtime" links to target "CURL::libcurl" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
-- Generating done
-- Build files have been written to: /github/aws-lambda-cpp/built
I want to debug the program locally and it is suggested that we can run our code locally in Docker container. I run $ docker run -v /tmp:/tmp -it --security-opt seccomp=unconfined amazonlinux:2017.03
and then feel confused how to run my code locally in the container. Does it mean that I need to build my project inside the container, upload it to my aws lambda and trigger my lambda inside the container? Or I can just run my code inside the container? Thanks!
Sorry for writing this as an issue.
What's the best way to test the lambda locally ?
There are no materials on the internet for testing custom run-time like C++.
Hey there!
I am trying to access Amazon S3 from Lambda written in C++.
I set the role of the my lambda function to AmazonS3FullAccess.
Here's my code:
#include <string>
#include <aws/lambda-runtime/runtime.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
using namespace aws::lambda_runtime;
invocation_response my_handler(invocation_request const& request)
{
Aws::S3::S3Client s3_client;
auto outcome = s3_client.ListBuckets();
if (outcome.IsSuccess())
{
return invocation_response::success("success", "application/json");
}
else
{
std::string error = "ListBuckets error: " + outcome.GetError().GetExceptionName() + " - " + outcome.GetError().GetMessage();
return invocation_response::failure(error, "error");
}
}
int main()
{
Aws::SDKOptions options;
Aws::InitAPI(options);
{
run_handler(my_handler);
}
Aws::ShutdownAPI(options);
return 0;
}
However running the code gives me the following error response:
{
"errorMessage": "ListBuckets Error: - curlCode: 77, Problem with the SSL CA cert (path? access rights?) with address : 52.216.133.83 with address : 52.216.133.83",
"errorType": "error",
"stackTrace": []
}
Any ideas?
Hi guys!
I just writing some lambdas in c++ using the aws-lambda-cpp
i checking my log and i have this Error in my log:
[ERROR] [1553201323958] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
do you know if this is normal? because i check and debug my code but i don't found nothing.
what my lambda do is extract the body from SQS request, and make a slack post with the message.
for that i use curl and have the ssl disable
other thing is i dont see a print message that i have in the main after the
invocation_response handler(invocation_request const &req) {
return invocation_response::success();
}
this is my main:
int main() {
//use AWS namespace and libs
using namespace Aws;
//set the log for the sdk
SDKOptions options;
//init AWS API
InitAPI(options);
{
auto handler_function = [](aws::lambda_runtime::invocation_request const &req) {
return handler(req);
};
run_handler(handler_function);
}
// shutdown the aws api
std::cout << "ShutdownAPI api" << "\n";
ShutdownAPI(options);
std::cout << "exit" << "\n";
//exit
return 0;
}
i dont see the Shutdown and exit print in the cloud-watch log
so the question
the ShutdownAPI(options); and the return 0 is never called?
thank you!!!
I'm trying to embed Python in C++ using Pybind11. But my C++ program is using the AWS Lambda C++ runtime.
Everything compiles perfectly. However, when I upload the AWS Lambda package and invoke the Lambda function, it gives this error:
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Why?
So, adding NO_LIBC to aws_lambda_package_target(${PROJECT_NAME})
solved my issues. I looked into packager
and found that if NO_LIBC is not set, then PKG_LD remains empty, and generates bootstrap
file like this:
#!/bin/bash
set -euo pipefail
export AWS_EXECUTION_ENV=lambda-cpp
exec $LAMBDA_TASK_ROOT/lib/ --library-path $LAMBDA_TASK_ROOT/lib $LAMBDA_TASK_ROOT/bin/hello ${_HANDLER}
Which of course fails. Looks pretty similar to #45 , this is on Arch Linux
Is there anything obvious I should be looking for in my own project that would cause this?
versions for reference: CMake version 3.13.3, gcc 8.3.0
In function lambda_handler(aws::lambda_runtime::invocation_request const&)': : undefined reference to
aws::lambda_runtime::invocation_response::success(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
(and many others including aws::lambda_runtime::run_handler)
got the following error:
[----------] Global test environment tear-down
[==========] 318 tests from 51 test cases ran. (554 ms total)
[ PASSED ] 318 tests.
make[2]: *** [aws-cpp-sdk-core-tests/aws-cpp-sdk-core-tests] Error 1
make[2]: *** Deleting file `aws-cpp-sdk-core-tests/aws-cpp-sdk-core-tests'
make[1]: *** [aws-cpp-sdk-core-tests/CMakeFiles/aws-cpp-sdk-core-tests.dir/all] Error 2
make: *** [all] Error 2
The command '/bin/sh -c cd aws-sdk-cpp/build && make' returned a non-zero code: 2
Here is docker command:
#install cpp runtime
RUN git clone https://github.com/awslabs/aws-lambda-cpp.git
RUN cd aws-lambda-cpp && mkdir build
RUN cd aws-lambda-cpp/build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=~/out
RUN cd aws-lambda-cpp/build && make
RUN cd aws-lambda-cpp/build && make install
I'm looking to add a C++ Lambda function that also has a dependency on OpenCV.
Unclear from the documentation what needs to be done to get this working on AWS Lambda's C++ runtime
Disclaimer: I really don't know cmake the c++ build system very well
I wanted to know if it is possible to generate a single well optimized binary (as Rust or Go would) instead of what is generated here: an executable with a bunch of .so
in a separated lib/
folder.
The reason for this request is that I'm very surprised by the size of the generated archives. For the exact same functionality (a few lines of code with only one dependency to the S3 client) the c++ runtime yields a zip file of 14MB and the Rust runtime only 1.9MB...
PS: I have read the Readme section, and I'm not sure to understand, should I use Alpine to use musl libc or Amazon Linux and use provided libc ?
The following error happens when following the tutorial for aws-lambda-package-demo using Manjaro Linux. A temporary solution was found.
Failed to identify, locate or package the loader. Please file an issue on Github! make[3]: *** [CMakeFiles/aws-lambda-package-demo.dir/build.make:57: CMakeFiles/aws-lambda-package-demo] Error 1
Because Manjaro is not supported, the functions to find libc did not properly trigger, which stopped the loader from being found.
The temporary solution was to modify packager:59 and change "Arch Linux" to "Manjaro Linux". This is because Manjaro is a derivative of Arch and also has the pacman utility installed.
I am building my project inside a Docker container with an image derivative of lambci/lambda-base:build (Amazon Linux 2018.03 AMI). The compiler is a self-built GCC 9.2.0 (with libstdc++.so.6.0.27, which is included in the artefact independent of the NO_LIBC flag).
The AL AMI in AWS Lambda has only packages for GCC 4.8.5 and 7.2.0 (with libstdc++ *.19 and *.24, respectively: https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html).
With the NO_LIBC flag, I get the following bootstrap file:
#!/bin/bash
set -euo pipefail
export AWS_EXECUTION_ENV=lambda-cpp
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LAMBDA_TASK_ROOT/lib
exec $LAMBDA_TASK_ROOT/bin/myApp ${_HANDLER}
Together with the following error upon execution:
START RequestId: c63aad98-228d-4081-9475-2b7c884b00e6 Version: $LATEST
/var/task/bin/myApp: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /var/task/lib/libaws-cpp-sdk-core.so)
END RequestId: c63aad98-228d-4081-9475-2b7c884b00e6
REPORT RequestId: c63aad98-228d-4081-9475-2b7c884b00e6 Duration: 288.41 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 15 MB
RequestId: c63aad98-228d-4081-9475-2b7c884b00e6 Error: Runtime exited with error: exit status 1
Runtime.ExitError
Without the flag, I get:
#!/bin/bash
set -euo pipefail
export AWS_EXECUTION_ENV=lambda-cpp
exec $LAMBDA_TASK_ROOT/lib/ld-linux-x86-64.so.2 --library-path $LAMBDA_TASK_ROOT/lib $LAMBDA_TASK_ROOT/bin/myApp ${_HANDLER}
and a passing Lambda function.
Now, if I overwrite the bootstrap file in case #1 with the one produced for case #2 (while still only shipping the reduced set of libs from case #1), the Lambda function also passes.
Can we somehow enable this behaviour for compilers with newer standard C++ library implementations?
Thanks and best,
Thomas
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.