gpt4 book ai didi

amazon-web-services - cloudformation windows userdata cfn-init.exe 行尾问题

转载 作者:行者123 更新时间:2023-12-03 07:45:05 25 4
gpt4 key购买 nike

通过添加一些 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: Message: The errors from user scripts: Usage: cfn-init.exe [options] or: cfn-init.exe [options] or: cat | cfn-init.exe [options] -

cfn-init.exe: error: -s option requires an argument cloudinittest : The term 'cloudinittest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Windows\TEMP\UserScript.ps1:30 char:1 + cloudinittest + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (cloudinittest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

-r : The term '-r' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Windows\TEMP\UserScript.ps1:31 char:2 + -r EC2Instance + ~~ + CategoryInfo : ObjectNotFound: (-r:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

最佳答案

这是因为您是在顶部使用\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"]}

关于amazon-web-services - cloudformation windows userdata cfn-init.exe 行尾问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50453113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com