- Newest
- Most votes
- Most comments
Hello.
I tested it in my environment with the following buildspec.yml:
version: 0.2
env:
secrets-manager:
DB_PASSWORD: arn:aws:secretsmanager:ap-northeast-1:123456789012:secret:test:name
DB_USERNAME: arn:aws:secretsmanager:ap-northeast-1:123456789012:secret:test:test
phases:
install:
on-failure: ABORT
commands:
- echo $DB_PASSWORD
- echo $DB_USERNAME
pre_build:
on-failure: ABORT
commands:
- echo "pre_build phases"
build:
on-failure: ABORT
commands:
- echo "build phases"
post_build:
on-failure: ABORT
commands:
- echo "post_build phases"
artifacts:
files:
- "**/*"
Since CloudTrail has recorded two action of "GetSecretValue" executed by CodeBuild against the same SecretsManager, it can be inferred that access occurs as many times as specified in the buildspec.yml file.
Based on the available information, there's no explicit documentation that states whether AWS CodeBuild makes a single call or multiple calls to AWS Secrets Manager when retrieving different values from the same secret in a buildspec file.
In your example, you're trying to extract two different fields (password and username) from the same JSON secret (mydbsecret). The buildspec format you've shown is the correct way to reference specific JSON fields within a secret.
When using AWS Secrets Manager with CodeBuild, the service role for your build project must have the secretsmanager:GetSecretValue permission. AWS recommends storing secrets with names that start with /CodeBuild/ (for example, /CodeBuild/dockerLoginPassword). If you use the "New service role" option when creating your build project, CodeBuild includes the necessary permissions to access secrets with names that start with /CodeBuild/. If your secret names don't follow this pattern, you'll need to update the service role to allow access to those specific secret names.
While the documentation doesn't specifically address whether multiple references to the same secret result in multiple API calls, the implementation details of how CodeBuild retrieves secrets from Secrets Manager are not explicitly documented in the provided sources.
Sources
Change build project settings in AWS CodeBuild - AWS CodeBuild
Create a build project in AWS CodeBuild - AWS CodeBuild
AWS CodeBuild build and test action reference - AWS CodePipeline
answered a year ago
