Study Guide: Managing Application Environments in AWS
Manage application environments by using AWS services
Managing Application Environments in AWS
This study guide covers the essential skills for the AWS Certified Developer - Associate (DVA-C02) exam regarding the creation, management, and deployment of application environments using AWS services.
Learning Objectives
After studying this material, you should be able to:
- Implement and manage isolated application environments (Dev, Test, Prod) using API Gateway stages and Lambda aliases.
- Deploy infrastructure using Infrastructure as Code (IaC) tools like AWS SAM and CloudFormation.
- Configure deployment strategies including Blue/Green, Canary, and Rolling updates.
- Manage application artifacts and dependencies for consistent deployments across environments.
- Automate testing within CI/CD pipelines using Amazon Q Developer and JSON test events.
Key Terms & Glossary
- Infrastructure as Code (IaC): The practice of managing and provisioning computing infrastructure through machine-readable definition files (e.g., YAML/JSON).
- Lambda Alias: A pointer to a specific version of a Lambda function (e.g.,
PRODpointing to version 5). - API Gateway Stage: A logical reference to a lifecycle state of your API (e.g.,
dev,prod). Each stage has its own configuration and URL. - Blue/Green Deployment: A strategy that involves running two identical production environments (Blue and Green) to minimize downtime and risk.
- Canary Deployment: A strategy where a small percentage of traffic is shifted to the new version to test stability before a full rollout.
- Staging Variables: Name-value pairs associated with an API Gateway stage used to dynamically pass configuration to backends like Lambda.
The "Big Idea"
[!IMPORTANT] The core philosophy of modern AWS environment management is Environment Isolation and Automation. By using Infrastructure as Code and CI/CD pipelines, developers ensure that the environment used for testing is an exact mirror of production, reducing "it works on my machine" bugs and allowing for safe, automated rollbacks.
Formula / Concept Box
Deployment Strategy Comparison
| Strategy | Downtime | Traffic Shifting | Rollback Speed | Best For... |
|---|---|---|---|---|
| All-at-once | High | 100% immediate | Slow | Non-critical dev environments |
| Rolling | None | Incremental (Batch) | Moderate | EC2 / On-premises clusters |
| Canary | None | Percent-based (e.g., 10%) | Very Fast | High-traffic web applications |
| Blue/Green | None | Flip via DNS/Load Balancer | Instant | Zero-downtime, high-risk updates |
Hierarchical Outline
- I. Environment Creation and Configuration
- API Gateway Stages: Used to differentiate environments. Utilize Stage Variables to point to different backend resources.
- Lambda Aliases: Enable weighted traffic shifting between versions for testing new code.
- AWS AppConfig: Manages application configurations without requiring code redeployments.
- II. Infrastructure as Code (IaC)
- AWS CloudFormation: The foundation for provisioning AWS resources via templates.
- AWS SAM (Serverless Application Model): Extension of CloudFormation optimized for serverless (Lambda, API Gateway, DynamoDB).
- III. Deployment Orchestration
- AWS CodePipeline: Automates the build, test, and deploy phases.
- AWS CodeDeploy: Manages the actual deployment logic (Canary/Linear) for Lambda, ECS, and EC2.
- IV. Testing and Verification
- JSON Test Events: Standardized payloads for testing Lambda functions.
- Amazon Q Developer: Used for generating automated tests and assisting in code debugging.
Visual Anchors
CI/CD Workflow for Environments
Blue/Green Traffic Shifting
\begin{tikzpicture}[node distance=2cm, every node/.style={rectangle, draw, minimum width=3cm, minimum height=1cm, align=center}] % Nodes \node (LB) [fill=gray!20] {Route 53 / ALB}; \node (Blue) [below left of=LB, xshift=-1cm, fill=blue!20] {Blue (V1 - Current)}; \node (Green) [below right of=LB, xshift=1cm, fill=green!20] {Green (V2 - New)};
% Arrows
\draw[->, line width=2pt, blue] (LB) -- node[left] {90\%} (Blue);
\draw[->, line width=1pt, green, dashed] (LB) -- node[right] {10\% (Canary)} (Green);
% Labels
\node[draw=none, below=0.5cm of Blue] {Stable Environment};
\node[draw=none, below=0.5cm of Green] {Testing Environment};\end{tikzpicture}
Definition-Example Pairs
- Stage Variable
- Definition: A parameter in API Gateway that can be referenced in the API's configuration to avoid hard-coding values.
- Example: Creating a variable
${stageVariables.functionAlias}to dynamically point an API to either theDEVorPRODLambda alias depending on the stage URL.
- AppSpec File
- Definition: A configuration file used by CodeDeploy to define the deployment actions and lifecycle hooks.
- Example: Using the
BeforeAllowTraffichook in the AppSpec to run a validation Lambda function before shifting traffic to a new version.
- In-Place Deployment
- Definition: A deployment where the application on each instance in the deployment group is stopped, the latest application revision is installed, and the new version is started.
- Example: Updating a fleet of EC2 instances behind a Load Balancer where instances are taken out of service, updated, and put back.
Worked Examples
Scenario: Connecting API Gateway to Lambda Aliases
Goal: Set up an environment where the prod stage of an API calls the PROD alias of a Lambda function, and the dev stage calls the LATEST version.
- Lambda Configuration: Create a Lambda function and publish a version. Create an alias named
PRODpointing to that version. - API Gateway Stage Variables:
- In the
prodstage, add a variable:lambdaAlias = PROD. - In the
devstage, add a variable:lambdaAlias = LATEST.
- In the
- Integration Request: In the API Gateway Method Execution, set the Lambda Function name to:
MyFunctionName:${stageVariables.lambdaAlias}. - Permissions: Run the
aws lambda add-permissioncommand to allow API Gateway to invoke the function with the variable placeholder.
[!NOTE] When using variables in the Lambda function name, you must manually grant invocation permissions because the AWS Console cannot predict the value of the variable to add them automatically.
Checkpoint Questions
- What is the main advantage of using a Canary deployment over an All-at-once deployment?
- In an AWS SAM template, which resource type is used to define a serverless function?
- True or False: The CodeDeploy Agent must be installed on Lambda functions to perform Blue/Green deployments.
- How do Staging Variables in API Gateway assist in environment management?
▶Click to reveal answers
- Canary allows you to test the new version on a small subset of real traffic, reducing the blast radius of a failure. All-at-once has higher risk and causes downtime if the instances are replaced.
AWS::Serverless::Function.- False. The CodeDeploy Agent is only required for EC2 and On-premises deployments. Lambda deployments are handled natively by the service.
- They allow you to use the same API definition for multiple environments (Dev/Test/Prod) by dynamically changing backend endpoints or Lambda versions based on the stage.