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
preguntada hace 2 años641 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas