Upgrade to Pro — share decks privately, control downloads, hide ads and more …

State of The Function .Net Cambridge

State of The Function .Net Cambridge

The version of The State of the Function that I gave at .net Cambridge.

Martin Beeby

May 22, 2018
Tweet

More Decks by Martin Beeby

Other Decks in Technology

Transcript

  1. Martin Beeby @thebeebs A small piece of code (Packaged) Deployed

    to a service (Through CLI/Portal) The service create a URL endpoint for that code SERVERLESS
  2. Martin Beeby @thebeebs Marketing Sites Timers/ CLIs Full applications USE

    CASES Single Page Applications Integration/ APIs Alexa Skills/Office Apps
  3. Martin Beeby @thebeebs Mobile App Allows Lawyers to transcribe claimants

    testimony Manages a Legal Case in the field LAW FIRM
  4. Martin Beeby @thebeebs 2 minute chunks How do you slice

    up audio In the right place? THE BASIC PROBLEM Speech to Text Claimant != Clementine 30 minutes transcription
  5. Martin Beeby @thebeebs ARCHITECTURE Webhook Function: Slices Audio Python Webhook

    Put Webhook Webhook R e s u l t 6 Minute Audio In 3 x 2minute Audio chunks Function: Node.js Function: Node.js
  6. Martin Beeby @thebeebs from pydub import AudioSegment from io import

    BytesIO from pydub.silence import split_on_silence with open(os.environ['inputBlob'], "rb") as wav_file: sound = AudioSegment.from_file(wav_file, format="wav") chunks = split_on_silence( sound, # split on silences longer than 1000ms (1 sec) min_silence_len=100, # anything under -50 dBFS is considered silence silence_thresh=-50, # keep 200 ms of leading/trailing silence keep_silence=200 ) http://github.com/thebeebs/thestateofthefunction THE FUNCTION
  7. Martin Beeby @thebeebs # now recombine the chunks so that

    the parts are at least 2 minutes target_length = 120 * 1000 output_chunks = [chunks[0]] for chunk in chunks[1:]: if len(output_chunks[-1]) < target_length: output_chunks[-1] += chunk else: # if the last output chunk is longer than the target length, # we can start a new one output_chunks.append(chunk) for index in range(len(output_chunks)): if index < 16: output_chunks[index].export(os.environ['part' + str(index + 1)], format="wav") http://github.com/thebeebs/thestateofthefunction THE FUNCTION
  8. Martin Beeby @thebeebs Built On the Web App Service (Currently

    IIS) Using CI/CD in the same way you deploy Web App Service function.json configuration DEPLOYMENT
  9. Martin Beeby @thebeebs Package all Files and Dependencies Into a

    Zip File That can be uploaded via web portal Or upload via CLI in a CI/CD workflow DEPLOYMENT
  10. Martin Beeby @thebeebs aws lambda create-function \ --region us-east-1 --function-name

    myTestFunction --zip-file fileb://path/package.zip --role role-arn --environment Variables="{LD_LIBRARY_PATH=/usr/bin/test/lib64}" --handler index.handler --runtime nodejs6.10 --profile default LAMBDA CLI
  11. Martin Beeby @thebeebs Fn Builds a container Or any Docker

    Container can be a function I use Wercker to deploy and build containers DEPLOYMENT
  12. Martin Beeby @thebeebs LANGUAGES Type Service Lambda Azure Fn Node

    ✔ ✔ ✔ C# ✔* ✔ ✔* Python ✔ ✔* ✔ go ✔ ✔ Java ✔ ✔* ✔ ruby ✔ F# ✔ ? Batch, Bash, Powershell ✔ ? php ✔ Any Docker Container ✔
  13. Martin Beeby @thebeebs Run when triggered by item being added

    to a queue or container etc In and Out or Using Storage SDK from function Used in this Legal Application STORAGE TRIGGER
  14. Martin Beeby @thebeebs BINDINGS LAMBDA Type Trigger Input Output API

    Gateway ✔ AWS IoT ✔ Alexa Skills Kit ✔ Cloudwatch Events, Logs ✔ Code Commit ✔ DynamoDb ✔ Kinesis ✔ S3 ✔ SNS ✔
  15. Martin Beeby @thebeebs BINDINGS AZURE Type Service Trigger Input Output

    Schedule Azure Functions ✔ HTTP (REST or webhook) Azure Functions ✔ ✔* Blob Storage Azure Storage ✔ ✔ ✔ Events Azure Event Hubs ✔ ✔ Queues Azure Storage ✔ ✔ Tables Azure Storage ✔ ✔ Tables Azure Mobile Apps ✔ ✔ No-SQL DB Azure CosmosDB ✔ ✔ Push Notifications Azure Notification Hubs ✔ ServiceBus Queue/Topic Azure Service Bus ✔ Event Grid All the things ✔
  16. Martin Beeby @thebeebs { "Records": [ { "eventVersion": "2.0", "eventTime":

    "1970-01-01T00:00:00.000Z", "requestParameters": { "sourceIPAddress": "127.0.0.1" }, "s3": { "configurationId": "testConfigRule", "object": { "eTag": "0123456789abcdef0123456789abcdef", "sequencer": "0A1B2C3D4E5F678901", "key": "uk-EN_sample.wav", "size": 1024 }, "bucket": { "arn": "arn:aws:s3:::mybucket", "name": "voicewavfiles", "ownerIdentity": { "principalId": "EXAMPLE" } }, "s3SchemaVersion": "1.0" }, "responseElements": { "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH", "x-amz-request-id": "EXAMPLE123456789" }, "awsRegion": "us-east-1", "eventName": "ObjectCreated:Put", "userIdentity": { "principalId": "EXAMPLE" }, "eventSource": "aws:s3" } ] } Webhooks BINDINGS FNPROJECT
  17. Martin Beeby @thebeebs fn run fn deploy –app myapp –-local

    cat sample.lamda.payload.json | fn call myapp /fnProject cat sample.lamda.payload.json | cURL http://myserver/r/myapp /fnProject DEPLOY
  18. Martin Beeby @thebeebs fn apps create cambridgeapp fn routes create

    cambridgeapp /voice -i thebeebs/voice:0.0.7 --timeout 120 fn routes list cambridgeapp cat .\sample.lamda.payload.json | fn call cambridgeapp voice CONTAINERS AS FUNCTIONS
  19. Martin Beeby @thebeebs Not establishing Standards Multiple Invocation Forgetting about

    devops COMMON MISTAKES Start up time - Preload Depending on Dependencies Poor Error Logging Managing Memory Long Running Tasks
  20. Martin Beeby @thebeebs Marketing Sites Timers/ CLIs Full applications USE

    CASES Single Page Applications Integration/Integration/ APIs Alexa Skills/Office Apps
  21. Martin Beeby @thebeebs FNPROJECT FLOW public void book1(TripReq input) {

    Flow f = Flows.currentFlow(); FlowFuture<BookingRes> flightFuture = f.invokeFunction("./flight/book", input.flight, BookingRes.class); FlowFuture<BookingRes> hotelFuture = f.invokeFunction("./hotel/book", input.hotel, BookingRes.class); FlowFuture<BookingRes> carFuture = f.invokeFunction("./car/book", input.carRental, BookingRes.class); flightFuture.thenCompose( (flightRes) -> hotelFuture.thenCompose( (hotelRes) -> carFuture.whenComplete( (carRes, e) -> EmailReq.sendSuccessMail(flightRes, hotelRes, carRes) ) ) ); }
  22. Martin Beeby @thebeebs public static async Task<object> Run(DurableOrchestrationContext ctx) {

    try { var x = await ctx.CallActivityAsync<object>("F1"); var y = await ctx.CallActivityAsync<object>("F2", x); var z = await ctx.CallActivityAsync<object>("F3", y); return await ctx.CallActivityAsync<object>("F4", z); } catch (Exception) { // error handling/compensation goes here } } DURABLE FUNCTIONS