1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Create an alias for an AWS Lambda function

    Tomasz ŁakomyTomasz Łakomy
    awsAWS

    Every AWS resource has a unique ARN - Amazon Resource Name.

    This is true for AWS Lambda function versions as well, which means that every single time we publish a new version of a function, we'd need to update our backend to point to this new ARN.

    In this lesson we're going to learn how to create an alias for an AWS Lambda function so we're able to do following things without having to update any code calling the function:

    • Update the function with a new version while keeping the same ARN pointing to it
    • Have a single ARN that once executed is going to call either one of two versions by having a random 50/50 split - useful for A/B testing on production
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 0:00 We have a Lambda function with two different versions. There's version 1 and version 2. In order to use those different versions in our code, we have to point our backend towards either version 1 or version 2.

    0:11 In order to do that, we have to use something that is called an Amazon Resource Name. We can see that over here. Every single Amazon Web Services resource has a unique resource name that, for instance, we can see it over here for the version 1, and it's going to be different for version 2.

    0:27 What if we wanted to have a single resource name that we can use, in order to call the version 1 or version 2, 50 percent of the time? In order to do that, we have to use aliases. In order to create a new alias, go to Actions, Create alias. I'm going to call it production-test, and I'm going to put it to the version 1.

    0:47 You can also shift traffic between two versions, based on the weights and the percentage that you assign. I can click on Additional version, select 2, and it's going to be called 50 percent of the time, which is useful if you want to do some sort of AB testing, for instance, on production.

    1:02 Now we can see that our alias has been successfully created. Let's test it. I'm going to close the test event. Here in the details, we can see that I've currently called the version 2. If I call it again, it's going to be going to calling the version 1, because it's going to call each one of those versions 50 percent of the time.

    1:19 Aliases are not only useful for this kind of testing. If I were to go over here to the latest version and create a version 3 of this function, like this, save it, and create a new version by publishing it, version number 3, right now, I can point this alias that I've created.

    1:39 Go to aliases, production-test, and I'm going to switch it. It's going to either call the version 3 or the version 2 of this function, 50 percent of the time. It is going to keep exactly the same Amazon Resource Name, which is very useful, because now we can update our versions without having to modify the code that is actually going to call this alias.

    2:01 If I test it now, expand details, I'm going to see that it is either version 2 or version 3 that is being called.