问题
We are looking into using aws-cdk in our CI/CD pipeline. We need to be able to pass parameters into the the template during the build so it can generate an artifact to use during deploy. I see we can use the cdk.json file to specify context properties, but this doesn't actually put the values into the CloudFormation template itself. Just gives you access to them in the code.
I have tried something like this:
const servicenameprop = new PipelinePrerequisitesProps();
servicenameprop.default = 'hello';
servicenameprop.type = 'String';
const serviceNameParameter = new Parameter(this, 'servicename', servicenameprop);
serviceNameParameter.value = new Token(servicename, 'servicename');
This results in parameters appearing in the CloudFormation dashboard tab, but there are no values set, just the defaults. Is this supported currently? If not, is it planned for the future?
回答1:
The CDK does not currently support passing parameters in as part of cdk deploy
. If you're leveraging parameters in your stacks, you'll have to manage the CloudFormation submission yourself, at least now. You could for example use the AWS CLI together with the result of running cdk synth
(you can use cdk synth -o <directory>
).
Generally speaking, we encourage the creation of CDK Stacks that are as concrete as possible. Passing context to your App directly at "synth" time will allow you code to reason over them and produce simpler, more predictable templates (for example, you can not put a resource in a template instead of adding a condition and a resource with a condition).
来源:https://stackoverflow.com/questions/53660503/passing-in-template-parameters