Was ist AWS Lambda? Lambda-Funktion mit Beispielen
โก Intelligente Zusammenfassung
AWS Lambda is an event-driven, serverless computing platform from Amazon Web Services that runs your code in response to triggers, automatically handling provisioning, scaling, and server management so you focus only on business logic.

Before exploring AWS Lambda, it helps to understand what serverless means.
Was ist serverlos?
Serverless is a term that generally refers to serverless applications. Serverless applications are ones that do not need any server provision and do not require you to manage servers.
Was ist AWS Lambda?
AWS Lambda ist eine ereignisgesteuerte, serverlose Computerplattform, die von bereitgestellt wird Amazon Als ein teil von Amazon Web Services. Therefore you do not need to worry about which AWS resources to launch, or how you will manage them. Instead, you need to put the code on Lambda, and it runs.
In AWS Lambda the code is executed based on the response of events in AWS services such as adding or deleting files in an S3 bucket, an HTTP request from Amazon API Gateway, and similar events. However, Amazon Lambda kann nur zum Ausfรผhren von Hintergrundaufgaben verwendet werden.
AWS Lambda function helps you to focus on your core product and business logic instead of managing operating system (OS) access control, OS patching, right-sizing, provisioning, scaling, and so on.
Wie funktioniert AWS Lambda?
Das folgende AWS Lambda-Beispiel mit Blockdiagramm erklรคrt die Funktionsweise von AWS Lambda in wenigen einfachen Schritten:
Schritt 1: Laden Sie zunรคchst Ihren AWS Lambda-Code in einer beliebigen von AWS Lambda unterstรผtzten Sprache hoch. Java, Python, Go, and C# are some of the languages that are supported by the AWS Lambda function.
Schritt 2: Dies sind einige AWS-Dienste, mit denen Sie AWS Lambda auslรถsen kรถnnen.
Schritt 3: AWS Lambda unterstรผtzt Sie beim Hochladen von Code und den Ereignisdetails, bei denen er ausgelรถst werden soll.
Schritt 4: Executes AWS Lambda code when it is triggered by AWS services.
Schritt 5: AWS charges only when the AWS Lambda code executes, and not otherwise.
Dies geschieht in den folgenden Szenarien:
- Laden Sie Dateien in einen S3-Bucket hoch
- When an HTTP get/post endpoint URL ist getroffen
- For adding, modifying, and deleting Dynamo DB tables
- Im Prozess der Datenstromerfassung
- Push-Benachrichtigung
- Hosting der Website
- E-Mail-Versand
Hinweis: You should remember that you will be charged for AWS services only when the AWS Lambda code executes, otherwise you do not need to pay anything.
Ereignisse, die AWS Lambda auslรถsen
Here are the events which will be triggered when you use AWS Lambda.
- Insert, updating, and deleting data in a Dynamo DB table
- Um Push-Benachrichtigungen in SNS einzubinden
- Um nach dem Protokollverlauf in CloudTrail zu suchen
- Eintritt in ein S3-Objekt
- DynamoDB kann AWS Lambda immer dann auslรถsen, wenn der Tabelle Daten hinzugefรผgt, geรคndert oder gelรถscht werden.
- Helps you to schedule the event to carry out the task at a regular time pattern.
- รnderungen an Objekten in S3-Buckets
- Benachrichtigungen gesendet von Amazon SNS.
- AWS Lambda can be used to process the CloudTrail logs.
- Mit API Gateway kรถnnen Sie AWS Lambda auf GET/POST-Methoden auslรถsen.
AWS Lambda Concepts
Funktion: Eine Funktion ist ein Programm oder ein Skript, das in AWS Lambda ausgefรผhrt wird. Lambda รผbergibt Aufrufereignisse an Ihre Funktion, die ein Ereignis verarbeitet und seine Antwort zurรผckgibt.
Laufzeit: Runtime allows functions in various languages which run on the same base execution environment. This helps you to configure your function in the runtime. It also matches your selected Programmiersprache.
Ereignisquelle: Eine Ereignisquelle ist ein AWS-Dienst, z Amazon SNS, or a custom service. This trigger helps the function execute its logic.
Lambda-Schichten: Lambda-Ebenen sind ein wichtiger Verteilungsmechanismus fรผr Bibliotheken, benutzerdefinierte Laufzeiten und andere wichtige Funktionsabhรคngigkeiten. Diese AWS-Komponente hilft Ihnen auch dabei, Ihren Entwicklungsfunktionscode getrennt von dem unverรคnderlichen Code und den verwendeten Ressourcen zu verwalten.
Protokollstrรถme: Log stream allows you to annotate your function code with custom logging statements which help you to analyse the execution flow and performance of your AWS Lambda functions.
So verwenden Sie AWS Lambda
Now, we will learn how to use AWS Lambda with an AWS Lambda example:
Schritt 1) Open AWS Lambda URL
Zurรผck Nach https://aws.amazon.com/lambda/ and Get Started.
Schritt 2) Ein Konto erstellen
Next, create an account or sign in with your existing account.
Schritt 3) Edit the code and click Run
In the next Lambda page, edit the code and click Run.
Schritt 4) Ausgabe prรผfen
You will see the output.
AWS Lambda VS AWS EC2
Here are some major differences between AWS Lambda and EC2.
| Kenngrรถรen | AWS Lambda | AWS EC2 |
| Definition | AWS Lambda ist eine Platform as a Service (PaaS). Es hilft Ihnen, Ihren Backend-Code auszufรผhren und auszufรผhren. | AWS EC2 is an Infrastructure as a Service (IaaS). It provides virtualized computing resources. |
| Flexibilitรคt | Does not offer any flexibility to log in to compute instances. It allows you to choose a customized operating system or language runtime. | Offers the flexibility to select a variety of instances, custom operating systems, security patches, and network, etc. |
| Installationsprozess | You need to select your environment where you want to run the code and push the code into AWS Lambda. | Zum ersten Mal in EC2 mรผssen Sie das Betriebssystem auswรคhlen, die gesamte erforderliche Software installieren und dann Ihren Code in EC2 รผbertragen. |
| Umgebungsbeschrรคnkungen | It is restricted to few languages. | Keine Umgebungseinschrรคnkungen. |
AWS Lambda vs. AWS Elastic Beanstalk
Here are some major differences between AWS Lambda and Elastic Beanstalk.
| Kenngrรถรen | AWS Elastic Beanstalk | AWS Lambda |
| Hauptaufgabe | Stellen Sie die Apps in der AWS Cloud bereit und verwalten Sie sie, ohne sich um die Infrastruktur kรผmmern zu mรผssen, auf der diese Anwendungen ausgefรผhrt werden. | AWS Lambda is used for running and executing your back-end code. You cannot use it to deploy an application. |
| Auswahl von AWS-Ressourcen | It gives you the freedom to select AWS resources; for example, you can choose an EC2 instance which is optimal according to your application. | You cannot select the AWS resources, like a type of EC2 instance; Lambda offers resources based on your workload. |
| Art des Systems | Es ist ein zustandsbehaftetes System. | Es ist ein staatenloses System. |
Anwendungsfรคlle von AWS Lambda
AWS Lambda is used for a wide range of applications like:
- Helps you with the ETL-Prozess
- Ermรถglicht die Durchfรผhrung von Echtzeit-Dateiverarbeitung und Echtzeit-Stream-Verarbeitung
- Zum Erstellen von Webanwendungen verwenden
- Verwenden Sie in Amazon Produkte wie Alexa Chatbots und Amazon Echo/Alexa
- Datenverarbeitung (Echtzeit-Streaming-Analyse)
- Automated backups of everyday tasks
- Scalable back ends (mobile apps, IoT devices)
- Hilft Ihnen bei der Ausfรผhrung serverseitiger Backend-Logik
- Allows you to filter and transform data
Best Practices fรผr die Lambda-Funktion
Here are some best practices of AWS Lambda functions:
- Nutzen Sie die richtige โAuszeitโ.
- Utilize the functions of local storage which is 500MB in size in the /temp folder.
- Minimize the use of start-up code which is not directly related to processing the current event.
- Sie sollten die integrierte CloudWatch-รberwachung Ihrer Lambda-Funktionen verwenden, um Anforderungslatenzen anzuzeigen und zu optimieren.
Wann Sie AWS Lambda nicht verwenden sollten
Following are the situations where Lambda is surely not an ideal option:
- It is not appropriate to use AWS Lambda for software packages or applications which rely on calling underlying Windows RPCs.
- If it is used for custom software applications with licensing agreements like MS-Office document processing, Oracle Datenbanken usw.
- AWS Lambda should not be used for custom hardware processes such as GPU acceleration and hardware affinity.
Vorteile der Verwendung von AWS Lambda
Here are the pros/benefits of using AWS Lambda:
- AWS Lambda is a highly flexible tool to use.
- It helps you to grant access to resources, including VPCs.
- Author directly with a WYSIWYG-Herausgeber in der Konsole.
- Sie kรถnnen es als Plugin fรผr verwenden Eclipse und Visual Studio.
- As it is a serverless architecture, you do not need to worry about managing or provisioning servers.
- Sie mรผssen keine einrichten Virtuelle Maschine.
- Hilft Entwicklern, die Reaktion des Codes auf Ereignisse auszufรผhren und auszufรผhren, ohne eine Infrastruktur aufzubauen.
- You just need to pay for the compute time taken, only when your code runs.
- Sie kรถnnen die Leistung Ihres Codes in Echtzeit รผber CloudWatch รผberwachen.
- It allows you to run your code without provisioning or managing any other server.
- Helps you to execute the code only when needed.
- Sie kรถnnen es automatisch skalieren, um einige Anfragen pro Tag zu bearbeiten und sogar mehr als Tausende von Anfragen pro Sekunde zu unterstรผtzen.
- AWS Lambda kann mit Hilfe externer Ereignis-Timer konfiguriert werden, um geplante Aufgaben auszufรผhren.
- Lambda function in AWS should be configured with external events and timers so it can be used for scheduling.
- Lambda functions are stateless so that they can be scaled quickly.
- AWS Lambda ist schnell und fรผhrt Ihren Code innerhalb von Millisekunden aus.
Einschrรคnkungen von AWS Lambda
Hier sind die Vor- und Nachteile der Verwendung von AWS Lambda:
- Das AWS Lambda-Tool ist nicht fรผr kleine Projekte geeignet.
- AWS Lambda entirely relies on AWS for the infrastructure, so you cannot install any additional software if your code demands it.
- Concurrent execution has a default limit of 1,000 per Region, which can be increased on request.
- Its memory volume can vary between 128 MB and 10,240 MB.
- Die Ereignisanforderung sollte 128 KB nicht รผberschreiten.
- Lambda-Funktionen helfen Ihnen, ihre Protokolle nur in CloudWatch zu schreiben. Dies ist das einzige Tool, mit dem Sie Ihre Funktionen รผberwachen oder Fehler beheben kรถnnen.
- Its code execution timeout is limited to 15 minutes.




