AWS Environment Management and Versioned Integration Testing
Create application environments that use approved versions for integration testing (for example, Lambda aliases, container image tags, AWS Amplify branches, AWS Copilot environments)
Environment Management and Versioned Integration Testing
To ensure software reliability, AWS provides mechanisms to isolate "approved" versions of code for integration testing before they reach production. This guide explores how to leverage Lambda aliases, container tags, and branch-based environments to create stable testing targets.
Learning Objectives
- Distinguish between immutable versions and mutable aliases/tags across AWS services.
- Configure AWS Lambda aliases to point to specific function versions for staging.
- Implement container image tagging strategies for Elastic Container Service (ECS) deployments.
- Utilize AWS Amplify branches and AWS Copilot environments to isolate integration testing suites.
- Apply API Gateway stage variables to dynamically route traffic to specific backend versions.
Key Terms & Glossary
- Immutable Version: A "snapshot" of code/configuration that cannot be changed once created (e.g., Lambda Version 1).
- Alias/Pointer: A mutable label that points to an immutable version (e.g., a Lambda alias named "PROD" pointing to Version 5).
- Integration Testing: Testing where individual software modules are combined and tested as a group to verify functional, performance, and reliability requirements.
- Blue/Green Deployment: A strategy that uses two identical environments (Blue for old, Green for new) to minimize downtime and risk.
- Stage Variable: A name-value pair used in API Gateway to change the behavior of an API at runtime based on the deployment stage.
The "Big Idea"
In modern cloud development, you never test against a moving target. By using "Approved Versions" (versions that have passed unit tests and builds), you ensure that your integration tests are validating a static, known state of the application. This prevents the "it worked 5 minutes ago" syndrome caused by developers pushing overlapping changes to a shared environment.
Formula / Concept Box
| Service | Versioning Mechanism (Immutable) | Environment/Routing Label (Mutable) |
|---|---|---|
| AWS Lambda | Function Version (e.g., 1, 2) | Alias (e.g., DEV, STAGING, PROD) |
| Containers (ECR) | Image Digest / Semantic Tag (v1.0.1) | Moving Tag (e.g., :latest, :testing) |
| AWS Amplify | Git Commit Hash | Branch Name (e.g., feature-fix, main) |
| API Gateway | Deployment ID | Stage (e.g., v1, beta) |
| Elastic Beanstalk | Application Version | Environment (e.g., my-app-test-env) |
Hierarchical Outline
- Serverless Versioning (AWS Lambda)
- Versions: Snapshots of code + configuration ($ARN:1); cannot be modified.
- Aliases: Named pointers (ARN:PROD$); used for Canary Deployments (routing weight percentage).
- Containerized Environments (ECS/Copilot)
- Image Tags: Using specific SHAs or version numbers rather than
:latestfor testing. - AWS Copilot: Simplifies environment creation (
copilot env init) for isolated VPCs per stage.
- Image Tags: Using specific SHAs or version numbers rather than
- Web & Mobile (AWS Amplify)
- Branch-based Environments: Every Git branch can provision a full backend/frontend stack for isolated PR testing.
- API Routing (API Gateway)
- Stages: Logical references to deployments.
- Staging Variables: Passing the alias name to a Lambda backend via
${stageVariables.lambdaAlias}.
Visual Anchors
Lambda Alias Traffic Shifting
Promotion Pipeline
Definition-Example Pairs
- Lambda Alias: A pointer to a specific version of a function.
- Example: Creating an alias
TESTthat points to Version 4. Your integration test suite invokes theTESTARN. When Version 5 is ready, you simply update theTESTalias to point to 5 without changing the test suite's configuration.
- Example: Creating an alias
- Container Image Tag: A label applied to a Docker image in ECR.
- Example: Instead of pulling
my-app:latest, which might change during a test run, the CI/CD pipeline pullsmy-app:build-402. This ensures the exact code that passed unit tests is the one being integrated.
- Example: Instead of pulling
- Amplify Branch: A complete copy of the frontend and backend tied to a Git branch.
- Example: A developer creates a branch
fix-auth. Amplify automatically createshttps://fix-auth.d123.amplifyapp.comwith its own Cognito pool and AppSync API for isolated testing.
- Example: A developer creates a branch
Worked Examples
Scenario: Dynamic Lambda Integration Testing
Goal: Use API Gateway to test a new Lambda version without changing the API endpoint.
- Publish Version: Publish your Lambda function code, creating Version 3.
- Create Alias: Create an alias named
integration-testpointing to Version 3. - Configure API Gateway:
- In the Lambda Integration, set the Lambda Function name to:
MyFunction:${stageVariables.lambdaAlias}. - Grant API Gateway permission to invoke the alias:
aws lambda add-permission --function-name MyFunction:integration-test ....
- In the Lambda Integration, set the Lambda Function name to:
- Set Variable: In the
teststage of API Gateway, set the Stage VariablelambdaAliastointegration-test. - Result: Any calls to the
teststage endpoint automatically route to the approved Version 3.
Checkpoint Questions
- True or False: You can modify the code of a specific AWS Lambda Version once it has been published. (Answer: False, versions are immutable).
- Scenario: You want to test a new UI feature in AWS Amplify without affecting the live site. What is the most efficient AWS-native way to do this? (Answer: Connect a new Git branch to Amplify to create a branch-based environment).
- Why is it risky to use the
:latesttag for container images in a staging environment? (Answer: It is a mutable pointer; if a new image is pushed during the test, the environment becomes inconsistent). - How do Lambda Aliases facilitate Canary Deployments? (Answer: By allowing you to assign weights, e.g., 10% of traffic to the new version and 90% to the old version).