项目作者: anmonteiro

项目描述 :
An OCaml custom runtime for AWS Lambda
高级语言: OCaml
项目地址: git://github.com/anmonteiro/aws-lambda-ocaml-runtime.git
创建时间: 2018-12-01T21:03:23Z
项目社区:https://github.com/anmonteiro/aws-lambda-ocaml-runtime

开源协议:BSD 3-Clause "New" or "Revised" License

下载


OCaml Runtime for AWS Lambda

This package provides a custom
runtime
for
AWS Lambda.

Installation

This repository provides two libraries:

  • lambda-runtime provides a runtime and API for
    AWS Lambda and
    API Gateway.
  • the vercel library depends on lambda-runtime and provides an interface to
    the Vercel service that resembles a request / response
    exchange.

The libraries in this repo are released to the OPAM package registry.

You can depend on them via:

  1. esy: esy add @opam/lambda-runtime and / or esy add @opam/vercel
  2. OPAM: opam install lambda-runtime vercel.

Example function

See the examples folder.

Deploying

Note: Based on the instructions in this blog
post
and
the Rust custom runtime
repository

For a custom runtime, AWS Lambda looks for an executable called bootstrap in
the deployment package zip. Rename the generated basic executable to
bootstrap and add it to a zip archive.

The Dockerfile (in conjunction with the build.sh script) in this
repo does just that. It builds a static binary called bootstrap and drops it
in the target directory.

  1. $ ./build.sh && zip -j ocaml.zip bootstrap

Now that we have a deployment package (ocaml.zip), we can use the AWS
CLI
to create a new Lambda function. Make sure to
replace the execution role with an existing role in your account!

  1. $ aws lambda create-function --function-name OCamlTest \
  2. --handler doesnt.matter \
  3. --zip-file file://./ocaml.zip \
  4. --runtime provided \
  5. --role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \
  6. --tracing-config Mode=Active

You can now test the function using the AWS CLI or the AWS Lambda console

  1. $ aws lambda invoke --function-name OCamlTest \
  2. --payload '{"firstName": "world"}' \
  3. output.json
  4. $ cat output.json # Prints: {"message":"Hello, world!"}

Copyright © 2018 António Nuno Monteiro

Distributed under the 3-clause BSD License (see LICENSE).