├── project ├── build.properties └── plugins.sbt ├── src └── main │ ├── resources │ └── lambda-exports.js │ └── scala │ └── demo │ └── awslambda │ └── DemoSuccess.scala ├── .gitignore ├── README.md └── LICENSE /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.8 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += "SBT release" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/" 2 | 3 | resolvers += Resolver.jcenterRepo 4 | 5 | libraryDependencies += "com.amazonaws" % "aws-java-sdk-lambda" % "1.9.26" 6 | 7 | addSbtPlugin("com.github.tptodorov" % "sbt-cloudformation" % "0.2.0") 8 | 9 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.2") 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/lambda-exports.js: -------------------------------------------------------------------------------- 1 | require("aws-lambda-scalajs-fastopt.js"); 2 | 3 | function makeLambda(scalaCallObject) { 4 | return function(event, context) { 5 | try { 6 | var msg = scalaCallObject.apply(event, context); 7 | context.done(null, msg); 8 | } catch (err) { 9 | context.done(err.toString(), null); 10 | } 11 | }; 12 | } 13 | 14 | exports.handler = makeLambda(demo.awslambda.DemoSuccess()); 15 | 16 | exports.failing = makeLambda(demo.awslambda.DemoFail()); -------------------------------------------------------------------------------- /src/main/scala/demo/awslambda/DemoSuccess.scala: -------------------------------------------------------------------------------- 1 | package demo.awslambda 2 | 3 | import scala.scalajs.js.annotation.JSExport 4 | 5 | @JSExport 6 | object DemoSuccess { 7 | @JSExport 8 | def apply(event: Object, context: Object): String = { 9 | println("Scala JS, Hello world!") 10 | println(event) 11 | println(context) 12 | "Completed Lambda Hello World" 13 | } 14 | } 15 | 16 | @JSExport 17 | object DemoFail { 18 | @JSExport 19 | def apply(event: Object, context: Object): String = { 20 | println("This lambda will fail!") 21 | throw new IllegalArgumentException("failed from Scala") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Scala template 3 | *.class 4 | *.log 5 | 6 | # sbt specific 7 | .cache 8 | .history 9 | .lib/ 10 | dist/* 11 | target/ 12 | lib_managed/ 13 | src_managed/ 14 | project/boot/ 15 | project/plugins/project/ 16 | 17 | # Scala-IDE specific 18 | .scala_dependencies 19 | .worksheet 20 | 21 | 22 | ### Maven template 23 | target/ 24 | pom.xml.tag 25 | pom.xml.releaseBackup 26 | pom.xml.versionsBackup 27 | pom.xml.next 28 | release.properties 29 | dependency-reduced-pom.xml 30 | 31 | 32 | ### Java template 33 | *.class 34 | 35 | # Mobile Tools for Java (J2ME) 36 | .mtj.tmp/ 37 | 38 | # Package Files # 39 | *.jar 40 | *.war 41 | *.ear 42 | 43 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 44 | hs_err_pid* 45 | 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-lambda-scalajs 2 | 3 | Proof of Concept for building ScalaJS based Lambda functions. Currently AWS Lambda supports only JavaScript. 4 | 5 | See: 6 | * src/main/scala/demo/awslambda/Demo.scala - some demo function objects 7 | * src/main/resources/lambda-exports.js - this exports ScalaJS function objects 8 | 9 | See build.sbt for configuration details. 10 | 11 | This projects contains two demo functions: 12 | 13 | * DemoSuccess - prints input arguments to console. 14 | * DemoFail - throws an exception and lambda function fails properly with an error message. 15 | 16 | ## Upload all functions 17 | 18 | This project uses [https://github.com/tptodorov/sbt-cloudformation] to setup deployment environment. 19 | 20 | sbt staging:uploadFunctions 21 | 22 | uploads functions with suffix -staging. 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Todor Todorov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------