How can I add information from a config file when processing a yaml-file with CloudFormationCreateReplaceChangeSetAction?

1

I have a pipeline with a source stage, build stage, and self-mutate stage. I'm trying to take an existing yaml file and prepare the project it's associated with for deployment. The yaml file uses a config file for production and a different for testing, which is why the code below produces the following error: Parameters: [DatabaseNamespace, SecretsKmsKey] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError;

I've been looking at the documentation found here and I think I'm close to figuring this out if I can pass the parameters from the config file with one of the props available.

The fourth stage of the pipeline:

      stageName: 'Test_Deploy',
      actions: [
        new CloudFormationCreateReplaceChangeSetAction({
          actionName: 'PrepareChanges',
          stackName: 'my-stack',
          changeSetName: 'StagedChangeSet',
          adminPermissions: true,
          templatePath: sourceOutput.atPath('cloudformation/cf-test.yaml'),
          runOrder: 1
        })
      ]
    })

Config file:

AppStackName=my-stack
AppDeployBucket=deploy-bucket
DatabaseNamespace=cf-test-database
SecretsKmsKey=secrets-kms-key
1 Answer
1
Accepted Answer

You can directly provide the parameter values to the stack being deployed using the parameterOverrides attribute (see the API documentation for details).

new CloudFormationCreateReplaceChangeSetAction({
    actionName: 'PrepareChanges',
    stackName: 'my-stack',
    changeSetName: 'StagedChangeSet',
    adminPermissions: true,
    templatePath: sourceOutput.atPath('cloudformation/cf-test.yaml'),
    runOrder: 1,
    parameterOverrides: {
        'AppDeployBucket' : 'your-value',
        'DatabaseNamespace' : 'your-value'
    }
});

In the example above, the parameter names and values are hard-coded.

If you want to specify the parameters using an artifact file, use templateConfiguration instead (documentation link):

new CloudFormationCreateReplaceChangeSetAction({
    actionName: 'PrepareChanges',
    stackName: 'my-stack',
    changeSetName: 'StagedChangeSet',
    adminPermissions: true,
    templatePath: sourceOutput.atPath('cloudformation/cf-test.yaml'),
    runOrder: 1,
    templateConfiguration: sourceOutput.atPath('parameter-file.json'),
});

The template configuration file should contain a JSON object that should look like this:

{
    "Parameters": {...},
    "Tags": {...},
    "StackPolicy": {...}
}
profile pictureAWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions