【问题标题】:cloudformation windows userdata cfn-init.exe end of line issuescloudformation windows userdata cfn-init.exe 行尾问题
【发布时间】:2018-05-21 16:35:25
【问题描述】:

通过添加一些 cfn-init 来从 S3 存储桶请求数据。 我相信我从 powershell 调用 cfn-init.exe 时遇到了语法问题,但似乎找不到在哪里。此结构取自Bootstrapping AWS CloudFormation Windows Stacks AWS Example。我还尝试从 AWS cfn-init documentation 的 bash 结构进行调整,但没有成功。

              "UserData": {"Fn::Base64": {"Fn::Join": ["\n", [
                "<powershell>",
                ...
                "cfn-init.exe -v -s", { "Ref" : "AWS::StackName" },
                " -r EC2Instance",
                "</powershell>"

        "Metadata" : {
            "AWS::CloudFormation::Init" : {
                "config": {
                    "files" : {
                        "C:\\chef\\validator.pem" : {
                            "source" : "https://s3.amazonaws.com/dtcfstorage/validator.pem",
                            "authentication" : "s3creds"
                        }
                    }
                },
                    "AWS::CloudFormation::Authentication" : {
                        "s3creds" : {
                            "type" : "S3",
                            "roleName" : "awss3chefkeyaccess"
                        }
                    }
                }
            }

cfn-init.exe 正在运行,但在参数传递到新行时出错:

2018/05/21 15:35:08Z:消息:来自用户脚本的错误:用法:cfn-init.exe [选项] 或:cfn-init.exe [选项] 或: 猫 | cfn-init.exe [选项] -

cfn-init.exe:错误:-s 选项需要一个参数 cloudinittest :术语“cloudinittest”未被识别为 cmdlet、函数、脚本文件或可操作的名称 程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 在 C:\Windows\TEMP\UserScript.ps1:30 char:1 + 云初始化测试 + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (cloudinittest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

-r :术语“-r”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查 名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 在 C:\Windows\TEMP\UserScript.ps1:31 char:2 + -r EC2Instance + ~~ + CategoryInfo : ObjectNotFound: (-r:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

【问题讨论】:

  • 还应该在来自 AWS 的 Windows Server 2016 基础 AMI 上添加它。我还在 AWS 的 2012 R2 AMI 上尝试了相同的代码,结果相似。

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

这是因为你在顶部使用 \n 加入了。如果您在同一行键入一些参数,则 join 函数的每个参数都将由换行事件分隔! 因此,您的命令 cfn-init 已被解释为:

cfn-init.exe -v -s
stack-name
 -r EC2Instance
...

由于线路中断,命令无法正常运行。 因此,您可以通过空格字符加入。您可以尝试将上述内容替换为:

{"Fn::Join": [" ", ["cfn-init.exe -v -s", {"Ref":"AWS::StackName"},
              "-r EC2Instance"]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    相关资源
    最近更新 更多