Hands-On Lab845 words

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.txt and vendor folders).
  • Externalize application configuration using AWS Systems Manager Parameter Store.
  • Create a valid buildspec.yml file 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.

Loading Diagram...

Step-by-Step Instructions

Step 1: Initialize the Project Structure

AWS recommends a clean separation between source code, tests, and configuration files.

bash
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.

  1. Open requirements.txt and add:
text
requests==2.31.0
  1. Install dependencies locally into a temporary directory to simulate a deployment package:
bash
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.

bash
aws ssm put-parameter \ --name "/todo-app/dev/api-url" \ --value "https://dev.api.brainybee.com" \ --type "String" \ --overwrite
Console alternative
  1. Open the AWS Systems Manager console.
  2. In the left navigation, choose Parameter Store.
  3. Click Create parameter.
  4. Name: /todo-app/dev/api-url | Type: String | Value: https://dev.api.brainybee.com.
  5. 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:

yaml
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.zip

Checkpoints

  1. Directory Check: Run ls -R. You should see src/ containing app.py and several library folders (like requests).
  2. Parameter Store Check: Verify your parameter exists in AWS.
    bash
    aws ssm get-parameter --name "/todo-app/dev/api-url" --query "Parameter.Value"
  3. Artifact Readiness: Run zip -v. If you can generate a .zip file from the src folder, your artifact is ready for deployment to S3 or Lambda.

Troubleshooting

ProblemPossible CauseFix
pip install failsPython/Pip not in PATHEnsure Python is installed and run python -m pip install
Access Denied on SSMMissing IAM PermissionsEnsure your CLI user has ssm:PutParameter permissions
Zip command not foundWindows environmentUse PowerShell Compress-Archive or install a CLI zip tool

Clean-Up / Teardown

[!IMPORTANT] Always delete cloud resources to prevent unexpected bills.

  1. Delete the SSM Parameter:
bash
aws ssm delete-parameter --name "/todo-app/dev/api-url"
  1. Remove local files:
bash
cd .. && rm -rf brainybee-todo-app

Challenge

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

ServiceUsageEstimated Cost
AWS SSM Parameter StoreStandard Parameters (up to 10,000)$0.00 (Free Tier)
AWS CodeBuildFirst 100 mins/month$0.00 (Free Tier)
Total$0.00

Concept Review

Artifact ComponentDescriptionDVA-C02 Context
DependenciesLibraries required for code to run (e.g., node_modules, site-packages).Must be included in the .zip or container image.
buildspec.ymlYAML file defining build phases (Install, Pre_build, Build, Post_build).Essential for AWS CodeBuild and CodePipeline.
Parameter StoreHierarchical storage for configuration data and secrets.Used for environment-specific configs (Dev vs Prod).
Resource RequirementsSpecifying Memory/CPU in templates.Skill 3.1.4: Define memory/concurrency for Lambda.

Ready to study AWS Certified Developer - Associate (DVA-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free