Slide 1

Slide 1 text

Serverless Computation Environment Ric da Silva @rmhsilva condense9.com Building a with Python, naturally

Slide 2

Slide 2 text

Hark Beyond infrastructure (as-code) Compilers 2

Slide 3

Slide 3 text

Serverless Computation Functions as a Service (FaaS) 3

Slide 4

Slide 4 text

4 So many tools & services: deployment, logging, monitoring, authentication, … A “Typical” Serverless Architecture

Slide 5

Slide 5 text

Project: Spec Python functions: f, g, h. Input: some parameter, x. Output: store value y in a database. y = f(g(h(x))) Constraints: - You must use AWS Lambda. - f, g, h take several minutes each to run. 5 Disclaimer: don’t use these function names at home!

Slide 6

Slide 6 text

Version 1 6 f(x) g(x) h(x) {“x”: “foo”} Store y = f(g(h(x))) ✔ Asynchronous invoke

Slide 7

Slide 7 text

Version 1: Testing 1. Unit-test f, h, g 2. Build an integration test 3. localstack 4. Staging env, CI 7 f(x) g(x) h(x) {“x”: “foo”} Store https://localstack.cloud/

Slide 8

Slide 8 text

Version 2 8 f(x) g(x) h(x) {“x”: “foo”} Store Inputs AWS Simple Queue Service Failures (“Dead Letter” Queue)

Slide 9

Slide 9 text

Hark Checklist ☐ Use Python ☐ Local testing ☐ Contextual debugging ☐ Operational support ☐ Easy cross-cloud portability 9

Slide 10

Slide 10 text

Let’s try Hark.

Slide 11

Slide 11 text

Series Computation 11

Slide 12

Slide 12 text

Parallel Computation Conditionals 12

Slide 13

Slide 13 text

Lists, mapping 13

Slide 14

Slide 14 text

API Endpoint 14 (But slowww for now)

Slide 15

Slide 15 text

More Stacktraces Upload triggers (AWS S3) Custom permissions (IAM statements) Custom build scripts (eg ./build.sh) Lambda configuration (memory, extra layers, etc) 15

Slide 16

Slide 16 text

16 a = get_future(“a”) if a.resolved: data_stack.push(a.value) else: this_thread.wait_for(a) wait_for: sort of like an implicit callback. This thread physically stops. When a resolves, this thread is continued.

Slide 17

Slide 17 text

f(x) data stack call stack trigger(fn, args) IP=0 f(x) Hark “CPU” Threads Waiting? Yes No IP=1 stdout Instructions async g(…) Finish New Thread (fn, args) New Thread Continue Thread (thread_id) Runtime Executable, Futures, CPU State, Stacks Memory (DynamoDB) …

Slide 18

Slide 18 text

until finished 18 Trigger API Deploy app code List sessions Get logs/results/… S3 Uploads Thread state Futures Hark & Python code New Session SNS status notifications Application data sources/sinks Logs Events StdOut Results Other AWS Services Hark CLI tool CI/CD Instance Data Control API API Gateway Manual Trigger Event data Runtime Hark Key-Value Store + Bucket ✨ https://github.com/boto/boto3 https://github.com/pynamodb/PynamoDB https://github.com/prompt-toolkit/python-prompt-toolkit https://github.com/pavdmyt/yaspin https://github.com/CITGuru/PyInquirer/

Slide 19

Slide 19 text

19 .hk import(f, src.main) fn main(x) { if x > 5 { print(“nope”) } else { Lex+Parse Optimise Compile Hark Executale Better AST Tail-call recursion, in particular https://commons.wikimedia.org/wiki/File:Abstract_syntax_tree_for_Euclidean_algorithm.svg - Import statements - Numbers, strings, … - Operations (+, *, …) - Function definitions - Assignments (x = 5) - Function Calls - … Convert the AST into byte-code that the Hark VM can execute Abstract Syntax Tree (AST) 01101 01011 Pack dataclasses, attrs functools typing parsy, sly https://github.com/python-attrs/attrs https://github.com/python-parsy/parsy https://github.com/dabeaz/sly ✨ Executable = Byte-Code + Python function references + Symbol table + Debugging info Byte-code

Slide 20

Slide 20 text

Checklist ✔ Use Python ✔ Local testing ✔ Contextual debugging ☐ Operational support ☐ True cross-cloud portability 20

Slide 21

Slide 21 text

Limitations Bandwidth (to/from session memory) Lambda startup time Account concurrency limits Others? 21

Slide 22

Slide 22 text

Hark Beyond infrastructure?! condense9.com, github/condense9 @rmhsilva 22