Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set the parameters in an AWS CloudFormation launch URL?

I need to point my users to a cloudformation stack that they will need to run, but I'd like to be able to personalize it based on the user. I've read this and I would like to create a URL like:

https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=SomeName&MyParam=blah&templateURL=https://s3.amazonaws.com/mytemplate.json

Notice the "MyParam=blah" in the middle. The user can still change the parameter to whatever they want, but I'd like to be able to set a default. Any ideas, other than writing a custom Cloudformation template per user?

like image 595
Ryan Shillington Avatar asked Feb 10 '17 04:02

Ryan Shillington


People also ask

How do you reference parameters in CloudFormation?

Referencing a parameter within a template You use the Ref intrinsic function to reference a parameter, and AWS CloudFormation uses the parameter's value to provision the stack. You can reference parameters from the Resources and Outputs sections of the same template.

How do I change parameters in CloudFormation stack?

In the AWS CloudFormation console , from the list of stacks, select the running stack that you want to update. In the stack details pane, choose Update. If you haven't modified the stack template, select Use current template, and then choose Next.

What is pseudo parameters in CloudFormation?

Pseudo parameters are parameters that are predefined by AWS CloudFormation. You don't declare them in your template. Use them the same way as you would a parameter, as the argument for the Ref function.

What is the maximum number of parameters that you can use in an AWS CloudFormation template?

The new per template limits for the maximum number of resources is 500 (previously 200), parameters is 200 (previously 60), mappings is 200 (previously 100), and outputs is 200 (previously 60). CloudFormation allows you to model and provision cloud resources as code in a safe, predictable, and scalable manner.


Video Answer


2 Answers

[Update]: As of Jul 14 2017, it is now possible to specify template parameters in URL query parameters provided to the launch stack URL. Use the param_parameterName format to specify template parameters, e.g.:

https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?stackName=SomeName&param_MyParam=blah&templateURL=https://s3.amazonaws.com/mytemplate.json

See Creating Quick-Create Links for Stacks for full details.


[Original answer, Feb 10 2017]:

It is not possible to preset default parameters directly via an AWS CloudFormation launch URL. stackName and templateURL are the only two URI fragment components that are parsed by the JavaScript code executed on this page.

Refer to the current CloudFormation Console JavaScript source to confirm this, specifically the parseRouteParams function in the StackInfo object used by the CreateStackController:

this.parseRouteParams = function(a) {
    a = _.reduce(a, function(a, b, d) {
        a[d] = decodeURIComponent(b);
        return a
    }, a);
    _.extend(this, _.pick(a, "stackName", "templateURL"))
}

Here are some other ideas:

  • Write some server-side code that dynamically renders the Default value of a Property in your CloudFormation template based on a provided query parameter, uploads the rendered template to an S3 bucket, then redirects to the create-stack page providing the URL to the newly-rendered template.
  • Use another interface to the CreateStack API such as the AWS CLI create-stack, or build your own web interface to dynamically provide default parameters.
  • Write a custom User Script / browser extension that extends the Console page to parse the additional URI fragment parameter and inject the correct value into the Console input field directly.
  • Ask AWS to add support for this feature directly into their URL parsing code.
like image 186
wjordan Avatar answered Oct 03 '22 01:10

wjordan


You can use our new quick launch URL to supply parameters to the Cloudformation Console. It supports Parameters using param_Foo syntax.

Here is an example for a sample APP

https://eu-central-1.console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/create/review?templateURL=https://s3-eu-central-1.amazonaws.com/cloudformation-templates-eu-central-1/WordPress_Single_Instance.template&stackName=MyWPBlog&param_DBName=mywpblog&param_InstanceType=t2.medium&param_KeyName=MyKeyPairUSEast1

Please note that this does not support deep linking for No Echo parameters, by design.

More info: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stacks-quick-create-links.html

like image 31
user1637473 Avatar answered Oct 02 '22 23:10

user1637473