The goal of this tutorial is to guide you through the process of building event-driven applications in a serverless architecture. We'll delve into the main concepts behind event-driven computing and serverless architecture, and then we'll build a simple application to put these concepts into action.
By the end of this tutorial, you should be able to:
Prerequisites:
Event-driven computing is a programming paradigm in which the flow of the program is determined by events such as user actions, sensor outputs, or messages from other programs. Event-driven programming is widely used in graphical user interfaces, real-time systems, and serverless computing.
Serverless does not mean there are no servers involved. Instead, it means that you don't have to manage servers. The cloud provider takes care of the server management, and you just focus on your code.
AWS Lambda is a serverless computing service provided by Amazon Web Services. It allows you to run your code in response to events, such as changes to data in an Amazon S3 bucket or an update to a DynamoDB table.
Let's create a simple AWS Lambda function that gets triggered when a file is uploaded to an S3 bucket.
// This is the main Lambda function
exports.handler = async (event) => {
// Get the object from the event
var s3object = event.Records[0].s3.object;
// Log the filename to the console
console.log('File uploaded:', s3object.key);
};
In the above example, exports.handler
is the main Lambda function that AWS will call when an event occurs. The event
parameter contains information about the triggering event. In this case, we're interested in the s3.object
data, which contains information about the uploaded file.
Key Points covered:
Next steps:
Additional resources:
Remember to test your applications thoroughly and seek help if you get stuck. Happy coding!