• Stars
    star
    192
  • Rank 196,508 (Top 4 %)
  • Language
    Erlang
  • License
    Other
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AWS Lambda in Erlang

erllambda

Enable AWS Lambda functions to be written in Erlang

logo

Overview

The erllambda library provides all functionality needed to build and deploy fully functional AWS Lambda functions, written entirely in Erlang.

Erlang Lambda functions implement a simple two function behavior:

-module(hello_lambda).

-behavior(erllambda).
-export([handle/2]).

-spec handle( Event :: map(), Context :: map() ) -> {ok, Body} | {error, ErrorBody}.
handle( Event, Context ) ->
    erllambda:succeed( "Hello Event ~p", [Event] ).

There are really two ways to get started. First you can checkout and review the erllambda_example project. This is a complete working AWS Lambda written in Erlang, with the goal of demonstrating the capabilities available as part of the framework, and how to write Lambda functions for different purposes in AWS.

The second path is to use the rebar3_erllambda plugin for rebar3. This will produce a fully working erllambda project that can be used as a starting point for any new development. This plugin also implements additional rebar3 erllambda zip building and AWS Lambda function packaging that simplify development.

More detailed information about developing Lambda functions using erllambda can be found in:

Ownership

The erllambda application and its supporting libraries are primarily owned by motobob and velimir

Dependencies

The erllambda application is built using rebar3, and all other dependencies are automatically pulled in when erllambda is used in other projects rebar.config.

The following are used as part of the Erlang/Elixir package for AWS Lambda:

Initial setup, compilation and testing

TLDR; as long as your basic Erlang environment is setup, getting started developing erllambda should be as easy as forking the repo, and then:

git clone [email protected]:${USER}/erllambda.git
cd erllambda
git remote add upstream [email protected]:alertlogic/erllambda.git
rebar3 compile 
rebar3 ct
rebar3 erllambda zip

Packaging and Deployment

There are two key points about running Erlang AWS Lambda functions:

OpenSSL version

Important notice: at this moment AWS Lambda native runtime has openssl 1.0.1k while latest linux systems have 1.0.2 or even 1.1.1.. See AWS Lambda

To be able to run Erlang Lambda functions in AWS Lambda it is vital to package your SW with Erlang built against openssl 1.0.1. You will want to setup DockerMachine and utilize the erllambda_docker repo for this purpose. This will allow you to perform release builds for erllambda based components directly from the command line.

Users can have their own Erlang dockers and have those with statically linked preferred openssl versions. However statically linking for base libraries is discouraged.

Lambda Memory Size

Current testing has shown that it does not make sense to run Erlang on AWS Lambda functions with less then 256MB RAM. Having 512-1024MB is optimal for most of the use cases.

Configuration

Code loading mode

Depending on a use case, erlang code loading mode can significantly affect execution performance.

To switch between interactive or embedded modes set CODE_LOADING_MODE environment variable on AWS Lambda function creation step with a desired value:

aws --profile default --region <region> \
 lambda create-function \
 --function-name <your_function> \
 --memory-size 1024 \
 --handler <your_function_module_name> \
 --zip-file fileb://_build/prod/<your_function>-0.0.0.zip \
 --environment "Variables={CODE_LOADING_MODE=interactive}"
 --runtime provided \
 --role <role-arn>

Basic Deployment

See Erllambda Example for the step-by-step procedure to deploy your Lambda. It boils down to following steps:

  • compile and build a prod profile release of your application.
rebar3 erllambda zip
  • create your AWS Lambda function
aws --profile default --region <region> \ 
 lambda create-function \
 --function-name <your_function> \
 --memory-size 1024 \
 --handler <your_function_module_name> \
 --zip-file fileb://_build/prod/<your_function>-0.0.0.zip \ 
 --runtime provided \
 --role <role-arn>
  • or update your previously deployed AWS Lambda function
aws --profile default --region <region> \ 
 lambda update-function-code /
 --function-name <your_function> \
 --zip-file fileb://_build/prod/<your_function>-0.0.0.zip
  • and invoke it
aws --profile default --region <region> \
 lambda invoke  --function-name <your_function> \
  --log-type Tail \
  --payload '{"msg": "hello"}' \
  outputfile.txt

It is however recommended to use CloudFormation based approach described in rebar3_erllambda

How to contribute

Contributions to this repo are always welcome. If you have an idea for improving the this or related components, please submit a github issue, or simply submit a PR directly that implements your improvement.

For complex changes, or the introduction of a major feature, it is beneficial to discuss ideas before implementing them, so that your efforts can focus on pull requests that will be accepted more easily.

As you prepare your pull request, make sure that you follow the coding conventions that exist in the files, and always make sure that all unit and common tests run. Please ensure that your contribution always adds to the coverage percentage, and does not decrease it.

How to report defects

If you encounter an problem, or simply have a question about using this repo, please submit a github issue.

More Repositories

1

mix_erllambda

Erllambda support for Elixir
Elixir
44
star
2

erllambda_elixir_example

Elixir
31
star
3

cloudwatch-logs-s3-export

Reliable export of the CloudWatch logs to an S3 bucket
JavaScript
25
star
4

al-agent-container

Alert Logic Agent for Docker Environments
Mustache
16
star
5

rebar3_erllambda

Rebar3 Plugin for building & deploying AWS Lambda functions implemented in Erllambda
Erlang
15
star
6

al-cloudformation-templates

Alert Logic AWS CloudFormation Templates
14
star
7

cwe-collector

AWS CloudWatch Events Collector
JavaScript
12
star
8

al-agents-ansible-playbooks

Ansible Playbooks to install and provision the Alert Logic Unified Agent
10
star
9

erllambda_example

Erlang
8
star
10

erllambda_docker

Erllambda support docker image
Dockerfile
8
star
11

al_agents

Alert Logic Agent Cookbook
Ruby
8
star
12

ci_lambda_checks

Cloud Insight Checks for AWS Lambda
JavaScript
7
star
13

ci_jira

Cloud Insight Jira Plug In
JavaScript
5
star
14

alertlogic-sdk-python

Alert Logic Software Development Kit for Python
Python
4
star
15

alcli

The Alert Logic Command Line Utility (CLI)
Python
3
star
16

alertlogic-sdk-definitions

Alert Logic APIs definitions
HTML
3
star
17

aws-manual-deployment

Collection of Terraform modules to manually deploy Vulnerability Scanning and IDS required infrastructure into an existing customer managed subnet in AWS.
HCL
3
star
18

paws-collector

Under Construction!!!
JavaScript
2
star
19

alertlogic-cli

Command Line Client for Alert Logic Services
Python
2
star
20

ehub-collector

Alert Logic Azure Event Hub Integration
JavaScript
2
star
21

azure-collector

Alert Logic Azure Collector
JavaScript
2
star
22

erllambda_sam_example

Erlang
2
star
23

nepal-client-libs

A collection of Node Enterprise Packages for Alert Logic (NEPAL) client libraries.
TypeScript
2
star
24

alertlogic-agents

Alert Logic, Inc. Agent Puppet Module
Ruby
2
star
25

al_ui_template

Template for Angular UI projects
JavaScript
1
star
26

lita-alertlogic

Alert Logic plugin for Lita
Ruby
1
star
27

al-arm-templates

Alert Logic Azure Resource Manager Templates
1
star
28

al-aws-access-analyzer-collector

Alert Logic Collector for AWS Identity and Access Management (IAM) Access Analyzer Findings
Python
1
star
29

ci_setup_cloudtrail

Python
1
star
30

al-azure-collector-js

JavaScript
1
star
31

al-collector-js

JavaScript
1
star