AWS CloudFormation用户数据传递 [英] AWS CloudFormation userdata passing

查看:154
本文介绍了AWS CloudFormation用户数据传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在AWS cloudformation中将参数输入数据传递给用户数据. 示例:我有一个参数EnvType,在运行CFT时我将传递"qa"作为该参数的输入.我希望此参数值"qa"被读取并传递给用户数据,以便可以将其写入实例磁盘.

How do I pass parameters input data to userdata in AWS cloudformation. Example: I have a parameter EnvType where I will pass "qa" as input to this parameter while running CFT. I want this parameter value "qa" to be read and pass to userdata so that I can write it it to instance disk.

Parameters: {
    "EnvType": {
        "Description": "Environment type",
        "Type": "String",
        "AllowedValues": [
            "prod",
            "qa"
        ]
    }

我尝试在用户数据中使用它,

I tried using this in user data as:

export STACK_TYPE='",
{
"Ref": "EnvType"
},
"'\n",
"echo \"$STACK_TYPE\" > stacktypes\n

我想在其中将EnvType的此输入附加到实例中名为stacktypes的文件中.

Where I wanted to append this input of EnvType into a file named stacktypes in the instance.

推荐答案

您可以将堆栈参数传递/附加到实例中的文件中. 如果您有这样的参数,

You can pass/append the stack parameter into a file in your instance. If you have parameter like this,

Parameters: {
"EnvType": {
    ...
}

您可以尝试将下面的UserData添加到实例属性中.

You can try to add the UserData below into your instance properties.

   "Properties": {
      ...
      "UserData": {
        "Fn::Base64": {
          "Fn::Join": [
            "",
            [
              "#!/bin/bash -xe\",
              "echo ",
              {
                "Ref": "EnvType"
              },
              " >> /path/yourfile\n"
            ]
          ]
        }
      }
    }

这会将EnvType参数附加到您实例中的文件/path/yourfile中.

This will append the EnvType parameter into file /path/yourfile in your instance.

这篇关于AWS CloudFormation用户数据传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆