简体   繁体   English

我可以在AWS CloudFormation启动URL中设置参数吗?

[英]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. 我需要将用户指向他们需要运行的cloudformation堆栈,但我希望能够根据用户对其进行个性化设置。 I've read this and I would like to create a URL like: 我已经读过这篇文章了 ,我想创建一个像这样的URL:

https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=SomeName&MyParam=blah&templateURL=https://s3.amazonaws.com/mytemplate.json 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. 请注意中间的“MyParam = blah”。 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? 除了为每个用户编写自定义Cloudformation模板之外的任何想法?

[ Update ]: As of Jul 14 2017 , it is now possible to specify template parameters in URL query parameters provided to the launch stack URL. [ 更新 ]:自2017年7月14日起 ,现在可以在提供给启动堆栈URL的URL查询参数中指定模板参数。 Use the param_parameterName format to specify template parameters, eg: 使用param_parameterName格式指定模板参数,例如:

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 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] : [原始答案,2017年2月10日]

It is not possible to preset default parameters directly via an AWS CloudFormation launch URL. 无法通过AWS CloudFormation启动URL直接预设默认参数。 stackName and templateURL are the only two URI fragment components that are parsed by the JavaScript code executed on this page. stackNametemplateURL是由此页面上执行的JavaScript代码解析的唯一两个URI片段组件。

Refer to the current CloudFormation Console JavaScript source to confirm this, specifically the parseRouteParams function in the StackInfo object used by the CreateStackController : 请参阅当前的CloudFormation控制台JavaScript源以确认这一点,特别是CreateStackController使用的StackInfo对象中的parseRouteParams函数:

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. 编写一些服务器端代码,根据提供的查询参数在CloudFormation模板中动态呈现Property的Default值,将呈现的模板上传到S3存储桶,然后重定向到create-stack页面,提供新的URL呈现的模板。
  • 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. 使用CreateStack API的另一个接口,例如AWS CLI create-stack ,或构建您自己的Web界面以动态提供默认参数。
  • 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. 编写一个自定义用户脚本/浏览器扩展,扩展Console页面以解析附加的URI片段参数,并将正确的值直接注入Console输入字段。
  • Ask AWS to add support for this feature directly into their URL parsing code. 请求AWS将此功能的支持直接添加到其URL解析代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM