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 different versions of an AWS Lambda function

    Tomasz ŁakomyTomasz Łakomy
    awsAWS

    It's awesome that we can edit a lambda function either directly in the AWS Console, or by uploading a new zip file or uploading it to an S3 bucket whenever we want.

    Although at some point we'd like to effectively "freeze" a function to ensure that no one can modify it anymore, for instance when we want to deploy this function to a production environment.

    In this lesson we're going to learn how to create different immutable versions of an AWS Lambda function, how to switch between them and how to call them separately

    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 Start by creating a new Lambda function. I'm going to go ahead and call this function versions, and I'm going to create it. Let's create a default test event so we can call this function. I'm going to call this event myTestEvent and save it.

    0:15 You will notice that every single time we'll create a Lambda function, we are able to go ahead over here and add a console.log or something. In other words, we can edit and save this function.

    0:26 What if we want to have an immutable version of this function? In other words, we would like to be able not to modify this function because, for instance, we're going to deploy it to our production environment.

    0:35 In order to do that we have to use version. You can find the different versions of your Lambda functions under qualifiers. Over here, we can see that we have already a $LATEST version. You will always have the $LATEST version by default. This is the only version that you are allowed to modify.

    0:50 Let's modify this function by adding event version 1. Save this function, and I'm going to go to Actions and Publish a new version. I'm going to go to version 1 and publish it.

    1:04 Over here, we can see that I have successfully created version 1 of my function, which is called versions. As we discussed, I am not able to modify this code. Code and handle editing is only available for the latest versions.

    1:15 I can click here and go to $LATEST. I'm going to create an event version 2. Save this. I'm going to publish a new version which I'm going to call version 2. Publish it.

    1:31 Right now, we have two different versions of this function. If I were to call this one and check out the details, I'm going to see over here in the log that I am calling the version 2. if I were to switch to the version 1 and call this function, I'm going to see that I'm calling the version 1. I am not able to modify either version 1 or version 2.