Serverless is the PaaS endgame
...but does not suit all workloads
Repo is the unit of collaboration
Repo commit is the unit of promotion
AWS Lambda is a viable execution platform
Responsibilities rather than Roles
Go is fantastic
func(...)
Administrator
privileges)AWS_REGION
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
$ go get -u -v github.com/mweagle/SpartaHelloWorld
$ cd $GOPATH/src/github.com/mweagle/SpartaHelloWorld
$ go get -u -v ./...
$ go run main.go help
$ go run main.go --help
Simple Sparta application that demonstrates
core functionality
Usage:
main [command]
Available Commands:
delete Delete service
describe Describe service
execute Execute
explore Interactively explore service
help Help about any command
provision Provision service
version Sparta framework version
Flags:
-f, --format string Log format [text, json] (default "text")
-h, --help help for main
--ldflags string Go linker string definition flags (https://golang.org/cmd/link/)
-l, --level string Log level [panic, fatal, error, warn, info, debug] (default "info")
-n, --noop Dry-run behavior only (do not perform mutations)
-t, --tags string Optional build tags for conditional compilation
Use "main [command] --help" for more information about a command.
`go run main.go provision --level info --s3Bucket $S3BUCKET`
$ go get -u -v github.com/mweagle/SpartaImager
$ cd $GOPATH/src/github.com/mweagle/SpartaImager
$ go run main.go provision --level info --s3Bucket $S3_BUCKET
// Provision an IAM::Role as part of this application
var iamRole = sparta.IAMRoleDefinition{}
// Setup the ARN that includes all child keys
resourceArn := fmt.Sprintf("%s/*", s3EventBroadcasterBucket)
iamRole.Privileges = append(iamRole.Privileges,
sparta.IAMRolePrivilege{
Actions: []string{"s3:GetObject", "s3:PutObject"},
Resource: resourceArn,
})
var lambdaFunctions []*sparta.LambdaAWSInfo
lambdaFn := sparta.HandleAWSLambda(
sparta.LambdaName(transformImage),
transformImage,
iamRole)
// The default timeout is 3 seconds - increase that to 30
// so the transform function doesn't timeout
lambdaFn.Options = &sparta.LambdaFunctionOptions{
Description: "Stamp assets in S3",
MemorySize: 128,
Timeout: 30,
}
// S3 notification configuration
lambdaFn.Permissions = append(lambdaFn.Permissions,
sparta.S3Permission{
BasePermission: sparta.BasePermission{
SourceArn: s3EventBroadcasterBucket,
},
Events: []string{"s3:ObjectCreated:*",
"s3:ObjectRemoved:*"},
})
lambdaFunctions = append(lambdaFunctions, lambdaFn)
$ go get -u -v github.com/mweagle/SpartaImager
$ cd $GOPATH/src/github.com/mweagle/SpartaImager
$ go run main.go provision --level info --s3Bucket $S3_BUCKET
apiStage := sparta.NewStage("v1")
apiGateway := sparta.NewAPIGateway("SpartaImagerAPI",
apiStage)
apiGateway.CORSEnabled = true
s3ItemInfoLambdaFn := sparta.HandleAWSLambda(
sparta.LambdaName(s3ItemInfo),
s3ItemInfo,
iamDynamicRole)
// Register the function with the API Gateway
apiGatewayResource, _ := api.NewResource("/info",
s3ItemInfoLambdaFn)
method, err := apiGatewayResource.NewMethod("GET",
http.StatusOK)
if err != nil {
return nil, err
}
// Whitelist query string params
method.Parameters["method.request.querystring.keyName"] = true
method.Parameters["method.request.querystring.bucketName"] = true
lambdaFunctions = append(lambdaFunctions, s3ItemInfoLambdaFn)
$ go get -u -v github.com/mweagle/SpartaHTML
$ cd $GOPATH/src/github.com/mweagle/SpartaHTML
$ go get -u -v ./...
$ go run main.go provision --level info --s3Bucket $S3_BUCKET
// Register the function with the API Gateway
apiStage := sparta.NewStage("v1")
apiGateway := sparta.NewAPIGateway("SpartaHTML", apiStage)
// Enable CORS s.t. the S3 site can access the resources
apiGateway.CORSEnabled = true
// Provision a new S3 bucket with the resources in the supplied subdirectory
s3Site, _ := sparta.NewS3Site("./resources")
// Deploy it
sparta.Main("SpartaHTML",
fmt.Sprintf("Sparta app that provisions a CORS-enabled API Gateway together with an S3 site"),
spartaLambdaFunctions(apiGateway),
apiGateway,
s3Site)
{
"APIGatewayURL": {
"Description": "API Gateway URL",
"Value": "https://p0ns30kpnd.execute-api.us-west-2.amazonaws.com/v1"
}
}
UPDATE_STACK
cycle.--provision
optionUse TemplateDecorators and WorkflowHooks to customize and extend your service
Lambda->SQS->ECS Worker Pool
Lambda->Grafana on EC2
馃弳
Sign Up for Serverless Slack Forum here
Export these slides to PDF