cpp/example_code/lambda/cpp_lambda/README.md
Shows how to build and package an AWS Lambda function using the AWS C++ Lambda runtime. This function can replace the Python Lambda function used in the Get started with functions scenario sample code.
The Lambda function is built and packaged using Docker.
Docker is needed to build and package the Lambda function. The Docker website contains installation instructions.
This sample code contains a DockerFile which is used to build the Docker image. Using a shell application, navigate to the folder containing this README.
Then enter the following command:
docker build . -f Dockerfile -t cpp_lambda_image
Now run the Docker image as a container using the following command:
docker run -i -t --name cpp_lambda --mount type=bind,source="$(pwd)",target=/cpp_lambda cpp_lambda_image bash
Your command line should now be running from within the Docker container. The preceding run command should have bound the directory containing this README to the Docker container.
Test whether the host directory is correctly bound by entering the following command:
ls /cpp_lambda
You should see the contents of this README's directory.
Dockerfile README.md calculator increment
Now build the two Lambda functions used by the sample code. Because the Docker container is bound to the directory containing
this README, the source code can be accessed within the container at /cpp_lambda.
Note: The AWS Lambda C++ Runtime is required for the next steps. It was installed when the Docker image was built.
cd /cpp_lambda/increment && \
mkdir build && \
cd build && \
cmake3 .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install && \
make && \
make aws-lambda-package-cpp_lambda_increment
cd /cpp_lambda/calculator && \
mkdir build && \
cd build && \
cmake3 .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install && \
make && \
make aws-lambda-package-cpp_lambda_calculator
These build steps have generated two zip files which will be used by the sample code in Get started with functions.
These files are referenced in the following section of code:
#if USE_CPP_LAMBDA_FUNCTION
static Aws::String LAMBDA_HANDLER_NAME(
"cpp_lambda_calculator");
static Aws::String INCREMENT_LAMBDA_CODE(
SOURCE_DIR "cpp_lambda/increment/build/cpp_lambda_increment.zip");
static Aws::String CALCULATOR_LAMBDA_CODE(
SOURCE_DIR "cpp_lambda/calculator/build/cpp_lambda_calculator.zip");
#else
Finally, in the source file get_started_with_functions_scenario.cpp, set the preprocessor constant USE_CPP_LAMBDA_FUNCTION to 1.
#define USE_CPP_LAMBDA_FUNCTION 1