<commit_before>---
title: AWS Continuous Infrastructure Delivery with CodePipeline and CloudFormation: How to pass Stack Parameters
date: 2017-04-10
---

When deploying CloudFormation stacks in a "Continuous Delivery" manner with CodePipeline, one might encounter the challenge to pass many parameters from the CloudFormation stack describing the pipeline to another stack describing the infrastructure to be deployed (in this example a stack named `application`).
 
Consider a CloudFormation snippet describing CodePipeline which deploys another CloudFormation stack:

```yaml
# pipeline.yaml
...
Resources:
  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      ...
      Stages:
      ...
      - Name: Application
        Actions:
        - Name: DeployApplication
          ActionTypeId:
            Category: Deploy
            Owner: AWS
            Provider: CloudFormation
            Version: 1
          Configuration:
            ActionMode: CREATE_UPDATE
            StackName: application
            TemplatePath: Source::application.yaml
```

Now when you want to pass parameters from the pipeline stack to the `application` stack, you could use the ParameterOverrides option offered by the [CodePipeline CloudFormation integration](https://aws.amazon.com/blogs/aws/codepipeline-update-build-continuous-delivery-workflows-for-cloudformation-stacks/), which might look like this:

```yaml
# pipeline.yaml
...
- Name: DeployApplication
  ...
  Configuration:
    StackName: application
    TemplatePath: Source::application.yaml
    ParameterOverrides: '{"ApplicationParameterA": "foo", "ApplicationParameterB": "bar"}'
```

This would pass the parameters `ApplicationParameterA` and `ApplicationParameterB` to the `application` CloudFormation stack. For reference this is how the `application` stack could look like:

```yaml
# application.yaml
---
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  ApplicationParameterA:
    Type: String
  ApplicationParameterB:
    Type: String

Resources:
...
```
## Alternative way of parameter passing with Template Configurations

Injecting parameters from the pipeline stack to the application stack can become awkward with the `ParametersOverrides` method. Especially when there are many parameters and they are passed into the pipeline stack as parameters as well, the pipeline template could look like this:
```yaml
# pipeline.yaml
---
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  ApplicationParameterA:
    Type: String
  ApplicationParameterB:
    Type: String

Resources:
  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Stages:
        ...
        - Name: DeployApplication
          ...
          Configuration:
            ...
            TemplatePath: Source::application.yaml
              ParameterOverrides: !Sub '{"ApplicationParameterA": "${ApplicationParameterA}", "ApplicationParameterB": "${ApplicationParameterB}"}'
```

An alternative way is to place a so called [template configuration](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w1ab2c13c19c17) into the same artifact which contains the `application.yaml` template, and reference it via the `TemplateConfiguration`:
```yaml
# pipeline.yaml
...
- Name: DeployApplication
  ...
  Configuration:
    ...
    TemplatePath: Source::application.yaml
    ParameterOverrides: '{"ApplicationParameterA": "foo", "ApplicationParameterB": "bar"}'
    TemplateConfiguration: Source::template_configuration.json
```

In our case, the `template_configuration.json` file would look like this:

```json
{
  "Parameters" : {
    "ApplicationParameterA" : "foo",
    "ApplicationParameterB" : "bar"<commit_msg>add another missing yaml node<commit_after>---
title: AWS Continuous Infrastructure Delivery with CodePipeline and CloudFormation: How to pass Stack Parameters
date: 2017-04-10
---

When deploying CloudFormation stacks in a "Continuous Delivery" manner with CodePipeline, one might encounter the challenge to pass many parameters from the CloudFormation stack describing the pipeline to another stack describing the infrastructure to be deployed (in this example a stack named `application`).
 
Consider a CloudFormation snippet describing CodePipeline which deploys another CloudFormation stack:

```yaml
# pipeline.yaml
...
Resources:
  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      ...
      Stages:
      ...
      - Name: Application
        Actions:
        - Name: DeployApplication
          ActionTypeId:
            Category: Deploy
            Owner: AWS
            Provider: CloudFormation
            Version: 1
          Configuration:
            ActionMode: CREATE_UPDATE
            StackName: application
            TemplatePath: Source::application.yaml
```

Now when you want to pass parameters from the pipeline stack to the `application` stack, you could use the ParameterOverrides option offered by the [CodePipeline CloudFormation integration](https://aws.amazon.com/blogs/aws/codepipeline-update-build-continuous-delivery-workflows-for-cloudformation-stacks/), which might look like this:

```yaml
# pipeline.yaml
...
- Name: DeployApplication
  ...
  Configuration:
    StackName: application
    TemplatePath: Source::application.yaml
    ParameterOverrides: '{"ApplicationParameterA": "foo", "ApplicationParameterB": "bar"}'
```

This would pass the parameters `ApplicationParameterA` and `ApplicationParameterB` to the `application` CloudFormation stack. For reference this is how the `application` stack could look like:

```yaml
# application.yaml
---
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  ApplicationParameterA:
    Type: String
  ApplicationParameterB:
    Type: String

Resources:
...
```
## Alternative way of parameter passing with Template Configurations

Injecting parameters from the pipeline stack to the application stack can become awkward with the `ParametersOverrides` method. Especially when there are many parameters and they are passed into the pipeline stack as parameters as well, the pipeline template could look like this:
```yaml
# pipeline.yaml
---
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  ApplicationParameterA:
    Type: String
  ApplicationParameterB:
    Type: String

Resources:
  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Stages:
        ...
        Actions:
        - Name: DeployApplication
          ...
          Configuration:
            ...
            TemplatePath: Source::application.yaml
              ParameterOverrides: !Sub '{"ApplicationParameterA": "${ApplicationParameterA}", "ApplicationParameterB": "${ApplicationParameterB}"}'
```

An alternative way is to place a so called [template configuration](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-cfn-artifacts.html#w1ab2c13c19c17) into the same artifact which contains the `application.yaml` template, and reference it via the `TemplateConfiguration`:
```yaml
# pipeline.yaml
...
- Name: DeployApplication
  ...
  Configuration:
    ...
    TemplatePath: Source::application.yaml
    ParameterOverrides: '{"ApplicationParameterA": "foo", "ApplicationParameterB": "bar"}'
    TemplateConfiguration: Source::template_configuration.json
```

In our case, the `template_configuration.json` file would look like this:

```json
{
  "Parameters" : {
    "ApplicationParameterA" : "foo",
    "ApplicationParameterB" : "bar"
{'fraction_non_alphanumeric': 0.0895065833222503, 'fraction_numerical': 0.008777763000398989, 'mean_word_length': 3.7474747474747474, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4670114', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1844, 'n_words': 636}