Amplify-cli: Using different parameters.json files in hosting backend

Created on 15 Apr 2019  路  5Comments  路  Source: aws-amplify/amplify-cli

* Which Category is your question related to? *
Hosting, CDN, backend Cloud Formation configuration files.

* What AWS Services are you utilizing? *
AWS CloudFront.

* Provide additional details e.g. code snippets *
Option to pass in custom CF template parameters.json file depending on environment.

feature-request hosting pending-response pending-review

Most helpful comment

Hi,

Thanks for the response.

I'm setting an alias for the CDN. Let's say my environments are example.com, develop-example.com, test-example.com. If we are allowed to use different parameter.json files, we would simple have a different value for each domain name.

Let's say by default parameters.json is used. But first check if an environment specific parameters.json file exists. If we are on develop environment, check for develop-parameters.json. Hope that makes sense? It is more a nice to have.

My current solution is the following:
Added the following to parameter.json:

{
  domainName: "example.com"
}

Then I updated template.json:

"Conditions": {
...
  "IsProduction": {
      "Fn::Equals" : [ { "Ref": "env" }, "master" ]
  }
}
...
    "Properties": {
        "DistributionConfig": {
            "Aliases": [ {
              "Fn::If" : [
                "IsProduction",
                { "Ref": "domainName" },
                {
                  "Fn::Join": [
                    "",
                    [
                      {
                        "Ref": "env"
                      },
                      "-",
                      { "Ref": "domainName" }
                    ]
                  ]
                }
              ]
            } ],
...

Which yields the desired result, but it is pretty involved. Compared to having the value in the parameter.json file. If you know what I mean. Thanks.

Regards.

All 5 comments

@jarrettj
Currently you can run 'amplify hosting configure' to configure different sections of the hosting service, including the CloudFront section, and those configuration changes are directly written into the template file.
And when you switch env, you are getting another set of resources.
Can you be more specific on what configuration settings are you want to keep in the parameters file, and how should they depend on the env?

Hi,

Thanks for the response.

I'm setting an alias for the CDN. Let's say my environments are example.com, develop-example.com, test-example.com. If we are allowed to use different parameter.json files, we would simple have a different value for each domain name.

Let's say by default parameters.json is used. But first check if an environment specific parameters.json file exists. If we are on develop environment, check for develop-parameters.json. Hope that makes sense? It is more a nice to have.

My current solution is the following:
Added the following to parameter.json:

{
  domainName: "example.com"
}

Then I updated template.json:

"Conditions": {
...
  "IsProduction": {
      "Fn::Equals" : [ { "Ref": "env" }, "master" ]
  }
}
...
    "Properties": {
        "DistributionConfig": {
            "Aliases": [ {
              "Fn::If" : [
                "IsProduction",
                { "Ref": "domainName" },
                {
                  "Fn::Join": [
                    "",
                    [
                      {
                        "Ref": "env"
                      },
                      "-",
                      { "Ref": "domainName" }
                    ]
                  ]
                }
              ]
            } ],
...

Which yields the desired result, but it is pretty involved. Compared to having the value in the parameter.json file. If you know what I mean. Thanks.

Regards.

Hey @jarrettj did you find any answer?

That's the solution above. Added a domainName and then used it in the single parameters.json as above.

So currently there is no valid solution for this?

Was this page helpful?
0 / 5 - 0 ratings