Lambda aliases

5 minutes 5 Questions

AWS Lambda aliases are pointers to specific Lambda function versions, providing a powerful mechanism for managing function deployments and traffic routing. Think of an alias as a named reference that can be updated to point to different function versions without changing the application code that invokes it. When you deploy a Lambda function, AWS creates versions that are immutable snapshots of your code and configuration. An alias acts as a mutable pointer to one or more of these versions. For example, you might create aliases named 'prod', 'staging', and 'dev' that point to different versions of your function. Key benefits of Lambda aliases include: 1. **Stable Endpoints**: Applications can invoke a function using an alias ARN, which remains constant even when the underlying version changes. This eliminates the need to update client configurations during deployments. 2. **Traffic Shifting**: Aliases support weighted traffic distribution between two versions. You can route a percentage of traffic to a new version while maintaining most traffic on the current stable version. This enables canary deployments and blue-green deployment strategies. 3. **Environment Separation**: Different aliases can represent different environments, making it easier to promote code through development stages by simply updating which version an alias points to. 4. **Rollback Capability**: If issues arise with a new version, you can quickly update the alias to point back to a previous working version. Aliases can also have their own resource policies and can be configured with provisioned concurrency settings. Each alias maintains its own CloudWatch metrics, allowing you to monitor performance per environment. To implement traffic shifting, you specify a primary version and an additional version with a weight between 0.0 and 1.0. For instance, setting an additional version weight of 0.1 routes 10% of invocations to that version while 90% goes to the primary version. This gradual rollout approach minimizes risk during deployments.

AWS Lambda Aliases: Complete Guide for AWS Developer Associate Exam

What are Lambda Aliases?

Lambda aliases are pointers to specific Lambda function versions. Think of them as friendly names that reference a particular version of your function. For example, you might have an alias called 'PROD' pointing to version 5, or 'DEV' pointing to version 8.

Why are Lambda Aliases Important?

Lambda aliases solve several critical deployment challenges:

• Stable Endpoints: Aliases provide a fixed ARN that doesn't change, even when you update the underlying version
• Environment Separation: Create aliases like DEV, TEST, and PROD to separate your deployment stages
• Blue/Green Deployments: Easily switch traffic between versions by updating the alias pointer
• Canary Deployments: Route a percentage of traffic to a new version for testing
• Rollback Capability: Quickly point an alias back to a previous version if issues arise

How Lambda Aliases Work

1. Creating Aliases: You create an alias and point it to a specific published version (not $LATEST)

2. ARN Structure: Alias ARN format is: arn:aws:lambda:region:account:function:function-name:alias-name

3. Weighted Aliases: A single alias can point to TWO versions simultaneously with configurable traffic weights. For example, 90% to version 5 and 10% to version 6

4. Updating Aliases: Change which version an alias points to with a simple update operation

Key Characteristics

• Aliases CANNOT point to $LATEST - only to published, immutable versions
• Each alias has its own unique ARN
• Aliases can have their own resource policies
• Event source mappings can use aliases
• API Gateway can invoke Lambda using alias ARNs

Weighted Alias Traffic Shifting

This feature enables canary deployments:
• Assign weights between 0.0 and 1.0 to two versions
• Both versions must have the same Dead Letter Queue (DLQ) configuration or no DLQ
• Both versions must have the same $LATEST (non-published) code
• Great for gradual rollouts and A/B testing

Exam Tips: Answering Questions on Lambda Aliases

• If a question mentions stable endpoints or fixed ARNs for Lambda - think aliases

• If you see canary deployment or traffic splitting for Lambda - weighted aliases is the answer

• Remember: Aliases point to VERSIONS, not to $LATEST

• Blue/Green deployment scenarios: Aliases allow instant traffic switching between versions

• When API Gateway needs to invoke different Lambda versions based on stage - use stage variables with Lambda aliases

• Traffic shifting percentages: Maximum of TWO versions per alias for weighted routing

• Rollback scenarios: Update the alias to point to the previous working version

• Environment-based questions: Aliases named after environments (PROD, DEV) are a common pattern

Common Exam Scenarios

1. Scenario: Need to test new code with 10% of production traffic
Answer: Use weighted alias pointing 90% to current version, 10% to new version

2. Scenario: Application needs consistent Lambda endpoint across deployments
Answer: Use alias ARN instead of version-specific ARN

3. Scenario: Quick rollback required after deployment failure
Answer: Update alias to point to previous version

4. Scenario: API Gateway stages need different Lambda code
Answer: Use stage variables mapped to Lambda aliases
Test mode:
More Lambda aliases questions
28 questions (total)

Other Deployment concepts