With this tutorial, let’s learn to deploy an AWS Serverless Application using AWS Serverless Application Model (AWS SAM) and configure events with Amazon EventBridge. AWS SAM is an open-source framework for developing serverless applications. It simplifies expressing functions, APIs, databases, and event source mappings. It is important to note that AWS SAM is an extension of AWS CloudFormation, which is AWS’ Infrastructure as Code (IaC) tool. You can define resources using CloudFormation in your AWS SAM template and use the full suite of resources, intrinsic functions, and other template features available in AWS CloudFormation for creating resources in your AWS SAM template.
The first thing you have to do is upload images to an S3 bucket on Amazon Web Services. As a result of this action, an event is raised, which invokes a Lambda function, which will resize the image and place it in a different bucket in S3.
AWS SAM CLI (If you use AWS Cloud9, it is already installed)
Using Amazon EventBridge, you can configure events as follows:
- Visit the Serverlessland Patterns Collection and select Amazon S3 to Amazon EventBridge to AWS Lambda. It deploys an S3 bucket, a Lambda function, an EventBridge rule, and IAM resources required to run the application on AWS.
2. In your terminal, copy and paste the cloning instructions.
3. Run sam deploy –guided to deploy the pattern
4. A success message appears:
5. Navigate to the EventBridge console and select Rules. Next, choose the rule that was created by AWS SAM (beginning with sam-app). The event source is S3 and the rule is invoked when an image is placed in the source bucket.
6. You will notice that the event target is the Lambda function you created from the AWS SAM template.
8. Choose Upload from the Objects tab and upload an image.
9. Go to the Lambda console and choose your Lambda function (starting with sam-app). Go to the Monitor tab and click View Logs in CloudWatch.
10. In the logs, you can see the event that triggered the Lambda function:
That’s all. In this post, we understood the concept of event-driven architecture and walk through a tutorial on creating an event-driven application utilizing the Serverlessland Patterns Collection.
To read about why one shouldn’t use Monolith Serverless Application: