SlideShare a Scribd company logo
AWS Lambda in Golang
HOW TO START
Wojciech Barczyński - wb@
wbarczynski.pro@gmail.com
Hypatos.ai
WOJCIECH BARCZYŃSKI
= Hypatos.ai
Lead So ware Engineer
Golang Warsaw
Organizer
Hobby:
Kubernetes/CloudNative
evangelist;
teacher/trainer
SMACC.io
Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
WHY SERVERLESS
1. Cut costs
2. Simplify
3. Generate/Prepare and cache
experience in LykeHQ
SMACC / Hypatos
1. Kubernetes/CloudNative
Agility. We own it. Observability.
SMACC.io / Hypatos.ia
1. Kubernetes/CloudNative
2. XaaS
3. Looking into Serverless
WHY GO?
Readibility
Performance [1][2]
Cheap Concurrency [3]
[1] [2] [3]go vs nodejs acloud benchmark Cost reduced
Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
DISADVANTAGES
Binary size
Complied no way to edit
Might have slower start [1]
[1] Some users report slow start times
HOW TO START
It is easy:
go dep
serverless framework
amazon sam CLI
HOW TO START
$ npm install -g serverless
$ go get github.com/tools/godep
$ brew tap aws/tap; brew install aws-sam-cli
DEMO - GENERATE CODE
Definicja binary per handler
$ serverless create -t aws-go-dep
DEMO - DEPLOY
$ make build
$ make deploy
DEMO - RUNNING LOCALLY
1. Prepare: template.yaml for sam
2. Execute:
$ sam local start-api
$ sam local start-api --env-vars env.json
DEMO - RUNNING LOCALLY
$ curl http://127.0.0.1:3000/hello
$ curl http://127.0.0.1:3000/hello/natalia
$ curl http://127.0.0.1:3000/hello?name=natalia
DEMO - GENERATE EVENTS
$ sam local generate-event
$ sam local generate-event s3 put > put_s3.json
$ sam local invoke "HelloWorldFunction" -e put_s3.sjon
DEMO - HANDLERS
func ()
func () error
func (TIn), error
func () (TOut, error)
func (context.Context) error
func (context.Context, TIn) error
func (context.Context) (TOut, error)
func (context.Context, TIn) (TOut, error)
AWS docs on valid handlers
DEMO - CONTEXT
see
ctx context.Context
# from ctx to lambdacontext
lc, _ := lambdacontext.FromContext(ctx)
implementation
TESTING
units
integration locally, e.g., with
in the cloud
dynamodb-local
localstack.cloud
GUIDE
time is $$
Golang:
Pass by value small data types
Pointers for large ones
Goroutines for, e.g., init
UNKNOWN
how to asses the resources [1]
how to integrate with our prometheus stack
Can we take the lesson to onPrem?
[1] aws-lambda-power-tuning
SUMMARY
Golang is a fast and simple to read language
Easy to use, give it a try :)
Later check more complex examples
github.com/wojciech12/talk_serverless_in_golang
Next talk: kubeless?
THANK YOU. QUESTIONS?
We are hiring.
BACKUP SLIDES
Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
INTERESTING
Golang on Kubeless
Golang Plugins and Lambda Layers
golang and GraalVM
AWS Fargate

More Related Content

Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw