Create an alias for an AWS Lambda function

Tomasz Łakomy
InstructorTomasz Łakomy
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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

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.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today