Canary Code Deployments and Testing Within AWS Lambda

Hands-On Lab

 

Photo of Andru Estes

Andru Estes

Training Architect

Length

00:30:00

Difficulty

Advanced

Welcome to this Learning Activity for working with Canary Function Deployments within AWS Lambda. This Learning Activity provides hands-on experience with creating different Lambda function versions and aliases, which will then be used for canary testing. The primary focus will be on these AWS Lambda features: 1. Lambda Console 2. Function Code 3. Function Versions 4. Function Aliases 5. Alias Weighting (Routing Config) 6. API Gateway Using versions and aliases allows you to follow today's best practices for code deployment and progression.

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.

Canary Code Deployments and Testing Within AWS Lambda

Introduction

In this hands-on lab, we will create different Lambda function versions and aliases, which will then be used for canary testing.

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: Function
    • Runtime: Python 2.7
    • Role: Choose an existing role
    • Existing role: lambda_exec_role_LA
  4. Click Create function.
  5. On the Function page, scroll to the Function code section.
  6. Replace the existing code there with the code from GitHub.
  7. Click Save.

Publish Our First Version and Create Our First Alias

  1. At the top, click Actions and select Publish new version.
  2. Give it a description (e.g., "Version 1"), 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.

Create and Deploy Our API Within API Gateway

  1. Navigate to API Gateway in a new browser tab.
  2. Click Get Started.
  3. Choose New API, and set the following values:
    • API name: Hello
    • Description: Hello
    • Endpoint Type: Regional
  4. Click Create API.
  5. On the Resources page, click Actions and select Create Resource from the dropdown.
  6. Give it a Resource Name of "hello".
  7. Click Create Resource.
  8. Make sure you have the /hello resource selected, click Actions, and select Create Method.
  9. In the Options dropdown, select GET and then click the checkmark.
  10. In the /hello - GET - Setup window, set the following values:
    • Integration type: Lambda Function
    • Use Lambda Proxy integration: Check
    • Lambda Region: us-east-1
    • Lambda Function: Function:PROD
    • Use Default Timeout: Check
  11. Click Save.
  12. Click Actions and select Deploy API.
  13. In the Deploy API dialog, set the following values:
    • Deployment stage: [New Stage]
    • Stage name: One
    • Stage description: One
    • Deployment description: One
  14. Click Deploy.
  15. In the One - GET - /hello section, open the invoke URL in a new browser tab. We should see the message we added in our Lambda code.

Publish Version 2 of Our Function and Update Our Alias

  1. In the Lambda console, click the Alias:PROD dropdown and select $LATEST.
  2. In the Function code section, replace the existing code with the code from GitHub.
  3. Click Save.
  4. Click Actions and select Publish new version.
  5. Give it a description (e.g., "Version 2"), 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 Additional Version to 2.
  8. Set the weight to 50%.
  9. Click Save.
  10. Refresh the browser tab with the invoke URL a few times to verify you are getting different versions of code based on the response.

Conclusion

Congratulations on completing this hands-on lab!