Skip to content

Instantly share code, notes, and snippets.

@akhilvijayan05
akhilvijayan05 / LambdaHandler.scala
Created April 9, 2018 11:44
Sample AWS Lambda Code
package com.example.handler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.example.models.Request;
import com.example.utils.constant.Constants;
import com.example.utils.fileprocessor.FileReader;
import com.example.models.Response;
package object ujson{
def transform[T](t: Transformable, v: Visitor[_, T]) = t.transform(v)
def read(s: Transformable): Js.Value = transform(s, Js)
def copy(t: Js.Value): Js.Value = transform(t, Js)
def write(t: Js.Value, indent: Int = -1): String = {
transform(t, StringRenderer(indent)).toString
}
trait Api {
def read[T: Reader](s: Transformable): T = s.transform(reader[T])
def readJs[T: Reader](s: Js.Value): T = s.transform(reader[T])
def reader[T: Reader] = implicitly[Reader[T]]
def write[T: Writer](t: T, indent: Int = -1): String = {
transform(t).to(StringRenderer(indent)).toString
}
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Lambda Sample Project
Resources:
Products:
Type: AWS::Serverless::Function
Properties:
Handler: com.example.handler.LambdaHandler
class EmployeeRepository {
val cluster = Cluster.builder.addContactPoint("127.0.0.1").build()
val session = cluster.connect()
val KEYSPACE_TABLE = "CREATE KEYSPACE IF NOT EXISTS udt WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
val ADDRESS_TABLE = "CREATE TYPE IF NOT EXISTS udt.address (employee_id int, residence_address text, office_address text,city text);"
val EMPLOYEE_TABLE = "CREATE TABLE IF NOT EXISTS udt.employee (employee_id int PRIMARY KEY,name text,address frozen<address>,salary text);"
session.execute(KEYSPACE_TABLE)
session.execute(ADDRESS_TABLE)
session.execute(EMPLOYEE_TABLE)
@akhilvijayan05
akhilvijayan05 / AMPS Publisher
Created October 13, 2018 11:57
A simple AMPS publisher example
import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
object Publisher extends App {
val client = new Client("MyClient")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")
client.logon()
client.publish("messages", "{ \"message\" : \"Hello, world!\" } ")
@akhilvijayan05
akhilvijayan05 / AMPS Subscriber
Last active October 13, 2018 12:02
A simple example for an AMPS subscriber
import com.crankuptheamps.client.Client;
import com.crankuptheamps.client.exception.AMPSException;
import scala.collection.JavaConverters._
object Subscriber extends App {
val client = new Client("subscribe")
try {
client.connect("tcp://127.0.0.1:9007/amps/json")
<SOW>
<Topic>
<Name>sow-topic</Name>
<FileName>sow/%n.sow</FileName>
<Expiration>enabled</Expiration>
<Key>/id</Key>
<MessageType>json</MessageType>
</Topic>
</SOW>
import akka.actor.Props
import akka.persistence.{PersistentActor, SnapshotOffer}
import com.knoldus.models._
import com.knoldus.persistence.CounterPersistentActor.Response
class CounterPersistentActor(id: String) extends PersistentActor {
override val persistenceId: String = id
var state = State(count = 0)
import cats.syntax.option._
val optionValue: Option[Int] = 35.some
val noneValue: Option[Int] = none[Int]