Skip to content

Latest commit

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Serverless-Annotations

This project aims to do one thing - make the SLS framework (www.serverless.com) easier to use in the Java world.

Bottom line

Annotated your classes, as seen below, specify some params in gradle, bada boom - you get a serverless.yml file out.

packageorg.densebrain.serverless.examples.simpleimportcom.amazonaws.services.lambda.runtime.*;importorg.densebrain.serverless.annotations.*importorg.densebrain.serverless.annotations.Functiondata classTestRequestModel(valid:String)
data classTestResponseModel(valid:String)
@Function(
name ="TestLambda",
environment = [
Environment(
name ="REF_VAR",
yaml =""""Fn::GetAtt": [SessionUpdateLambdaFunction, Arn]"""
)
],
http = [
HttpEvent(
path ="/test/{hello}",
method =HttpEventMethod.GET,
input =TestRequestModel::class,
output =TestResponseModel::class,
request =Request(
paths = [Parameter("hello",true)],
querystrings = [Parameter("since",false)]
)
)
],
schedule = [
ScheduleEvent("rate(3 minutes)")
],
cloudwatch = [
CloudwatchEvent(""" event: source: - "aws.batch" detail: jobName: - "$"""+"""{self:custom.customVar}"""")
]
)
classTestLambda : RequestHandler<TestRequestModel, TestResponseModel> {
overridefunhandleRequest(input:TestRequestModel, context:Context): TestResponseModel {
returnTestResponseModel(input.id)
}
}

Gradle Configuration

task serverlessBuild(type: ServerlessBuilderTask) {
// WE SUGGEST USING SHADOW TO BUILD // A SINGLE ARCHIVE TO MAKE SCANNING EASIER
dependsOn(shadowJar)
// PATH TO ARCHIVE OF CLASSES
archive = file("${buildDir.absolutePath}/libs/${shadowJar.archiveName}")
// (OPTIONAL) Bring your own serverless.yml template// If you specify a template then functions will be appended to // your functions block
serverlessConfigFile = serverlessBaseFile
// OUTPUT PATH FOR serverless.yml
outputFile = file("${projectDir.absolutePath}/serverless.yml")
// BASE PACKAGE TO SCAN FOR ANNOTATED TYPES
basePackage ="your.package.here"// GENERATE MODELS/DOCUMENTATION FOR SWAGGER, etc
generateDocumentation =true// (OPTIONAL) If omitted then the documentation block is appended// to any existing "custom" block in the serverless.yml
documentationOutputFile = file("${projectDir.absolutePath}/documentation.yml")
}
build.dependsOn(serverlessBuild)

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages