All Projects → mkotsur → Aws Lambda Scala

mkotsur / Aws Lambda Scala

Licence: mit
Writing AWS Lambdas in Scala

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Aws Lambda Scala

Chalice
Python Serverless Microframework for AWS
Stars: ✭ 8,513 (+6205.93%)
Mutual labels:  serverless, cloud, aws-lambda
Node Lambda Log
Basic logging mechanism for Node 6.10+ Lambda Functions
Stars: ✭ 115 (-14.81%)
Mutual labels:  serverless, cloud, aws-lambda
Awesome Layers
λ A curated list of awesome AWS Lambda Layers. Sponsored by https://cloudash.dev
Stars: ✭ 1,655 (+1125.93%)
Mutual labels:  serverless, cloud, aws-lambda
Dialetus Service
API to Informal dictionary for the idiomatic expressions that each Brazilian region It has
Stars: ✭ 202 (+49.63%)
Mutual labels:  serverless, aws-lambda, json
Aws Auto Cleanup
Open-source application to programmatically clean your AWS resources based on a whitelist and time to live (TTL) settings
Stars: ✭ 276 (+104.44%)
Mutual labels:  serverless, cloud, aws-lambda
Serverlessbydesign
A visual approach to serverless development. Think. Build. Repeat.
Stars: ✭ 254 (+88.15%)
Mutual labels:  serverless, cloud, aws-lambda
Portkey
Live-coding the Cloud
Stars: ✭ 139 (+2.96%)
Mutual labels:  serverless, cloud, aws-lambda
Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+3506.67%)
Mutual labels:  serverless, cloud, aws-lambda
Tensorflow Lambda Layer
Lets you import Tensorflow + Keras from an AWS lambda
Stars: ✭ 79 (-41.48%)
Mutual labels:  serverless, cloud, aws-lambda
Lambda Toolkit
*DO NOT USE* - This project was done during my initial python and lambda's studies. I would recommend you the `serverless framework`.
Stars: ✭ 114 (-15.56%)
Mutual labels:  serverless, aws-lambda
Dynamodb Json
DynamoDB json util to load and dump strings of Dynamodb json format to python object and vise-versa
Stars: ✭ 114 (-15.56%)
Mutual labels:  serverless, json
Serverless Side Rendering React Next
Sample repo for setting up Next and React on AWS Lambda with the Serverless Framework.
Stars: ✭ 117 (-13.33%)
Mutual labels:  serverless, aws-lambda
Serverless Docker Image Resize
Simple serverless image resize on-the-fly - Deploy with one command - Built with AWS Lambda and S3
Stars: ✭ 114 (-15.56%)
Mutual labels:  serverless, aws-lambda
Aws Lambda R Runtime
Serverless execution of R code on AWS Lambda
Stars: ✭ 121 (-10.37%)
Mutual labels:  serverless, aws-lambda
Serverless static website with basic auth
Builds a serverless infrastructure in AWS for hosting a static website protected with Basic Authentication and published on a subdomain registered via Route 53
Stars: ✭ 112 (-17.04%)
Mutual labels:  serverless, aws-lambda
Serverless Architectures Aws
The code repository for the Serverless Architectures on AWS book
Stars: ✭ 120 (-11.11%)
Mutual labels:  serverless, aws-lambda
Athena Express
athena-express makes it easier to execute SQL queries on Amazon Athena by chaining together a bunch of methods in the AWS SDK. This allows you to execute SQL queries AND fetch JSON results in the same synchronous call - well suited for web applications.
Stars: ✭ 111 (-17.78%)
Mutual labels:  aws-lambda, json
Serverless Layers
Serverless.js plugin that implements AWS Lambda Layers which reduces drastically lambda size, warm-up and deployment time.
Stars: ✭ 119 (-11.85%)
Mutual labels:  serverless, aws-lambda
Serverless Plugin Optimize
Bundle with Browserify, transpile and minify with Babel automatically to your NodeJS runtime compatible JavaScript
Stars: ✭ 122 (-9.63%)
Mutual labels:  serverless, aws-lambda
Architect
The simplest, most powerful way to build serverless applications
Stars: ✭ 1,925 (+1325.93%)
Mutual labels:  serverless, aws-lambda

Codacy Badge Known Vulnerabilities Build Status Maven Central Join the chat at https://gitter.im/software-farm/aws-lambda-scala

Writing a handler for AWS lambda in Scala can be as easy as...

import io.circe.generic.auto._
import io.github.mkotsur.aws.handler.Lambda._
import io.github.mkotsur.aws.handler.Lambda
import com.amazonaws.services.lambda.runtime.Context

case class Ping(inputMsg: String)

case class Pong(outputMsg: String)

class PingPongHandler extends Lambda[Ping, Pong] {

  override def handle(ping: Ping, context: Context) = Right(Pong(ping.inputMsg.reverse))

}

The input JSON will be automatically de-serialized into Ping, and the output into Pong. The handle() method is supposed to return Either[Throwable, Pong]: Right if the input was handled correctly, and Left otherwise.

This handler can be used in AWS Lambda as: io.github.mkotsur.example::handle.

Features:

  • Return Futures right from the handler!
  • JSON (de)serialization of case classes;
  • Plain strings are supported too;
  • AWS API Gateway proxy integration;
  • Uncaught errors are logged with SLF4J and re-thrown.

Examples

Returning futures

import io.circe.generic.auto._
import io.github.mkotsur.aws.handler.Lambda._
import io.github.mkotsur.aws.handler.Lambda
import com.amazonaws.services.lambda.runtime.Context
import scala.concurrent.Future

case class Ping(inputMsg: String)

class PingFuturePongHandler extends Lambda[Ping, Future[Int]] {

  override def handle(ping: Ping, context: Context) = 
    Right(Future.successful(ping.inputMsg.length))

}

Not receiving and not returning any value

This lambda will accept an empty string, or string with null as an input.

import io.circe.generic.auto._
import io.github.mkotsur.aws.handler.Lambda._
import io.github.mkotsur.aws.handler.Lambda
import com.amazonaws.services.lambda.runtime.Context

class NothingToNothingHandler extends Lambda[None.type, None.type] {
  
  override protected def handle(i: None.type, c: Context) = {
    println("Only side effects")
    Right(None)
  }

}

API Gateway proxy integration

You can write less boilerplate when implementing a handler for API Gateway proxy events by extending Lambda.ApiProxy[I, C, O]. There are three type parameters there. The first one (I) corresponds to the body field of the API Gateway proxy event, the second one (C) corresponds to requestContext field, and the third one – to the body in the response object. More info about how the even looks like here.

import io.circe.generic.auto._
import io.circe.Json
import io.github.mkotsur.aws.handler.Lambda._
import io.github.mkotsur.aws.proxy._
import io.github.mkotsur.aws.handler.Lambda
import com.amazonaws.services.lambda.runtime.Context
import MyProxy._

object MyProxy {

  case class MyRequestBody(name: String)

  case class MyResponseBody(score: Int)

}

class MyProxy extends Lambda.ApiProxy[MyRequestBody, Json, MyResponseBody] {
  override def handle(
                                 i: ApiProxyRequest[MyRequestBody, Json],
                                 c: Context
                               ): Either[Throwable, ApiProxyResponse[MyResponseBody]] =
    i.body match {
      case Some(MyRequestBody("Bob")) =>
        Right(ApiProxyResponse.success(Some(MyResponseBody(100))))
      case Some(MyRequestBody("Alice")) =>
        Right(ApiProxyResponse.success(Some(MyResponseBody(50))))
      case Some(_) =>
        Right(ApiProxyResponse(404))
      case None =>
        Left(new IllegalArgumentException)
    }
}

Tip 1: of course, you can also pass a type defined by a case class into the second type parameter. Please check #24 and src/test/scala/io/github/mkotsur/aws/proxy/ProxyRequestTest.scala for an example.

Tip 2: Don't forget that Lambda.ApiProxy is a very thin wrapper around Lambda, so if something in ApiProxyRequest or ApiProxyResponse doesn't work for you - feel free to define your own case classes (and if you believe that the use case is generic enough – consider contributing back to the library).

Other usages

Feel free to look at src/test/scala for more examples. And of course, contributions to the docs are welcome!

Adding to your project

Scala versions supported: 2.11.x, 2.12.x, 2.13.x.

libraryDependencies += "io.github.mkotsur" %% "aws-lambda-scala" % {latest-version}

How does aws-lambda-scala compare with Serverless framework

Short answer: they complement each other. Long answer: read this blog post.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].