Skip to main content

Posts

Showing posts from January, 2023

How to run a scheduled job with EventBridge and Lambda

Greetings! Triggering a piece of code by a timer has multiple use cases. Hence I am going to talk about how can we do it using AWS EventBridge. Run daily/monthly reports Send reminders Scheduled data mining Send marketing emails The source code for this article can be found here . Let's learn how we can achieve this architecture using AWS EventBridge and Lambada. EventBridge AWS EventBridge is a serverless event bus service that you can use to connect your applications with data from a variety of sources including AWS services and external services. An event is an indicator of a change in the environment. When an event receives, it applies a rule to route the event to a target. Rules match events to targets based on either an event pattern or on a schedule which is the focus of this article. Let's build the architecture using the serverless framework. Initialize the project Let's initialize the project using serverless cli. mkdir eventbridge-lambda-t

How to secure an API using Lambda authorizer

Greetings! I wrote about creating a CRUD API using API Gateway and Lambda in a previous article. However, I did not talk about how to secure it. In this article, I am going to explain how we can use Lamda Authorizer to secure an API. The complete code is here . Lambda Authorizer Lambda authorizer is an API gateway feature to control access to your API. It uses the provided lambda function to do so. This is useful when we want to implement a custom authorization scheme that uses a bearer token (JWT) or a request parameter. Token authorizer - uses a token to authorize uses. It receives the caller's identity in a bearer token, such as a JSON Web Token (JWT) or an OAuth token Request authorizer - uses parameters, headers, and query strings to pass user identity In this article, we use a token-based authorizer. For simplicity, we expect our token to be "cat". Initialize the project Let's initialize the project using the serverless framework.

Handling file uploads with S3 and Labmda

Greetings File uploading and invoking logic based on that can be a common business scenario. We can categorize a few such use cases as below. Image resizing such as thumbnail creation Read JSON file content and invoke logic Image processing The source code for this article can be found here . Let's learn how we can achieve this architecture using AWS S3 and Lambada. S3 Events We can enable events for a particular S3 bucket for bucket operations such as file added, and updated. When we enable this feature, we need to provide the event recipient such as a lambda function. When the bucket operations occur, the provided target will be invoked. Let's build the architecture using the serverless framework. Initialize the project Let's initialize the project using serverless cli. mkdir s3-lambda-trigger cd s3-lambda-trigger serverless create --template aws-nodejs npm init -y npm install @aws-sdk/client-s3 --save We have installed the S3 dependency