### Install AWS Lambda Runtime Interface Emulator (RIE)
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/README.md
Installs the RIE on your local machine for testing container image Lambda functions. Ensure you have curl and chmod available.
```shell
mkdir -p ~/.aws-lambda-rie && \
curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
chmod +x ~/.aws-lambda-rie/aws-lambda-rie
```
--------------------------------
### Build and Install AWS Lambda C++ Runtime
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/README.md
Commands to clone the repository, build, and install the runtime library on a GNU/Linux system. Ensure CMake version 3.9 or later is installed.
```bash
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
```
--------------------------------
### Load SNSEvent using EventLoader
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-tests/README.md
Illustrates loading an SNSEvent from a JSON file using the EventLoader utility. This is beneficial for custom test setups.
```java
SNSEvent snsEvent = EventLoader.loadSNSEvent("sns_event.json");
```
--------------------------------
### Build Lambda Application
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/s3/README.md
Compiles the Lambda function written in C++ and packages it into a zip file ready for deployment. It uses CMake to configure the build and specifies the installation prefix for dependencies.
```bash
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install
make
make aws-lambda-package-encoder
```
--------------------------------
### Build AWS C++ SDK
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/api-gateway/README.md
Builds the AWS C++ SDK from source, focusing on the 'core' component and disabling shared libraries for a static build. Installs the SDK to a specified prefix.
```bash
mkdir ~/install
git clone https://github.com/aws/aws-sdk-cpp.git
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 \
-DCMAKE_INSTALL_PREFIX=~/install \
-DENABLE_UNITY_BUILD=ON
make
make install
```
--------------------------------
### Build Lambda Application
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/dynamodb/README.md
Compiles the Lambda function code located in main.cpp and packages it into a deployable zip file. It uses CMake to configure the build, referencing the previously installed SDK and runtime.
```bash
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install
$ make
$ make aws-lambda-package-ddb-demo
```
--------------------------------
### Build Lambda Application and Package
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/api-gateway/README.md
Compiles the C++ Lambda function and packages it for deployment. This involves CMake configuration using the installed SDK and runtime, followed by a make command to create the deployment package.
```bash
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install
make
make aws-lambda-package-api
```
--------------------------------
### CMakeLists.txt for AWS Lambda C++ Example
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/api-gateway/CMakeLists.txt
This CMakeLists.txt file configures a C++ project for AWS Lambda. It specifies the minimum CMake version, C++ standard, project name, and finds the necessary AWS Lambda runtime and SDK components. It then adds an executable target, links the required libraries, and packages the target for Lambda deployment.
```cmake
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(api LANGUAGES CXX)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS core)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-lambda-runtime ${AWSSDK_LINK_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
```
--------------------------------
### Java Lambda Handler Example
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/README.md
A simple Java class demonstrating a Lambda function handler. This class provides a 'sayHello' method that returns a greeting string.
```java
package example;
public class App {
public static String sayHello() {
return "Hello λ!";
}
}
```
--------------------------------
### Run Automated Local Tests
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/README.md
Executes automated tests for the runtime interface client, including RIE setup, dependency management, and Docker orchestration. Ensure prerequisites like Maven and Docker are met.
```shell
make test-rie
```
--------------------------------
### Build C++ Lambda Runtime
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/dynamodb/README.md
Clones and builds the AWS C++ Lambda runtime, configuring it for release and specifying an installation prefix. This runtime is necessary for deploying C++ Lambda functions.
```bash
$ git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git
$ cd aws-lambda-cpp-runtime
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=~/install
$ make
$ make install
```
--------------------------------
### Load APIGatewayProxyRequestEvent using EventLoader
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-tests/README.md
Demonstrates using EventLoader to manually load an APIGatewayProxyRequestEvent from a JSON file. Useful for custom test setups or when annotations are not used.
```java
APIGatewayProxyRequestEvent restEvent =
EventLoader.loadApiGatewayRestEvent("apigw_rest_event.json");
```
--------------------------------
### Build AWS C++ SDK
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/dynamodb/README.md
Builds the AWS C++ SDK, specifying only the DynamoDB module and configuring build options for release, shared libraries, unity build, and installation prefix.
```bash
$ mkdir ~/install
$ git clone https://github.com/aws/aws-sdk-cpp.git
$ cd aws-sdk-cpp
$ mkdir build
$ cd build
$ cmake .. -DBUILD_ONLY="dynamodb" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DENABLE_UNITY_BUILD=ON \
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
-DCMAKE_INSTALL_PREFIX=~/install \
-DENABLE_UNITY_BUILD=ON
$ make -j 4
$ make install
```
--------------------------------
### Run Lambda Container Image with RIE Locally
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/README.md
Runs your Lambda function packaged as a container image locally using Docker and the RIE. This command starts an endpoint at http://localhost:9000/2015-03-31/functions/function/invocations.
```shell
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \
--entrypoint /aws-lambda/aws-lambda-rie \
myfunction:latest \
/usr/bin/java -cp './*' com.amazonaws.services.lambda.runtime.api.client.AWSLambda example.App::sayHello
```
--------------------------------
### Build AWS C++ SDK
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/s3/README.md
Builds the AWS C++ SDK, focusing only on the S3 module, with specific configurations for release type, shared libraries, memory management, installation prefix, and unity build.
```bash
mkdir ~/install
git clone https://github.com/aws/aws-sdk-cpp.git
cd aws-sdk-cpp
mkdir build
cd build
cmake .. -DBUILD_ONLY="s3" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
-DCMAKE_INSTALL_PREFIX=~/install \
-DENABLE_UNITY_BUILD=ON
make
make install
```
--------------------------------
### Integrate AWS Lambda Runtime with CMake Project
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/README.md
CMake configuration to find and link the aws-lambda-runtime library to your executable. This setup is for projects that also use CMake.
```cmake
cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 11)
project(demo LANGUAGES CXX)
find_package(aws-lambda-runtime)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-lambda-runtime)
target_compile_features(${PROJECT_NAME} PRIVATE "cxx_std_11")
target_compile_options(${PROJECT_NAME} PRIVATE "-Wall" "-Wextra")
# this line creates a target that packages your binary and zips it up
aws_lambda_package_target(${PROJECT_NAME})
```
--------------------------------
### Build AWS C++ Lambda Runtime
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-runtime-interface-client/src/main/jni/deps/aws-lambda-cpp-0.2.7/examples/api-gateway/README.md
Clones and builds the AWS C++ Lambda runtime. This process involves CMake configuration for a Release build with static libraries and installation to a specified prefix.
```bash
git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git
cd aws-lambda-cpp-runtime
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=~/install
make
make install
```
--------------------------------
### Log4j2 Configuration for AWS Lambda
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/aws-lambda-java-log4j2/README.md
Configure log4j2.xml to define appenders and loggers. This example sets up a Lambda appender that can format logs as TEXT or JSON based on the AWS_LAMBDA_LOG_FORMAT environment variable.
```xml
%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n
```
--------------------------------
### Implement Java Lambda Request Handler
Source: https://github.com/aws/aws-lambda-java-libs/blob/main/README.md
Use this interface for Lambda functions that process simple request/response models. No specific setup is required beyond including the aws-lambda-java-core dependency.
```java
public class Handler implements RequestHandler