Giter VIP home page Giter VIP logo

aws-lambda-to-api-gateway's Introduction

AWS C++ Lambda & API Gateway

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.

Prerequisites

  1. CMake (version 3.15 or later)
  2. git
  3. Make or Ninja
  4. zip
  5. libcurl-devel

Build the AWS Lambda SDK

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

Build the AWS C++ SDK

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

Build the Runtime

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

Build the application

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.

First Commit Your Code

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

Update Code

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

aws-lambda-to-api-gateway's People

Contributors

nickfox-taterli avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.