从CloudFormation参数获取输入并将其传递给从S3下载的脚本

时间:2015-09-10 20:49:04

标签: amazon-web-services amazon-s3 amazon-cloudformation

在我的AWS CloudFormation模板中创建时,我达到了16KB的用户数据限制....然后我发现我可以将脚本放入S3(包含我的所有用户数据)并将该文件作为用户的一部分复制数据并运行该脚本...但我的问题是如何将我传递给CloudFormation的参数如下所示并将其传递到我将从S3运行的文件/脚本/用户数据中?那么如何将参数从CloudFormation传递到/root/usr.sh脚本?

这是我的用户数据:

"UserData": {
          "Fn::Base64": {
            "Fn::Join": [
              "",
              [
                "#!/bin/bash -x\n\n",
                "yum -y install tcsh lvm2 sysstat\n\n\n",
                "# AWS CLI download and Installation\n",
                "curl \"https://s3.amazonaws.com/aws-cli/awscli-bundle.zip\" -o \"/usr/awscli-bundle.zip\"\n",
                "unzip /usr/awscli-bundle.zip -d /usr/awscmdline/\n",
                "/usr/awscmdline/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws\n",
                "/usr/local/aws/bin/aws configure set region ",
                {
                  "Ref": "AWS::Region"
                },
                "\n",
                "/usr/local/bin/aws s3 cp s3://test123/usr.sh /root/usr.sh \n",
                "chmod 744 /root/usr.sh \n",
                "/root/usr.sh"
              ]
            ]
          }
        }

以下是示例参数:

"Parameters": {
    "SelectInstanceType": {
      "Description": "EC2 instance type",
      "Type": "String",
      "Default": "r3.8xlarge",
      "AllowedValues": [
        "r3.large",
        "r3.xlarge",
        "r3.2xlarge",
        "r3.4xlarge",
        "r3.8xlarge",
        "c4.large",
        "c4.xlarge",
        "c4.2xlarge",
        "c4.4xlarge",
        "c4.8xlarge"
      ],
      "ConstraintDescription": "Must be a valid EC2 instance type."
    },
    "Keyname": {
      "Description": "Keypair to use to launch the instance",
      "Type": "AWS::EC2::KeyPair::KeyName"
    },
    "IPAddress": {
      "Description": "Private IP",
      "Type": "String",
      "Default": "10.10.10.X"
    },

0 个答案:

没有答案