We'll build a Lambda function that can be used as an API Gateway proxy to echo your input parameters from HTTP GET request.
That being said, the instructions below should work on any Linux distribution.
- CMake (version 3.15 or later)
- git
- Make or Ninja
- zip
- libcurl-devel
In a terminal, run the following commands:
$ git clone https://github.com/awslabs/aws-lambda-cpp.git --depth=1
$ cd aws-lambda-cpp
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/aws_library
$ make && make install
Start by building the SDK from source.
$ git clone https://github.com/aws/aws-sdk-cpp.git --depth=1
$ cd aws-sdk-cpp
$ mkdir build
$ cd build
$ cmake .. -DBUILD_ONLY="core" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DENABLE_UNITY_BUILD=ON \
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
-DENABLE_UNITY_BUILD=ON \
-DCMAKE_INSTALL_PREFIX=~/aws_library
$ make -j 4
$ sudo make install
Now let's build the C++ Lambda runtime, so in a separate directory clone this repository and follow these steps:
$ git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git --depth=1
$ cd aws-lambda-cpp-runtime
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=~/aws_library
$ make
$ sudo make install
The last step is to build the Lambda function in main.cpp
and run the packaging command as follows:
$ git clone https://github.com/nickfox-taterli/aws-lambda-to-api-gateway --depth=1
$ cd aws-lambda-to-api-gateway
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/aws_library
$ make
$ make aws-lambda-package-demo
You should now have a zip file called demo.zip
.
Make sure you attach the appropriate policies and/or permissions for any other AWS services that you plan on using.
Then,create the Lambda function:
$ aws lambda create-function --function-name demo \
--role <specify role arn here> \
--runtime provided --timeout 15 --memory-size 128 \
--handler demo --zip-file fileb://demo.zip
Make sure you attach the appropriate policies and/or permissions for any other AWS services that you plan on using.
Then,create the Lambda function:
$ aws lambda update-function-code --function-name demo \
--zip-file fileb://demo.zip