I cannot get any CloudFormation template to deploy or validate when using PowerShell, but using the exact template I have no issues doing it using AWS CLI or using the AWS Console.
Let's take a basic CloudFormation template, lets call it Test.template
.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Simple template.",
"Parameters" : {
"KeyName" : {
"Type" : "String",
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server"
}
},
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : "test",
}
}
}
}
Nothing special, very basic. Ignoring that this would fail when you were to create the EC2 resource, this is a properly formatted JSON CloudFormation template.
Now, if I run this command using the AWS CLI, it comes back successful and outputs the paramaters:
aws cloudformation validate-template --template-body file://c:/temp/Test.template
Using the exact same file, if I run this in PowerShell I get an error:
Test-CFNTemplate -TemplateBody file://c:/temp/Test.template
Test-CFNTemplate : Template format error: unsupported structure. At line:1 char:1 + Test-CFNTemplate -TemplateBody file://c:/temp/Test.template + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Amazon.PowerShe...NTemplateCmdlet:TestCFNTemplateCmdlet) [Test-CFNTemplate], InvalidOperationException + FullyQualifiedErrorId : Amazon.CloudFormation.AmazonCloudFormationException,Amazon.PowerShell.Cmdlets.CFN.TestCFNTemplateCmdlet
I also have no issues deploying this template using either the AWS Console or using aws cloudformation create-stack
I just cannot figure out why I can't do it using PowerShell.
New-CFNStack
is returning the same error above as well:
Template format error: unsupported structure.
I installed the latest version of the AWS PowerShell module and I'm running Powershell 5.1.14409.1012
Everything else I found regarding this error were from folks who had issues because they weren't using file://
in the TemplateBody but that doesn't appear to be the case here.