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
질문됨 2년 전641회 조회
1개 답변
1
수락된 답변

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
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠