buildspec.yml, and the required IAM/KMS permissions. By the end you should be able to choose the right service for build and deployment secrets and avoid common pitfalls (rotation, cross-account access, and encryption).
Decision framework — Secrets Manager vs Parameter Store
-
Secrets Manager (purpose-built for secrets)
- Native rotation support (built-in for supported managed resources; custom rotation via Lambda for custom secrets)
- Always encrypted with AWS KMS
- Stores JSON key/value secrets and supports referencing a specific JSON key
- Per-secret monthly cost (suitable for high-value credentials that require rotation)
-
Systems Manager Parameter Store (general configuration storage)
- Types:
String,StringList,SecureString - Standard tier is free (4 KB per parameter, up to 10,000 parameters)
SecureStringuses KMS (AWS-managed or customer-managed CMKs)- Cost-effective at scale for many configuration values and non-rotating secrets
- Types:
- Use Secrets Manager for credentials that require frequent or automatic rotation (e.g., database credentials).
- Use Parameter Store (Standard or
SecureString) for configuration values or many non-rotating secrets where cost is a factor.

username: MyCompanypassword: SuperSecretPassword123!registry: docker.io
secret-id:jsonKey notation (see the buildspec.yml example below).




/devops-020-130/test-parameter) to organize parameters. Select a tier (Standard is free through reasonable limits) and choose a type (String, StringList, SecureString).
SecureStringuses KMS for encryption; for cross-account decryption you must use a customer-managed CMK (the default AWS-managed CMK cannot be used cross-account).- Use
StringListfor comma-separated lists such as feature flags.



buildspec.yml)
CodeBuild supports importing environment variables from both SSM Parameter Store and Secrets Manager in the env: section of buildspec.yml:
parameter-store— reference SSM parameters by name or ARN.secrets-manager— reference Secrets Manager secrets usingsecret-idorsecret-id:jsonKeyto map a specific JSON key to an environment variable.
buildspec.yml example (consolidated for this demo):
secretsmanager:GetSecretValue) and/or SSM parameters (ssm:GetParameter, ssm:GetParameters). If the secret/parameter is protected by a customer-managed CMK, the role also needs kms:Decrypt and kms:DescribeKey on that CMK. If KMS is not permitted, CodeBuild will fail with AccessDeniedException.
Example IAM policy fragments (trimmed for clarity):
If you use Secrets Manager or SSM
SecureString with a customer-managed CMK, ensure the CodeBuild role is allowed to call kms:Decrypt and kms:DescribeKey on that CMK. For cross-account access, the CMK’s key policy must explicitly allow the other account.- Rotation: Secrets Manager supports automatic rotation (1–365 day schedule). Custom secrets require a Lambda rotation handler; some AWS services (RDS) have built-in rotation without custom code.
- Cross-account access: For CodeBuild in Account A to read secrets or SecureString parameters in Account B, grant both the resource-level access (Secrets Manager/SSM) and the CMK key policy permissions for
kms:Decrypt. You may need to reference full ARNs inbuildspec.yml. - Buildspec syntax: Use
secret-id:jsonKeyinenv.secrets-managerto map a specific JSON key to an environment variable. SSM parameter names or ARNs go underenv.parameter-store. - Cost tradeoffs: Secrets Manager is priced per secret and is often the best choice for rotation-enabled credentials. Parameter Store Standard tier is free and more cost-effective for many configuration values.
- AWS Secrets Manager Developer Guide
- AWS Systems Manager Parameter Store
- AWS CodeBuild buildspec reference: environment variables