Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Serverless workshop with Amazon Web Services

169 Aufrufe

Veröffentlicht am

By Alexandre Pinhel (twitter.com/AlexPinhel), Solution Architect @AWS

Serverless computing, where cloud providers dynamically allocate resources to execute the code, helps save money.

Alexandre from Amazon Web Services came to The Family to present what’s new in the serverless space and also to build a serverless application (a Twitter bot leveraging Lambda layers to process tweets) on the spot!

What new features have been released lately? What patterns are usable for serverless applications? What are the best practices and a concrete use case or two?

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Serverless workshop with Amazon Web Services

  1. 1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T AWS -Serverless Alexandre Pinhel AWS – Solutions Architect
  2. 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Serverlessapplications Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function Node.js Python Java C# Go Ruby Runtime API
  3. 3. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T ServerlessWebApplications
  4. 4. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T AWS Lambda releasehistory ? *As of October 2018, does not include region launches 2015 2016 2017 2018
  5. 5. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Lambda Layers Lets functions easily share code: Upload layer once, reference within any function Promote separation of responsibilities, lets developers iterate faster on writing business logic Built in support for secure sharing by ecosystem
  6. 6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Using Lambda Layers • Put common components in a ZIP file and upload it as a Lambda Layer • Layers are immutable and can be versioned to manage updates • When a version is deleted or permissions to use it are revoked, functions that used it previously will continue to work, but you won’t be able to create new ones • You can reference up to five layers, one of which can optionally be a custom runtime Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib:2 Lambda Layers arn:aws:lambda:region:accountId:layer:shared-lib:3
  7. 7. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Lambda RuntimeAPI Bring any Linux compatible language runtime Powered by new Runtime API - Codifies the runtime calling conventions and integration points At launch, custom runtimes powering Ruby support in AWS Lambda, more runtimes from partners (like Erlang) Custom runtimes distributed as “layers” Rule Stack
  8. 8. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T RuntimeBootstrap • The bootstrap executable act as a bridge between the Runtime HTTP API and the Function to be executed • Bootstrap needs to manage response/error handling, context creation and function execution • Information on the interface endpoint and the function handler are shared as environment variables /runtime API /invocation/next /init/error /ID/error /invocation/ID/response /invocation/ID/error bootstrap Process events/headers Clean up Initialize and Invoke function Response/Error handling Lambda Function
  9. 9. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Bootstrap d’un RuntimeCustom • L’exécutable bootstrap agit comme un pont entre le Runtime HTTP de Lambda et la fonction à exécuter • Le Boostrap doit gérer la gestion des réponses et des erreurs, créer le contexte et executer la fonction • Les informations liées au endpoint et les handler de fonction sont partagées comme des variables environnement /runtime API /invocation/next /init/error /ID/error /invocation/ID/response /invocation/ID/error bootstrap Process events/headers Clean up Initialize and Invoke function Response/Error handling Lambda Function #!/bin/sh set -euo pipefail # Initialization - load function handler source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh" # Processing while true do HEADERS="$(mktemp)" # Get an event EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06- 01/runtime/invocation/next") REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2) # Execute the handler function from the script RESPONSE=$($(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA") # Send the response curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE" done
  10. 10. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Common Lambda usecases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  11. 11. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Serverlessarchitectures 1. File put into bucket 2. Lambda invoked 2. Lambda invoked 1. Data published to a topic Data 1. Message inserted into to a queue 3. Function removes message from queue 2. Lambda polls queue and invokes function Topic MessageObject
  12. 12. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Serverlessarchitectures 2. Lambda polls stream 1. Data published to a stream 3. Amazon Kinesis returns stream data Data 2. Lambda invoked 1. Chatbot conversation needs “fulfillment” Chatbot 1. Scheduled time occurs 2. Lambda invoked Event (time-based)
  13. 13. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Keeporchestration outof code Track status of data and execution Remove redundant code
  14. 14. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T AWSStepFunctions “Serverless” workflow management with zero administration • Makes it easy to coordinate the components of distributed applications and microservices using visual workflows • Automatically triggers and tracks each step and retries when there are errors, so your application executes in order and as expected • Logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly Task Choice Failure capture Parallel tasks
  15. 15. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T StepFunctions: Integrations Simplify building workloads such as order processing, report generation, and data analysis Write and maintain less code; add services in minutes More service integrations: AWS Step Functions Amazon Simple Notification Service Amazon Simple Queue Service Amazon SageMaker AWS Glue AWS Batch Amazon Elastic Container Service AWS Fargate
  16. 16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Simpler integration,lesscode With serverless polling With direct service integrationStart End AWS Lambda functions Start End No Lambda functions
  17. 17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Best Practices
  18. 18. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Don’t startfromscratch AWS Chalice AWS Amplify AWS SAM AWS: Third-party: Serverless Framework
  19. 19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T SAMTemplate Note to Cloudformation that it is a SAM template Create an AWS Lambda function with an IAM policy, runtime, the code available on zip file and the handler to start. Will create an event with API Gateway and the path associated. Create an Amazon DynamoDB with 5 RCU & WCU AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://sam-demo-bucket/todo_list.zip Handler: index.gethtml Runtime: nodejs8.10 Policies: AmazonDynamoDBReadOnlyAccess Events: GetHtml: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::Serverless::SimpleTable
  20. 20. DEMO!
  21. 21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T aws.amazon.com/serverless
  22. 22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T https://secure.flickr.com/photos/dullhunk/202872717/
  23. 23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Resources Workshop serverless on Github: https://github.com/aws-samples/aws-serverless-workshops Twitter Bot on github (without layer): https://github.com/aws-samples/aws-twitterbot-workshop Power tuning for Lambda: https://github.com/alexcasalboni/aws-lambda-power-tuning Registration for AWS free workshop: https://aws.amazon.com/fr/serverless-workshops/ Layers: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html https://github.com/mthenw/awesome-layers (languages, tools, monitoring) Amplify: https://aws-amplify.github.io/docs/

×