Skip to content

Commit 2e1aa03

Browse files
committed
Minor edits in the READMEs along with updated CMake commands
- In the AWS C++ SDK `ENABLE_UNITY_BUILD` now defaults to `ON` - Expose the CMake `BUILD_SHARED_LIBS` flag as a configurable option
1 parent 095ff84 commit 2e1aa03

File tree

6 files changed

+53
-37
lines changed

6 files changed

+53
-37
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(aws-lambda-runtime
66

77
option(ENABLE_LTO "Enables link-time optimization, requires compiler support." ON)
88
option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF)
9+
option(BUILD_SHARED_LIBS "Enables building using shared libraries" OFF)
910

1011
add_library(${PROJECT_NAME}
1112
"src/logging.cpp"

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![GitHub](https://img.shields.io/github/license/awslabs/aws-lambda-cpp.svg)](https://github.com/awslabs/aws-lambda-cpp/blob/master/LICENSE)
22
![CodeBuild](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiQkN1b0srbWtnUjNibFVyL2psNmdaM0l4RnVQNzVBeG84QnQvUjRmOEJVdXdHUXMxZ25iWnFZQUtGTkUxVGJhcGZaVEhXY2JOSTFHTlkvaGF2RDRIZlpVPSIsIml2UGFyYW1ldGVyU3BlYyI6IjRiS3hlRjFxVFZHSWViQmQiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
33
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/awslabs/aws-lambda-cpp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-lambda-cpp/context:cpp)
4+
45
## AWS Lambda C++ Runtime
56

67
C++ implementation of the lambda runtime API
@@ -14,13 +15,15 @@ Since AWS Lambda runs on GNU/Linux, you should build this runtime library and yo
1415

1516
### Prerequisites
1617
Make sure you have the following packages installed first:
18+
1719
1. CMake (version 3.9 or later)
1820
1. git
1921
1. Make or Ninja
2022
1. zip
2123
1. libcurl-devel (on Debian-basded distros it's libcurl4-openssl-dev)
2224

2325
In a terminal, run the following commands:
26+
2427
```bash
2528
$ git clone https://github.com/awslabs/aws-lambda-cpp.git
2629
$ cd aws-lambda-cpp
@@ -42,11 +45,15 @@ target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-lambda-runtime)
4245
target_compile_features(${PROJECT_NAME} PRIVATE "cxx_std_11")
4346
target_compile_options(${PROJECT_NAME} PRIVATE "-Wall" "-Wextra")
4447
45-
# this line creates a target that packages your binary and zips it up
48+
#
49+
# This line creates a target that packages your binary along with its shared dependencies
50+
# as a zip file ready for deployment
51+
#
4652
aws_lambda_package_target(${PROJECT_NAME})
4753
```
4854

4955
And here is how a sample `main.cpp` would look like:
56+
5057
```cpp
5158
#include <aws/lambda-runtime/runtime.h>
5259

@@ -78,6 +85,7 @@ $ cd build
7885
$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/lambda-install
7986
$ make
8087
$ make aws-lambda-package-demo
88+
8189
```
8290
The last command above `make aws-lambda-package-demo` will create a zip file called `demo.zip` in the current directory.
8391

@@ -101,6 +109,7 @@ $ cat trust-policy.json
101109
}
102110
103111
```
112+
104113
Then create the IAM role:
105114

106115
```bash
@@ -110,6 +119,7 @@ $ aws iam create-role --role-name lambda-demo --assume-role-policy-document file
110119
Note down the role Arn returned to you after running that command. We'll need it in the next steps:
111120

112121
Attach the following policy to allow Lambda to write logs in CloudWatch:
122+
113123
```bash
114124
$ aws iam attach-role-policy --role-name lambda-demo --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
115125
```
@@ -118,14 +128,15 @@ Make sure you attach the appropriate policies and/or permissions for any other A
118128

119129
And finally, create the Lambda function:
120130

121-
```
131+
```bash
122132
$ aws lambda create-function --function-name demo \
123-
--role <specify role arn from previous step here> \
124-
--runtime provided --timeout 15 --memory-size 128 \
125-
--handler demo --zip-file fileb://demo.zip
133+
--role <specify role arn from previous step here> \
134+
--runtime provided --timeout 15 --memory-size 128 \
135+
--handler demo --zip-file fileb://demo.zip
126136
```
127137

128138
And to invoke the function:
139+
129140
```bash
130141
$ aws lambda invoke --function-name demo --payload '{"answer":42}' output.txt
131142
```
@@ -152,6 +163,7 @@ This can be done by passing the `NO_LIBC` flag in CMake as follows:
152163
```cmake
153164
aws_lambda_package_target(${PROJECT_NAME} NO_LIBC)
154165
```
166+
155167
### Common Pitfalls with Packaging
156168

157169
* Any library dependency your Lambda function has that is dynamically loaded via `dlopen` will NOT be automatically packaged. You **must** add those dependencies manually to the zip file.
@@ -164,12 +176,15 @@ For example, if you are using the AWS C++ SDK, it's best to set the following co
164176
Aws::Client::ClientConfiguration config;
165177
config.caFile = "/etc/pki/tls/certs/ca-bundle.crt";
166178
```
179+
167180
If you are not using the AWS C++ SDK, but happen to be using libcurl directly, you can set the CA bundle location by doing:
181+
168182
```c
169183
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, "/etc/pki/tls/certs/ca-bundle.crt");
170184
```
171185
172186
## FAQ & Troubleshooting
187+
173188
1. **Why is the zip file so large? what are all those files?**
174189
Typically, the zip file is large because we have to package the entire C standard library.
175190
You can reduce the size by doing some or all of the following:

ci/codebuild/build-cpp-sdk.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ set -euo pipefail
66
cd /aws-sdk-cpp
77
mkdir build
88
cd build
9-
cmake .. -GNinja -DBUILD_ONLY="lambda" \
9+
cmake .. -GNinja \
10+
-DBUILD_ONLY="lambda" \
1011
-DCMAKE_BUILD_TYPE=Release \
11-
-DENABLE_UNITY_BUILD=ON \
1212
-DBUILD_SHARED_LIBS=ON \
1313
-DENABLE_TESTING=OFF \
1414
-DCMAKE_INSTALL_PREFIX=/install $@

examples/api-gateway/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Example using the AWS C++ Lambda runtime and Amazon API Gateway
22

3-
In this example, we'll build a simple "Hello, World" lambda function that can be invoked using an api endpoint created using Amazon API gateway. This example can be viewed as the C++ counterpart to the NodeJS "Hello, World" API example as viewed [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html). At the end of this example, you should be able to invoke your lambda via an api endpoint and receive a raw JSON response. This example employs the use of the AWS C++ SDK to parse the request and write the necessary response.
4-
3+
In this example, we'll build a simple "Hello, World" lambda function that can be invoked using an api endpoint created using Amazon API gateway. This example can be viewed as the C++ counterpart to the NodeJS "Hello, World" API example as viewed [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html). At the end of this example, you should be able to invoke your lambda via an api endpoint and receive a raw JSON response. This example employs the use of the AWS C++ SDK to parse the request and write the necessary response.
4+
55
## Build the AWS C++ SDK
6-
Start by building the SDK from source.
6+
Start by building the AWS C++ SDK from source:
77

88
```bash
99
$ mkdir ~/install
@@ -15,29 +15,28 @@ $ cmake .. -DBUILD_ONLY="core" \
1515
-DCMAKE_BUILD_TYPE=Release \
1616
-DBUILD_SHARED_LIBS=OFF \
1717
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
18-
-DCMAKE_INSTALL_PREFIX=~/install \
19-
-DENABLE_UNITY_BUILD=ON
18+
-DCMAKE_INSTALL_PREFIX=~/install
2019
$ make
2120
$ make install
2221
```
2322

2423
## Build the Runtime
25-
We need to build the C++ Lambda runtime as outlined in the other examples.
24+
We need to build the C++ Lambda runtime as outlined in the other examples:
2625

2726
```bash
2827
$ git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git
2928
$ cd aws-lambda-cpp-runtime
3029
$ mkdir build
3130
$ cd build
32-
$ cmake .. -DCMAKE_BUILD_TYPE=Release \
33-
-DBUILD_SHARED_LIBS=OFF \
34-
-DCMAKE_INSTALL_PREFIX=~/install \
31+
$ cmake .. \
32+
-DCMAKE_BUILD_TYPE=Release \
33+
-DCMAKE_INSTALL_PREFIX=~/install
3534
$ make
3635
$ make install
3736
```
3837

3938
## Build the application
40-
The next step is to build the Lambda function in `main.cpp` and run the packaging command as follows:
39+
The next step is to build the Lambda function in `main.cpp` and run the packaging script as follows:
4140

4241
```bash
4342
$ mkdir build
@@ -62,18 +61,19 @@ For the rest of this example, we will use the AWS Management Console to create t
6261
1. Once you have added the API gateway, locate the newly created endpoint. View how to test the endpoint below.
6362

6463
## Test the endpoint
65-
Feel free to test the endpoint any way you desire. Below is a way to test using cURL:
64+
Test the endpoint:
6665

67-
```
66+
```bash
6867
curl -v -X POST \
6968
'<YOUR-API-ENDPOINT>?name=Bradley&city=Chicago' \
7069
-H 'content-type: application/json' \
7170
-H 'day: Sunday' \
7271
-d '{ "time": "evening" }'
7372
```
7473

75-
With the expected response being:
76-
```
74+
With the expected response being:
75+
76+
```json
7777
{
7878
"message": "Good evening, Bradley of Chicago. Happy Sunday!"
7979
}

examples/dynamodb/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ To also show case how this can be done on a Linux distro other than Amazon Linux
66
That being said, the instructions below should work on any Linux distribution.
77

88
## Build the AWS C++ SDK
9-
Start by building the SDK from source.
9+
Start by building the AWS C++ SDK from source:
10+
1011
```bash
1112
$ mkdir ~/install
1213
$ git clone https://github.com/aws/aws-sdk-cpp.git
1314
$ cd aws-sdk-cpp
1415
$ mkdir build
1516
$ cd build
16-
$ cmake .. -DBUILD_ONLY="dynamodb" \
17+
$ cmake .. \
18+
-DBUILD_ONLY="dynamodb" \
1719
-DCMAKE_BUILD_TYPE=Release \
1820
-DBUILD_SHARED_LIBS=OFF \
1921
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
20-
-DCMAKE_INSTALL_PREFIX=~/install \
21-
-DENABLE_UNITY_BUILD=ON
22-
22+
-DCMAKE_INSTALL_PREFIX=~/install
2323
$ make -j 4
2424
$ make install
2525
```
@@ -32,15 +32,15 @@ $ git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git
3232
$ cd aws-lambda-cpp-runtime
3333
$ mkdir build
3434
$ cd build
35-
$ cmake .. -DCMAKE_BUILD_TYPE=Release \
36-
-DBUILD_SHARED_LIBS=OFF \
35+
$ cmake .. \
36+
-DCMAKE_BUILD_TYPE=Release \
3737
-DCMAKE_INSTALL_PREFIX=~/install \
3838
$ make
3939
$ make install
4040
```
4141

4242
## Build the application
43-
The last step is to build the Lambda function in `main.cpp` and run the packaging command as follows:
43+
The last step is to build the Lambda function in `main.cpp` and run the packaging script as follows:
4444

4545
```bash
4646
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install

examples/s3/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ To also show case how this can be done on a Linux distro other than Amazon Linux
66
That being said, the instructions below should work on any Linux distribution.
77

88
## Build the AWS C++ SDK
9-
Start by building the SDK from source.
9+
Start by building the AWS C++ SDK from source:
10+
1011
```bash
1112
$ mkdir ~/install
1213
$ git clone https://github.com/aws/aws-sdk-cpp.git
1314
$ cd aws-sdk-cpp
1415
$ mkdir build
1516
$ cd build
16-
$ cmake .. -DBUILD_ONLY="s3" \
17+
$ cmake .. \
18+
-DBUILD_ONLY="s3" \
1719
-DCMAKE_BUILD_TYPE=Release \
1820
-DBUILD_SHARED_LIBS=OFF \
1921
-DCUSTOM_MEMORY_MANAGEMENT=OFF \
20-
-DCMAKE_INSTALL_PREFIX=~/install \
21-
-DENABLE_UNITY_BUILD=ON
22-
22+
-DCMAKE_INSTALL_PREFIX=~/install
2323
$ make
2424
$ make install
2525
```
@@ -32,15 +32,15 @@ $ git clone https://github.com/awslabs/aws-lambda-cpp-runtime.git
3232
$ cd aws-lambda-cpp-runtime
3333
$ mkdir build
3434
$ cd build
35-
$ cmake .. -DCMAKE_BUILD_TYPE=Release \
36-
-DBUILD_SHARED_LIBS=OFF \
35+
$ cmake .. \
36+
-DCMAKE_BUILD_TYPE=Release \
3737
-DCMAKE_INSTALL_PREFIX=~/install \
3838
$ make
3939
$ make install
4040
```
4141

4242
## Build the application
43-
The last step is to build the Lambda function in `main.cpp` and run the packaging command as follows:
43+
The last step is to build the Lambda function in `main.cpp` and run the packaging script as follows:
4444

4545
```bash
4646
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=~/install

0 commit comments

Comments
 (0)