Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29250

Can't call any powershell script from Cloudformation template (windows instance)

$
0
0

I created a Windows 2012 AMI and created an instance of that AMI using the CloudFormation template shown below.

In that JSON script I want to call a PowerShell script to disable a service (simple one). The EC2 Windows 2012 instance gets created. I made sure EC2Config service was running before I took AMI.But the PowerShell script doesn't get executed from the CFN template. Any idea why?

{
     "AWSTemplateFormatVersion": "2010-09-09",
     "Description": "EC2 Head Node Instance ",
     "Parameters": {
       "VPC": {
        "Description": "The default VPC",
        "Type": "AWS::EC2::VPC::Id"
    },
    "AvailabilityZone": {
        "Description": "Availablity Zone",
        "Type": "String"

    },
    "Region":{
        "Description": "Dev/Test/Prod regions",
        "Type": "String"
    },
    "AMI": {
        "Description": "AMI to start virtual server",
        "Type": "String",
        "Default": "ami-19273960",
        "MaxLength": 12,
        "MinLength": 12
    },      
    "Subnet": {
        "Description": "subnet to launch virtual server in",
        "Type": "AWS::EC2::Subnet::Id"
    }

},      
"Resources": {
    "EC2Instance": {
        "Type": "AWS::EC2::Instance",
        "Metadata": {
            "AWS::Cloudformation::Init": {
                "configSets": {
                     "config": [
                     "rename",
                     "bootstrapDSC"
                      ]                 
                },
                "rename": {
                     "a-rename-computer" : {
                      "command": "powershell.exe -Command Rename-Computer -qrmawshead01 Server1 -Restart",
                      "waitAfterCompletion" : "forever"
                      }
                },
                "bootstrapDSC": {
                     "a-setpullmode" : {
                      "command": "powershell.exe -Command c:\\cfn\\scripts\\SetPullMode.ps1",
                              "waitAfterCompletion" :"0"
                      }  

                }

            }

        },
        "Properties": {
            "ImageId" : { "Ref": "AMI"},
            "SubnetId": {"Ref": "Subnet"},
            "AvailabilityZone": {"Ref": "AvailabilityZone"},
            "SecurityGroupIds" : [ "sg-b603b2cc" ],
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Head Node in DEV region"
                }
            ]
            }
        }

},
"Outputs": {
    "InstanceId": {
        "Value": {"Ref": "EC2Instance"},
        "Description": "ID of virtual server"
    },

    "PublicIPAddress": {
        "Value": {"Fn::GetAtt": ["EC2Instance", "PublicIp"]},
        "Description": "public IP address of virtual server"
    }
  }
 }

Viewing all articles
Browse latest Browse all 29250

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>