Working through adding some cfn-init to request data from an S3 bucket.
I believe I've got a syntax problem with the cfn-init.exe call from powershell but cannot seem to find where. This structure was taken from the Bootstrapping AWS CloudFormation Windows Stacks AWS Example. I've also tried adapting from the bash structure from AWS cfn-init documentation with no success.
"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"
}
}
}
}
The cfn-init.exe is being run but errors out as the arguments are passing to new lines:
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
It's because you have joined using \n at the top. Every arg to the join function will separate by a newline event if you type some on the same line!
Therefore, your command cfn-init has been interpreted as:
cfn-init.exe -v -s
stack-name
-r EC2Instance
...
Since the line is broken, the command doesn't get run properly.
As such, you can join by a space character. You can try replacing the above by this:
{"Fn::Join": [" ", ["cfn-init.exe -v -s", {"Ref":"AWS::StackName"},
"-r EC2Instance"]}
Related
I am following the instructions in here to install the Ops agent on my local Windows machine.
These are the steps that I follow in PowerShell (as admin):
(New-Object Net.WebClient).DownloadFile("https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.ps1", "${env:UserProfile}\add-google-cloud-ops-agent-repo.ps1") Invoke-Expression "${env:UserProfile}\add-google-cloud-ops-agent-repo.ps1 -AlsoInstall"
As soon as I execute this, the output is:
googet : The term 'googet' 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:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:171 char:10
+ if (! (googet listrepos | Select-String -quiet "https://packages.cl ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
googet : The term 'googet' 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:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:198 char:24
+ if (! $Version -and (googet listrepos | Select-String -quiet "https ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
googet : The term 'googet' 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:\Users\bot_runner_01\add-google-cloud-ops-agent-repo.ps1:205 char:10
+ if (! (googet installed google-cloud-ops-agent 2>&1 | Select-String ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (googet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
No changes made.
How can I fix this? thank you
I had the same issue, found that running the 'Installing the guest environment' scripts in the page below worked for me:
https://cloud.google.com/compute/docs/images/install-guest-environment?authuser=0#installing_guest_environment
I want to build this open source project from source for contributing. I am following this docs for windows. I cloned the repo and install chocolatey as mention. Then I am executing the commands in "prepare the enviorment section" . I was able to run 1st command correctly
PS A:\wasmedgebuild\WasmEdge> choco install cmake ninja vswhere
But when I run second one .
PS A:\wasmedgebuild\WasmEdge> $vsPath = (vswhere -latest -property
installationPath) Import-Module (Join-Path $vsPath
"Common7\Tools\Microsoft.VisualStudio.DevShell.dll") Enter-VsDevShell
-VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64 -winsdk=10.0.19041.0"
I am getting this error:
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:2 char:26
+ Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudi ...
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
Enter-VsDevShell : The term 'Enter-VsDevShell' 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 line:3 char:1
+ Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCm ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Enter-VsDevShell:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Screenshot
I don't know what is the problem. Am I doing it in wrong way?
I was following the AWS documentation example for envelope encryption in which there is a command for PowerShell. The command doesn't work on my PC so I need someone to help me figure out why. Below is the link to the documentation;
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/crypto-cli-examples.html
Below is the error I get when I follow the instructions in the documentations;
PS C:> $CmkArn = arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89
arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89 : The term
'arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a417-f5bba5e6af89' 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 line:1 char:11
$CmkArn = arn:aws:kms:us-west-1:404148889442:key/c6b58e8e-f890-4d97-a ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (arn:aws:kms:us-...17-f5bba5e6af89:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
The syntax in their example is wrong, this is how it should be written:
# To run this example, replace the fictitious key ARN with a valid value.
PS C:\> $CmkArn = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
PS C:\> aws-encryption-cli --encrypt `
--input Hello.txt `
--master-keys key=$CmkArn `
--metadata-output $home\Metadata.txt `
--encryption-context purpose=test `
--output .
The fictitious ARN needs quotes around it.
I am trying to create a windows VM with chef client by ARM (Azure resource manager) template. I find an example template in github:
https://github.com/Azure/azure-quickstart-templates/tree/master/chef-extension-windows-vm
{
"name": "[concat(variables('vmName'),'/',variables('chefClientName'))]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2015-05-01-preview",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
],
"properties": {
"publisher": "Chef.Bootstrap.WindowsAzure",
"type": "ChefClient",
"typeHandlerVersion": "1201.12",
"settings": {
"client_rb": "[parameters('client_rb')]",
"runlist": "[parameters('runlist')]"
},
"protectedSettings": {
"validation_key": "[parameters('validation_key')]"
}
}
}
I deploy this template in powershell, storageAcount/vNet/IP/NIC/VM are created successfully. But the chef extension create fail with the following error:
New-AzureResourceGroupDeployment : 3:44:51 PM - Resource Microsoft.Compute/virtualMachines/extensions
'myVM/chefExtension' failed with message 'Extension with publisher 'Chef.Bootstrap.WindowsAzure', type 'ChefClient',
and type handler version '1201.12' could not be found in the extension repository.'
At line:1 char:1
+ New-AzureResourceGroupDeployment -Name $deployName -ResourceGroupName $RGName -T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
How can I create a VM with chef by ARM template ?
Thanks.
The failure is cause by wrong "typeHandlerVersion", "1201.12" is no longer available. "1207.12" works fine. To get the available extension information, use the following powershell command:
Get-AzureVMAvailableExtension | select ExtensionName,Publisher,Version,PublishedDate
I'm trying to install a custom compiled package that I have in S3 as a zip file. I added this on my Cloudformation template:
"sources" : {
"/opt" : "https://s3.amazonaws.com/mybucket/installers/myapp-3.2.1.zip"
},
It downloads and unzip it on /opt without issues, but all the "executables" files don't have the "x" permission. I mean "-rw-r--r-- 1 root root 220378 Dec 4 18:23 myapp".
If I download the zip and unzip it in any directory, the permissions are Ok.
I already read the Cloudformation documentation and there is no clue there.
Someone can help me figuring this out? Thanks in advance.
Maybe you can combine a "configSets" (to guarantee the execution order) and a "command" element to write something like :
"AWS::CloudFormation::Init" : {
"configSets" : {
"default" : [ "download", "fixPermissions" ]
},
"download" : {
"sources" : {
"/opt" : "https://s3.amazonaws.com/mybucket/installers/myapp-3.2.1.zip"
},
},
"fixPermissions" : {
"commands" : {
"fixMyAppPermissions" : {
"command" : "chmod +x /opt/myapp-3.2.1/myapp"
}
}
}
}
Source :
https://s3.amazonaws.com/cloudformation-examples/BoostrappingApplicationsWithAWSCloudFormation.pdf
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html