Aws Lambda in Golang | Wojciech Barczynski | #4 Serverless UG Warsaw
- 1. AWS Lambda in Golang
HOW TO START
Wojciech Barczyński - wb@
wbarczynski.pro@gmail.com
Hypatos.ai
- 11. HOW TO START
$ npm install -g serverless
$ go get github.com/tools/godep
$ brew tap aws/tap; brew install aws-sam-cli
- 12. DEMO - GENERATE CODE
Definicja binary per handler
$ serverless create -t aws-go-dep
- 14. DEMO - RUNNING LOCALLY
1. Prepare: template.yaml for sam
2. Execute:
$ sam local start-api
$ sam local start-api --env-vars env.json
- 15. 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
- 16. DEMO - GENERATE EVENTS
$ sam local generate-event
$ sam local generate-event s3 put > put_s3.json
$ sam local invoke "HelloWorldFunction" -e put_s3.sjon
- 17. 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
- 18. DEMO - CONTEXT
see
ctx context.Context
# from ctx to lambdacontext
lc, _ := lambdacontext.FromContext(ctx)
implementation
- 21. 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
- 22. SUMMARY
Golang is a fast and simple to read language
Easy to use, give it a try :)
Later check more complex examples