Course contentsShow
← Cloud and Infrastructure
Lesson 1827 of 2,98938. AWS Native CI/CDFree lesson

Environment Variables and Parameter Store

Use environment variables, AWS Systems Manager Parameter Store, and Secrets Manager in builds for secure configuration.

Environment Variables and Parameter Store

You'll learn how to securely manage configuration and secrets in AWS CodeBuild using environment variables, Parameter Store, and Secrets Manager.

When your build needs configuration values—API endpoints, database names, or sensitive credentials—hardcoding them into your buildspec is a security nightmare. AWS CodeBuild offers three ways to inject values safely.

Environment Variables in the Build

You can define plaintext environment variables directly in your CodeBuild project or buildspec file. These are fine for non-sensitive values like region names or feature flags:

env:
  variables:
    BUILD_ENV: "production"
    LOG_LEVEL: "info"

These get exposed to your build commands as standard shell variables.

AWS Systems Manager Parameter Store

Think of Parameter Store as a centralized key-value store for configuration. You store values there once, reference them in builds, and CodeBuild fetches them at runtime:

env:
  parameter-store:
    DB_HOST: /myapp/production/db-host
    API_KEY: /myapp/production/api-key

CodeBuild automatically retrieves these values using IAM permissions. Update the parameter in Parameter Store, and all future builds use the new value—no code changes needed.

Secrets Manager for Sensitive Data

For highly sensitive credentials (passwords, tokens), AWS Secrets Manager offers automatic rotation and enhanced security:

env:
  secrets-manager:
    DB_PASSWORD: prod-db-credentials:password

The syntax is secret-name:json-key. Secrets Manager handles encryption, auditing, and lifecycle management for you.

Why This Matters

This pattern separates code from configuration, prevents credential leaks in version control, and enables different values per environment—all while maintaining security through IAM policies.

Key Takeaway: Use plaintext environment variables for non-sensitive config, Parameter Store for shared configuration, and Secrets Manager for credentials—letting AWS CodeBuild securely inject them at build time without exposing secrets in your code.