Description
Describe the bug
Using the apprunner-alpha module, methods .addEnvironmentVariable()
and .addSecret()
only work if there are existing entries that have been created in the initial imageConfiguration
props. This is because in the private renderEnvironmentVariables()
and renderEnvironmentSecrets()
methods, there is an if condition which returns undefined if there are no entries in the initial imageConfiguration
prop. See code here
aws-cdk/packages/@aws-cdk/aws-apprunner/lib/service.ts
Lines 1139 to 1167 in d986e14
Expected Behavior
Ability to use the methods without having defined initial env variables in the props.
Current Behavior
No environment or secret variables are rendered if only using the .addEnvironmentVariable()
and .addSecret()
methods.
Reproduction Steps
const service = new Service(this, 'service', {
source: Source.fromAsset({
imageConfiguration: {
port: 3000,
},
asset: imageAsset,
}),
instanceRole,
})
service.addEnvironmentVariable('TEST', 'test')
service.addSecret('SECRET', Secret.fromSecretsManager(secret)
This will not render any secrets or environment variables in the resulting template, but adding some initial values will cause add environment variables to be correctly rendered, e.g.
const service = new Service(this, 'service', {
source: Source.fromAsset({
imageConfiguration: {
port: 3000,
environmentSecrets: { SEED1: Secret.fromSecretsManager(seedSecret) },
environmentVariables: { SEED2: 'seed' },
},
asset: imageAsset,
}),
instanceRole,
})
service.addEnvironmentVariable('TEST', 'test')
service.addSecret('SECRET', Secret.fromSecretsManager(secret)
Possible Solution
Correct the faulty if logic in renderEnvironmentVariables()
and renderEnvironmentSecrets()
Additional Information/Context
No response
CDK CLI Version
2.66.0
Framework Version
No response
Node.js Version
16.17.0
OS
M1 MacOS
Language
Typescript
Language Version
No response
Other information
No response
Activity
pahud commentedon Feb 28, 2023
Thanks for addressing this issue and the PR contribution.
fix(apprunner-alpha): env vars and secrets can't solely be added via …
github-actions commentedon Mar 3, 2023
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
fix(apprunner-alpha): env vars and secrets can't solely be added via …