1
votes

I tried to run cfn-signal from cloudformation, to create a Windows server 2008 instance. creating stack and roles and waithandler are fine, the only problem is sending a successfull signal from instance to the cloudformation.

the Userdata of cloudformation template is :

  "UserData": {
          "Fn::Base64": {
            "Fn::Join": [
              "",
              [
                "<script> \n",
                "cd C:\\chef\\ff_dotnet_2008\\test\\integeration\\default \n",
                "C:\\opscode\\chef\\embedded\\bin\\inspec.bat exec win2008.rb \n",
                "cd /",
                "\n",
                "cfn-signal.exe ",
                {
                  "Fn::Base64": {
                    "Ref": "WaitHandlewin2008"
                  }
                },
                "\n",
                "echo cfn-signal: %ERRORLEVEL% >> C:\\userdata.log \n",
                "</script>"
              ]
            ]
          }
        }
      }
    },

I loged in through the instance, the inspec part of userdata ran successfully but for cfn-signal.exe the error is :

2017-07-27T17:55:18.813Z: Ec2HandleUserData: Message: Could not find <powershell> and </powershell>
2017-07-27T17:55:18.814Z: Background plugin complete: Ec2HandleUserData
2017-07-27T17:55:18.814Z: After ready plugins complete.
2017-07-27T17:55:19.988Z: SSM Service is running now
2017-07-27T17:55:23.793Z: Failed to fetch instance metadata http://169.254.169.254/latest/meta-data/public-ipv4 with exception The remote server returned an error: (404) Not Found.
2017-07-27T17:55:23.797Z: Ec2SetWallpaper: Could not get metadata for: meta-data/public-ipv4

Error in Aws Console is:

AWS::CloudFormation::WaitCondition : WaitCondition timed out. Received 0 conditions when expecting 1

I ran the same command inside the instance and it works. even I used this Userdata for windows server 2016 and it is working as well! So, I cloudnt undestand what is the problem! any suggestion?

1
It should be <powershell></powershell> instead of <script>!Aira

1 Answers

0
votes

It would be much easier if I can see the rest of the ec2 creation CF template but looking at your error message my guess would be it's not associated with a public IP.

When fetching meta-data, you get 404 if there is no such resource. Try the private IP.

http://169.254.169.254/latest/meta-data/local-ipv4

If you need to add a public IP to your instance, use the below code snippet. (Replace SecurityGroupIds & SubnetId in your existing CFT)

"NetworkInterfaces":[  
   {  
      "AssociatePublicIpAddress":"true",
      "DeviceIndex":"0",
      "GroupSet":[  
         {  
            "Ref":"SecurityGroup01"
         }
      ],
      "SubnetId":{  
         "Ref":"SubnetA"
      }
   }
]