Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package argument to deep-merge in a JSON file during packaging #1195

Closed
wants to merge 2 commits into from

Commits on Jul 30, 2019

  1. Add package argument to deep-merge in a JSON file during packaging

    Its a common use case to need to modify a Chalice generated template
    before deployment. Often to inject resources, values, or
    configurations that are not supported directly by Chalice. It will
    always be the case that something on AWS is not supported by Chalice
    directly that a consumer may want to interact with. This PR opens up
    an interface to address that gap more easily in Chalice itself.
    
    The package command can now be invoked with a new argument:
    
      $ chalice package --merge-template extras.json out
    
    This extras.json file should be a JSON formatted file which will be
    deep-merged on top of the sam.json that is generated by Chalice.
    
    For a simple example lets assume that we have the default new Chalice
    project and that extras.json has the following content:
    
    ```
    {
        "Resources": {
    	"APIHandler": {
    	    "Properties": {
    		"Environment": {
    		    "Variables": {
    			"foo": "bar"
    		    }
    		}
    	    }
    	}
        }
    }
    ```
    
    The generated template located at out/sam.json will have the this
    environment variable injected into it:
    
    ```
    ...
    ...
        "APIHandler": {
          "Type": "AWS::Serverless::Function",
          "Properties": {
            "Runtime": "python3.6",
            "Handler": "app.app",
            "CodeUri": "./deployment.zip",
            "Tags": {
              "aws-chalice": "version=1.9.1:stage=dev:app=test"
            },
            "Timeout": 60,
            "MemorySize": 128,
            "Role": {
              "Fn::GetAtt": [
                "DefaultRole",
                "Arn"
              ]
            },
            "Environment": {
              "Variables": {
                "foo": "bar"
              }
            }
          }
        },
    ...
    ...
    ```
    
    Obviously this simple example could have been achieved using the
    config file for the environment variables. But using the extras.json
    file we could have injected a DynamoDB table into the template, and
    injected the table name as a REF into the APIHandler's environment
    variables.
    
    For the time being the merge functionality is relatively simple. It can
    be extended over time as we discover what types of merge extensions
    are needed.
    stealthycoin committed Jul 30, 2019
    Configuration menu
    Copy the full SHA
    ddbf6fe View commit details
    Browse the repository at this point in the history

Commits on Aug 1, 2019

  1. Refactor

    * Simplify merger implementation
    * Pull multiple post processor handling out of the AppPackager and into
      a composite post processor
    * Make DeepMerger injectable into the TemplateMergePostProcessor to
      allow different mergers to be injected in the future
    * Remove config file option, instead you must specify the command line
      option
    * Add changelog entry
    * Add documentation section for merging under the cfn topic
    stealthycoin committed Aug 1, 2019
    Configuration menu
    Copy the full SHA
    d49d9c5 View commit details
    Browse the repository at this point in the history