Skip to content

Commit

Permalink
adding ReservedConcurrentExecutions
Browse files Browse the repository at this point in the history
  • Loading branch information
dnvriend committed Mar 24, 2018
1 parent 73ffa95 commit f750f0c
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 36 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -342,6 +342,10 @@ The 'default cli config' file:
- [Lambda Environment Variables](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html)

## Changelog
## 1.0.28 (2018-03-23)
- Support for generic lambdas by using the `GenericHandler` trait and annotating it with a `@GenericConf` configuration.
- Added support for

## 1.0.27 (2018-03-02)
- SAM generates an `AWS::ApiGateway::Stage` resource with a name where the `samStage` was part of the
encoded resource name. This name was the result of applying the `Serverless Transform`. To export the
Expand Down
Expand Up @@ -9,4 +9,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -12,4 +12,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -14,4 +14,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -11,4 +11,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -11,4 +11,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -11,4 +11,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -9,4 +9,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -10,4 +10,5 @@
int memorySize() default 1024;
int timeout() default 300;
String description() default "";
int reservedConcurrentExecutions() default -1;
}
Expand Up @@ -4,41 +4,56 @@ import com.github.dnvriend.sbt.sam.cf.CloudFormation
import com.github.dnvriend.sbt.sam.cf.resource.Resource
import com.github.dnvriend.sbt.sam.cf.resource.lambda.event.EventSource
import play.api.libs.json._
import com.github.dnvriend.sbt.util.JsMonoids
import play.api.libs.json.{ JsValue, Json, Writes }

import scalaz.NonEmptyList
import scalaz.syntax.all._

object ServerlessFunction {
implicit val writes: Writes[ServerlessFunction] = Writes.apply(model => {
import model._

val baseProperties: JsValue = {
Json.obj(
"Handler" -> s"$fqcn::handleRequest",
"Runtime" -> "java8",
"CodeUri" -> Json.obj(
"Bucket" -> deploymentBucketName,
"Key" -> jarName,
"Version" -> latestVersion
),
"Policies" -> managedPolicies,
"Description" -> description,
"MemorySize" -> memorySize,
"Timeout" -> timeout,
"Tracing" -> "Active",
"Environment" -> Json.obj(
"Variables" -> Json.obj(
"STAGE" -> stage,
"PROJECT_NAME" -> projectName,
"VERSION" -> projectVersion,
"AWS_ACCOUNT_ID" -> CloudFormation.accountId
).++(Json.toJsObject(envVars))
),
"Tags" -> Json.obj(
"sbt:sam:projectName" -> projectName,
"sbt:sam:projectVersion" -> projectVersion,
"sbt:sam:stage" -> stage
),
"Events" -> Json.toJson(eventSource)
).++(determineVpcConfig)
}

val properties: JsValue = NonEmptyList(
baseProperties,
Json.toJson(model.reservedConcurrentExecutions.map(value => Json.obj("ReservedConcurrentExecutions" -> value)))
).fold(JsMonoids.jsObjectMerge)

Json.obj(
lambdaName -> Json.obj(
"Type" -> "AWS::Serverless::Function",
"Properties" -> Json.obj(
"Handler" -> s"$fqcn::handleRequest",
"Runtime" -> "java8",
"CodeUri" -> Json.obj(
"Bucket" -> deploymentBucketName,
"Key" -> jarName,
"Version" -> latestVersion
),
"Policies" -> managedPolicies,
"Description" -> description,
"MemorySize" -> memorySize,
"Timeout" -> timeout,
"Tracing" -> "Active",
"Environment" -> Json.obj(
"Variables" -> Json.obj(
"STAGE" -> stage,
"PROJECT_NAME" -> projectName,
"VERSION" -> projectVersion,
"AWS_ACCOUNT_ID" -> CloudFormation.accountId
).++(Json.toJsObject(envVars))
),
"Tags" -> Json.obj(
"sbt:sam:projectName" -> projectName,
"sbt:sam:projectVersion" -> projectVersion,
"sbt:sam:stage" -> stage
),
"Events" -> Json.toJson(eventSource)
).++(determineVpcConfig)
"Properties" -> properties
)
)
})
Expand All @@ -54,6 +69,7 @@ case class ServerlessFunction(
jarName: String,
latestVersion: String,
description: String,
reservedConcurrentExecutions: Option[Int],
memorySize: Int,
timeout: Int,
managedPolicies: List[String],
Expand Down
Expand Up @@ -23,6 +23,7 @@ case class LambdaConfig(
memorySize: Int = 1024,
timeout: Int = 300,
description: String = "",
reservedConcurrentExecutions: Option[Int] = None,
managedPolicies: List[String] = List.empty,
vpcConfig: Option[VPCConfig] = None,
envVars: Map[String, String] = Map.empty
Expand Down Expand Up @@ -236,9 +237,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

DynamoHandler(
LambdaConfig(cl, fqcn, simpleName, memorySize, timeout, description),
LambdaConfig(cl, fqcn, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
DynamoConf(tableName, batchSize, startingPosition, enabled)
)
}
Expand All @@ -250,9 +252,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

HttpHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
HttpConf(path, method, authorization)
)
}
Expand All @@ -262,9 +265,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

ScheduledEventHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
ScheduleConf(schedule)
)
}
Expand All @@ -274,9 +278,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

SNSEventHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
SNSConf(topic)
)
}
Expand All @@ -288,9 +293,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

KinesisEventHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
KinesisConf(stream, startingPosition, batchSize)
)
}
Expand All @@ -301,11 +307,12 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)
val events = anno.annotationType().getMethod("events").invoke(anno).asInstanceOf[Array[String]].toList
val s3Events = S3Events.fromList(events)

S3EventHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
S3Conf(bucketResourceName, filter, s3Events)
)
}
Expand All @@ -315,9 +322,10 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

CloudWatchHandler(
LambdaConfig(cl, className, simpleName, memorySize, timeout, description),
LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions),
CloudWatchConf(pattern)
)
}
Expand All @@ -326,8 +334,9 @@ object ClassifyLambdas {
val memorySize = anno.annotationType().getMethod("memorySize").invoke(anno).asInstanceOf[Int]
val timeout = anno.annotationType().getMethod("timeout").invoke(anno).asInstanceOf[Int]
val description = anno.annotationType().getMethod("description").invoke(anno).asInstanceOf[String]
val reservedConcurrentExecutions = Option(anno.annotationType().getMethod("reservedConcurrentExecutions").invoke(anno).asInstanceOf[Int]).find(_ >= 0)

GenericHandler(LambdaConfig(cl, className, simpleName, memorySize, timeout, description))
GenericHandler(LambdaConfig(cl, className, simpleName, memorySize, timeout, description, reservedConcurrentExecutions))
}


Expand Down
Expand Up @@ -452,6 +452,7 @@ object CloudFormationTemplates {
jarName,
latestVersion,
conf.description,
conf.reservedConcurrentExecutions,
conf.memorySize,
conf.timeout,
conf.managedPolicies,
Expand Down

0 comments on commit f750f0c

Please sign in to comment.