What is the lambda@edge service?
Published: 2022-05-29 16:54:10


What is the lambda? 
Lambda is a service where you can run your application without a server. You only pay for the processing time you use.

What is the lambda@edge service?

Lambda@Edge is a feature of Amazon CloudFront that allows you to run your application closer to end-users, improve performance and reduce latency.
With Lambda@Edge you don't have to manage regions in multiple locations around the world and incur high costs.

What is the difference between lambda vs lambda@edge?

The major difference is in the API Gateway and the Lambda are regional service. Lambda@Edge is a global service. Lambda@Edge allows you to execute the logic across multiple location. This is the main difference between Lambda and Lambda@Edge, remaining all the things are mostly similar.. The main difference between Lambda and Lambda@Edge is everything else is similar.


The example projects 
In this project, we will perform image resizing with lambda@edge. if you want to use the lambda@edge service you have to use the north Virginia service. Other regions unfortunately do not support it.

Create an S3 bucket and set it to this policy.
`{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": "arn:aws:s3:::example-lambda-edge/*"
        }
    ]
}`

We import the relevant template to the cloudformation service. I prefer to import with s3 link. You can find the relevant link in the github link in the resources section.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btutgvlsegin1uwpevxj.png)
We're going to the next step.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vv7jyouu0spo2yge6gh.png)

Then we change only 3 options. Pay attention to the S3 bucket name.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2ghax4zz63lv4lyblup.png)
We're going to the next step.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgmy655rr227mfl5p4k7.png)

Click the Next button on the next pages. We don't need to take any action.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqimooy1xi7rimcp17zy.png)

  ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/deffvepe8teehgm9rhdx.png)

We import successful 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6v3jk3y19jrsf0z1ywt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g57dpmaxjyftug1t5m1k.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3eos4m5xqmgf5yn1yen.png)

Here we deploy to the lambda@edge service

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbruqnpoxgf5o2tt2c30.png)

We deploy on the first lambda@edge.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jex25kj3l6gpjqhi5bes.png)
 
We deploy 2 services on lambda@edge.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgq0q9t4gifjwm3o6ar1.png)
Our deployment is successful.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfdeh8ruahoc9m6rihe6.png)
 
Then we test it. You can reach it from the link to try more different modules.

References
https://aws.amazon.com/lambda/edge/
https://aws.amazon.com/blogs/networking-and-content-delivery/resizing-images-with-amazon-cloudfront-lambdaedge-aws-cdn-blog/
http://www.thumbor.org/
https://www.youtube.com/watch?v=uVk-ffHeV7c&ab_channel=KoffeeWithKode
https://docs.aws.amazon.com/solutions/latest/serverless-image-handler/template.html