Lab: Preparing Application Artifacts for AWS Deployment
Prepare application artifacts to be deployed to AWS
Lab: Preparing Application Artifacts for AWS Deployment
In this lab, you will learn how to organize application code, manage dependencies, and prepare environment-specific configurations as required for the AWS Certified Developer - Associate (DVA-C02) exam. We will focus on creating a deployment-ready package for an AWS Lambda function, utilizing a standard directory structure and AWS Systems Manager Parameter Store for externalized configuration.
[!WARNING] This lab involves creating resources in your AWS account. Ensure you follow the Clean-Up / Teardown section at the end to avoid unnecessary charges.
Prerequisites
- AWS Account: An active AWS account with Administrator access or equivalent permissions for IAM, SSM, and S3.
- AWS CLI: Installed and configured with your credentials (
aws configure). - Python 3.9+: Installed on your local machine to manage dependencies.
- Text Editor: VS Code, Sublime, or similar.
Learning Objectives
- Organize a project directory structure compliant with AWS deployment best practices.
- Manage code dependencies within a package (e.g.,
requirements.txtand vendor folders). - Externalize application configuration using AWS Systems Manager Parameter Store.
- Create a valid
buildspec.ymlfile for AWS CodeBuild to automate artifact creation.
Architecture Overview
This lab simulates the "Preparation" phase of a CI/CD pipeline. We focus on the local environment and the cloud configuration store.
Step-by-Step Instructions
Step 1: Initialize the Project Structure
AWS recommends a clean separation between source code, tests, and configuration files.
mkdir brainybee-todo-app && cd brainybee-todo-app
mkdir src
touch src/app.py requirements.txt buildspec.yml▶Console alternative
Navigate to your local file explorer and create the folder brainybee-todo-app. Inside, create a folder named src and three empty files named app.py, requirements.txt, and buildspec.yml.
Step 2: Define Dependencies
For AWS Lambda, dependencies must be packaged along with the function code. We will use the requests library as an example.
- Open
requirements.txtand add:
requests==2.31.0- Install dependencies locally into a temporary directory to simulate a deployment package:
pip install -r requirements.txt -t src/[!TIP] Installing with
-t src/(target) places the libraries directly in your source folder so they are included when the folder is zipped for Lambda.
Step 3: Configure Environment-Specific Settings
Instead of hardcoding the "Database Table Name" or "API Endpoint," we use AWS Systems Manager Parameter Store.
aws ssm put-parameter \
--name "/todo-app/dev/api-url" \
--value "https://dev.api.brainybee.com" \
--type "String" \
--overwrite▶Console alternative
- Open the AWS Systems Manager console.
- In the left navigation, choose Parameter Store.
- Click Create parameter.
- Name:
/todo-app/dev/api-url| Type:String| Value:https://dev.api.brainybee.com. - Click Create parameter.
Step 4: Create the Build Specification
AWS CodeBuild requires a buildspec.yml file in the root directory to know how to handle your artifacts.
Paste the following into your buildspec.yml file:
version: 0.2
phases:
install:
runtime-versions:
python: 3.9
commands:
- echo "Installing dependencies..."
- pip install -r requirements.txt -t src/
build:
commands:
- echo "Building deployment package..."
- cd src && zip -r ../deployment_package.zip .
artifacts:
files:
- deployment_package.zipCheckpoints
- Directory Check: Run
ls -R. You should seesrc/containingapp.pyand several library folders (likerequests). - Parameter Store Check: Verify your parameter exists in AWS.
bash
aws ssm get-parameter --name "/todo-app/dev/api-url" --query "Parameter.Value" - Artifact Readiness: Run
zip -v. If you can generate a.zipfile from thesrcfolder, your artifact is ready for deployment to S3 or Lambda.
Troubleshooting
| Problem | Possible Cause | Fix |
|---|---|---|
pip install fails | Python/Pip not in PATH | Ensure Python is installed and run python -m pip install |
| Access Denied on SSM | Missing IAM Permissions | Ensure your CLI user has ssm:PutParameter permissions |
| Zip command not found | Windows environment | Use PowerShell Compress-Archive or install a CLI zip tool |
Clean-Up / Teardown
[!IMPORTANT] Always delete cloud resources to prevent unexpected bills.
- Delete the SSM Parameter:
aws ssm delete-parameter --name "/todo-app/dev/api-url"- Remove local files:
cd .. && rm -rf brainybee-todo-appChallenge
Scenario: Your security team requires that the API URL for production be encrypted.
Task: Create a new parameter named /todo-app/prod/api-url using the --type "SecureString" flag in the CLI. Then, attempt to retrieve its value using aws ssm get-parameter --name ... --with-decryption.
Cost Estimate
| Service | Usage | Estimated Cost |
|---|---|---|
| AWS SSM Parameter Store | Standard Parameters (up to 10,000) | $0.00 (Free Tier) |
| AWS CodeBuild | First 100 mins/month | $0.00 (Free Tier) |
| Total | $0.00 |
Concept Review
| Artifact Component | Description | DVA-C02 Context |
|---|---|---|
| Dependencies | Libraries required for code to run (e.g., node_modules, site-packages). | Must be included in the .zip or container image. |
| buildspec.yml | YAML file defining build phases (Install, Pre_build, Build, Post_build). | Essential for AWS CodeBuild and CodePipeline. |
| Parameter Store | Hierarchical storage for configuration data and secrets. | Used for environment-specific configs (Dev vs Prod). |
| Resource Requirements | Specifying Memory/CPU in templates. | Skill 3.1.4: Define memory/concurrency for Lambda. |