Skip to main content

Working with Aliases and Versions for Your AWS Lambda Functions

Hands-On Lab

 

Photo of

Training Architect

Length

00:30:00

Difficulty

Advanced

Welcome to this Learning Activity where we will be creating a Lambda function, and then building a new version using updated code. Once we have two separate versions, we will then see how we can utilize aliases for rapid code progression. After everything is all said and done, you will have some hands-on experience with real-life scenarios, dealing with updating and deploying Lambda code. The primary focus will be on these AWS features: 1. Lambda Console 2. Function Code 3. Lambda Versions & Aliases AWS Lambda allows you to create functions and only have to worry about managing your code!

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Aliases and Versions for Your AWS Lambda Functions

Introduction

In this hands-on lab, we we will create a Lambda function, and then build a new version using updated code. Once we have two separate versions, we will then see how we can utilize aliases for rapid code progression.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

All of the code used in the lesson is available for download here.

Create Your Lambda Function

  1. Navigate to Lambda.
  2. Click Create a function.
  3. Make sure the Author from scratch option at the top is selected, and then use the following settings:
    • Name: CreateThumbnail
    • Runtime: Node.js 8.10
    • Role: Choose an existing role
    • Existing role: lambda_exec_role_LA
  4. Click Create function.
  5. On the CreateThumbnail page, scroll to the Function code section.
  6. Set Code entry type to Upload a .ZIP file and upload the file from GitHub.
  7. Click Save.
  8. In the Environment variables section, set the following values:
    • Key: DST_BUCKET
    • Value:
      • Navigate to S3 in a new browser tab.
      • Click the listed bucketb.
      • Copy the cfst name at the top.
      • Back in the Environment variables section, paste the value in for Value here.
  9. In the Basic settings section, set the following values:
    • Memory (MB): 1024 MB
    • Timeout: 10 seconds
  10. Click Save.

Configure Your Event Source Mapping (S3 Trigger)

  1. In the Designer section, select S3.
  2. In the Configure triggers section, set the following values:
    • Bucket: bucketa
    • Event type: Object Created (All)
    • Filter pattern: .jpg
    • Enable trigger: Check
  3. Click Add, and then Save.

Test Your Function

  1. In a new browser tab, navigate to S3.
  2. Click to open bucketa.
  3. Upload a .jpg image to bucketa.
  4. In the Lambda console, select the Monitoring tab and wait a few seconds to verify your function was invoked.
  5. In S3, check for the resized image in bucketb.

Create a New Version and Alias

  1. At the top of the Lambda console, click Actions and select Publish new version.
  2. Give it a description (e.g., "Ver A"), and click Publish.
  3. In the Actions dropdown, select Create alias, and set the following values:
    • Name: PROD
    • Description: Prod
    • Version: 1
  4. Click Create.

Recreate Your Event Source Mapping

  1. Verify you are working on the new PROD alias you created. The ARN should be visible on the top right with :PROD on the end.
  2. In the Designer section, select S3.
  3. In the Configure triggers section, set the following values:
    • Bucket: bucketc
    • Event type: Object Created (All)
    • Filter pattern: .jpg
    • Enable trigger: Check
  4. Click Add, and then Save.
  5. In the S3 tab, open bucketc and upload the same .jpg as before.
  6. In the Lambda console, select the Monitoring tab and wait a few seconds to verify your function was invoked.

Publish a Second Version and Remap Your Alias

  1. In the Lambda console, click the Alias:PROD dropdown and select $LATEST.
  2. In the Function code section, under //constants, set the MAX_WIDTH and MAX_HEIGHT to 100.
  3. Click Save.
  4. Click Actions and select Publish new version.
  5. Give it a description (e.g., "Ver B"), and click Publish.
  6. In the Version: 2 dropdown, select the Aliases tab and click the PROD alias.
  7. Scroll to the Aliases section, and set the Version to 2.
  8. Click Save.
  9. In the S3 tab, open bucketc and upload the same .jpg as before.
  10. In the Lambda console, select the Monitoring tab and wait a few seconds to verify your function was invoked.
  11. In S3, check for the resized image in bucketb.

Conclusion

Congratulations on completing this hands-on lab!