Skip to content

Instantly share code, notes, and snippets.

@bytekast
bytekast / template.yaml
Created May 3, 2021 18:33
Sam Template - API Gateway (with Authorizer) => Kinesis Data Stream => Kinesis Firehose => S3
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
StageName:
Type: String
Default: dev
AllowedValues:
- dev
- staging
serverless create \
--template-url https://github.com/bytekast/serverless-toolkit/tree/master/templates/java-springboot-monolith \
--path my-springboot-service
cd my-springboot-service
./gradlew clean build # build
./gradlew bootRun # run locally
curl http://localhost:8080/greeting # test locally
serverless deploy # deploy
package com.serverless
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.RequestHandler
import io.vertx.core.AbstractVerticle
import io.vertx.core.Vertx
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
task(buildJson) {
doLast {
new File("$buildDir/build.json").newWriter().withWriter { w ->
w << JsonOutput.toJson([distribution: relativePath(jar.archivePath), version: jar.version])
}
}
}
jar.finalizedBy buildJson
@bytekast
bytekast / serverless_create.sh
Last active February 26, 2018 04:29
create microservice template
serverless create \
--template-url https://github.com/bytekast/serverless-templates/tree/master/microservice-starter \
--path myservice
@bytekast
bytekast / AbstractEventHandler.groovy
Created December 7, 2017 04:52
Common Base Handler for Lambda Functions
package com.stedi.platform.lambda
import com.amazonaws.services.lambda.runtime.Context
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.codehaus.groovy.runtime.StackTraceUtils
@Slf4j
@CompileStatic
abstract class AbstractEventHandler implements CommonTrait, AmazonSNSTrait, DataDogTrait, SentryTrait {
@Builder
@ToString(includePackage = false)
@CompileStatic
class Response {
int statusCode
String body
private Map<String, String> headers = [:]
void addHeader(String key, String value) {
headers.put(key, value)
@bytekast
bytekast / serverless.yml
Last active September 22, 2017 09:32
Serverless with Spring Boot / Spring Data
service: springboot-lambda
provider:
name: aws
runtime: java8
memorySize: 1536
timeout: 60
package:
artifact: build/distributions/springboot-lambda.zip
@bytekast
bytekast / promiseChaining.groovy
Last active August 29, 2017 07:01
Chaining Promises in Groovy GPars
final successHandler = { controller.successEvent(context, transmissionUuid, parcel) }
final errorHandler = { Exception e -> controller.errorEvent(context, transmissionUuid, parcel, e) }
task { controller.download(sessionId, parcel) }
.then { download -> controller.save(download, transmissionUuid, parcel) }
.then { download -> controller.forward(download, transmissionUuid, parcel) }
.then { controller.delete(sessionId, parcel.id) }
.then(successHandler, errorHandler)
service: user-service
provider:
name: aws
runtime: java8
memorySize: 1536
timeout: 60
package:
artifact: build/distributions/user-service.zip