Notes from AWS Chalk session at AWS re:Invent 2018 – Lambda@Edge optimisations

CATEGORIES

Blog

Lambda@Edge makes it possible to run Lambda code in Edge locations to modify viewer/origin requests. This can be used to modify HTTP headers, change content based on user-agent and more. We’ve written about it previously, so feel free to read this blog post if you want an introduction: https://nordcloud.com/aws-lambdaedge-running-lambda-code-in-edge-locations/

There are quite a few limitations for Lambda@Edge which depends on which request event you are responding on. For example the maximum response that is generated by the lambda function is totally different depending on if it is a viewer or origin response (40 Kb vs 1 Mb). The function in itself also has limits, such as maximum 3GB of memory allocation and 50 Mb zipped deployment package size.

This means that most use-cases have a need for optimisation. First thing first: evaluate if you really need to use Lambda@Edge. Cloudfront currently have a lot of functionality that is possible to take part of before trying to reinvent the wheel – caching depending on device, selecting headers to base caching on, regional blocks with WAF, etc. Even your origin can sometimes handle header rewrites and other header manipulation, which means that there is no need to spend the time to build it yourself. So you should only use Lambda@Edge if you know that cloudfront can’t do it and that there will be a benefit to rendering or serving your content at the edge.

Optimise before the function

If you’ve decided to use Lambda@Edge you should first look into the optimisations you can do before the function is invoked by the event. Cloudfront does a lot of optimisations for you. It groups requests so that if the response time of the object fetch is the same it will put them together and do only one get instead of sending all of them to the origin. Note that cloudfront is a multilayered CDN which will try to catch the cache from the closest location in cloudfront on miss in a specific region as well, so there is no need to build multi-region caching yourself. Another thing to look at in cloudfront is the origin paths that the event reacts upon. Perhaps the function only needs to react on a very specific HTTP path. If possible it is also always better to let the function react on origin events instead of viewer events which in turn makes the amount of events to react upon fewer and you have higher limitations for function size, response time and resource allocation.

Coding optimisations

When writing the function you should try to utilise global variables as much as possible since they are re-used between invocations and cached on the workers for a couple of hours. Small things such as keeping TCP sockets usable and perhaps using UDP instead of TCP can make a difference especially since Lambda@Edge is synchronous.

Deployment testing

When deploying the function, look at minimising the code with different tools such as browserify. Also note that Lambda@Edge can be deployed with different memory allocations so make sure that you test which size gives you the best bang for the buck – sometimes raising the memory usage from 128 Mb to 256 Mb gives you much faster responses without costing that much more.

S3 performance

If you are fetching content from S3, try using S3 Select to get just what you need from a subset of data from an object by using simple SQL expressions, and even better, try to use cached content in Cloudfront instead of trying to fetch it from S3 or other origins. This makes a lot of sense especially if the data can be cached.

Last but not least: Remove the function when not in use. Don’t use Lambda@Edge if you don’t need to anymore.

If you’d like to learn more about moving your business to the Cloud, please contact us here.

Blog

Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

Blog

Building better SaaS products with UX Writing (Part 3)

UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

Blog

Building better SaaS products with UX Writing (Part 2)

The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

Get in Touch

Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.








    Two new Amazon CloudFront Edge Locations in the Nordics

    CATEGORIES

    Blog

    Amazon just announced really exciting news to the current and future Nordic customers.

    Amazon CloudFront coverage in the Nordic countries has developed very rapidly. In 2016 Amazon had one Amazon CloudFront edge location in Stockholm. Today Amazon has a total of 6 edge locations in the Nordic region – three in Stockholm and one in Copenhagen, Helsinki and Oslo.

    The current Amazon CloudFront edge location coverage, together with the expected Sweden Region launch later this year, makes Amazon CloudFront hard to pass when considering a solution for content delivery and DDoS protection in the region.

    FASTER CONTENT DELIVERY AND GREATER BANDWIDTH

    The new Amazon CloudFront Edge locations mean faster content delivery and greater bandwidth in the whole region with the AWS hallmark ease of use and pay-as-you-go pricing scheme. The locations bring the AWS private data transfer backbone closer to the customers for improved security. In addition, Amazon CloudFront plays a crucial role in the delivery of managed DDoS protection with the AWS Shield Advanced.

    “Our Nordic customers have benefited from Amazon CloudFront´s ease of use and pay-as-you-go model for years. The speed of launching new edge locations is really remarkable as the service performance improves without any action or additional costs to our customers. As for any other Amazon CloudFront location, we are able to offer preferential pricing for significant customer use,” says Jaakko Kontiainen, Nordcloud Alliance Lead for AWS.

    AMAZON CLOUDFRONT

    Amazon CloudFront is a global content delivery network (CDN) service that securely delivers data, videos applications, and APIs to your viewers with low latency and transfer speeds. CloudFront is integrated with AWS – both physical locations that are directly connected to the AWS global infrastructure, as well as software that works seamlessly with services including AWS shield for DDoS mitigation, Amazon S3, Elastic Load Balancing, or Amazon EC2 as origins for your applications, and AWS Lambda to run custom code close to your viewers.

    KEY BENEFITS OF CLOUDFRONT

    Some of the key benefits include extensive integration with other AWS services, ease of use, a cost-effective pay-as-you-go pricing scheme, and the growing global distribution network exhibited by the latest Edge location. For more information, please go to: https://aws.amazon.com/cloudfront/details/

    Nordcloud is an AWS Premier Consulting Partner and participates in the Amazon Cloudfront Service Delivery Program recognising our experience in delivering solutions using Amazon CloudFront. If you would like to talk to us further about Amazon CloudFront, other Amazon Web Service offerings, or migrating your business onto the AWS Cloud, please contact us here.

    Blog

    Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

    When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

    Blog

    Building better SaaS products with UX Writing (Part 3)

    UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

    Blog

    Building better SaaS products with UX Writing (Part 2)

    The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

    Get in Touch

    Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.








      New Amazon CloudFront Edge location arrives in Finland!

      CATEGORIES

      Blog

      Congratulations if you distribute content to customers in Finland, and a special congratulations if you are already doing it through Amazon CloudFront!

      Amazon Web Services have just announced the opening of the first Amazon CloudFront Edge location in Finland. This means that you can now distribute your content to your customers in Finland faster, with greater bandwidth and with the simplicity that AWS can offer.

      “As an AWS Consulting Partner originating in Finland, we’re thrilled how this new Edge location delivers faster service to the Finnish end users. Better yet, our current Finnish customers will get these improvements without any action or additional costs,” says Jaakko Kontiainen, Nordcloud Alliance Lead for AWS.

      Amazon CloudFront

      Amazon CloudFront is a global content delivery network (CDN) service that securely delivers data, videos applications, and APIs to your viewers with low latency and transfer speeds. CloudFront is integrated with AWS – both physical locations that are directly connected to the AWS global infrastructure, as well as software that works seamlessly with services including AWS shield for DDoS mitigation, Amazon S3, Elastic Load Balancing, or Amazon EC2 as origins for your applications, and AWS Lambda to run custom code close to your viewers.

      Some of the key benefits include extensive integration with other AWS services, ease of use, a cost-effective pay-as-you-go pricing scheme, and the growing global distribution network exhibited by the latest Edge location.

      If you would like to talk to us further about Amazon CloudFront, other Amazon Web Service offerings, or migrating your business onto the AWS Cloud, please contact us here

      Blog

      Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

      When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

      Blog

      Building better SaaS products with UX Writing (Part 3)

      UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

      Blog

      Building better SaaS products with UX Writing (Part 2)

      The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

      Get in Touch

      Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.








        Deliver your content quickly with Amazon Cloudfront

        CATEGORIES

        Blog

        This is especially true for all kinds of media services, where low latency and high data transfer speeds are crucial. This is where Cloudfront comes into play.

        Think of a postman, who happens to live in a country with only one, central post office. Every morning he goes to that office, picks up the mail, and delivers it to the recipients. The next day he goes to post office, picks up the mail, delivers it, and so on.

        Even if there were 100 000 postmen and they all would be super quick, there would probably be a lot of delays, since there is only the central post office where all the mail needs to be picked up from.

        ..Not to mention, how bad that would be for traffic overall. Imagine driving there.

        What if instead of a centralized post office, there were post offices in each city around the country for daily deliveries, and only the packages so big which need to be delivered in a truck would be delivered from the central office?

        Much faster deliveries and less traffic on roads.

        This is a simplified model of how Amazon Cloudfront works. It is a Content Delivery Network (CDN) based on a network of so-called edge locations. Edge locations are worldwide-spread access points (data centers) for end users in AWS network, and are specifically used by Amazon Web Services to deliver content to end users with low latency. Edge locations can be found in most major cities around the world – at the moment there are 54 of them, and new ones are being built all the time.

        More static content is usually stored in so-called origin servers, often in Amazon S3 buckets. For example, your static images & videos (since they don’t change that often) can be stored in origin servers, while streaming media & constantly updating content can be stored in Cloudfront.

        If you’re operating globally, or just need content distributed quickly in high speed and low latency – such as streaming videos or basically media in any format, it is a good idea to consider putting Cloudfront into use. If you are an existing AWS user, Amazon Cloudfront will certainly simplify the management of your content distribution and most likely lower your costs.

        Blog

        Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

        When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

        Blog

        Building better SaaS products with UX Writing (Part 3)

        UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

        Blog

        Building better SaaS products with UX Writing (Part 2)

        The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

        Get in Touch

        Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.