Friday, October 16, 2015

AWS CloudFormation WaitCondition example

CloudFormation is a great tool for spinning up EC2 instances and the like.

Here is an example of using a wait condition for waiting until a Windows 2012 R2 Base service has started.  Please excuse the designer JSON.  I was using it to validate the JSON correctness.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "YourInstanceId": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "DisableApiTermination": "false",
        "InstanceInitiatedShutdownBehavior": "stop",
        "ImageId": "ami-dfccd1ef",
        "KeyName": "YourKeyName",
        "Monitoring": "false",
        "Tags": [
          {
            "Key": "Name",
            "Value": "NameOfYourInstance"
          }
        ],
        "NetworkInterfaces": [
          {
            "DeleteOnTermination": "true",
            "DeviceIndex": 0,
            "SubnetId": "yourSubnetId",
            "GroupSet": [
              "yourSecurityGroupId"
            ],
            "AssociatePublicIpAddress": "true"
          }
        ],
"UserData": {
          "Fn::Base64": {
            "Fn::Join": [
              "",
              [
                "<powershell>\n",
                "Start-Service BITS \n",
"$arrService = Get-Service BITS \n",
"$returnCode = 1 \n",
"if ($arrService.Status -eq 'running'){ $returnCode = 0 } \n",
"while($arrService.Status -ne 'running') \n",
"{ \n",
"Start-Sleep -s 5 \n",
"$arrService = Get-Service BITS \n",
"if ($arrService.Status -eq 'running'){ $returnCode = 0 } \n",
"} \n",
                "cfn-signal.exe -e $returnCode ",
                {
                  "Fn::Base64": {
                    "Ref": "WaitHandle"
                  }
                },
                "\n",
                "</powershell> \n",
                "<persist>true</persist>"
              ]
            ]
          }
        }
      }
    },
    "WaitCondition": {
      "Type": "AWS::CloudFormation::WaitCondition",
      "DependsOn" : "instancei1c92e0da",
      "Properties": {
        "Handle" : { "Ref" : "WaitHandle" },
        "Timeout" : "300"
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "b0f248b8-89a7-4b6b-881a-ef79dd677322"
        }
      }
    },
    "WaitHandle": {
      "Type": "AWS::CloudFormation::WaitConditionHandle",
      "Properties": {},
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "1f0d4b0b-1971-4e5d-9b2c-5472c764dc92"
        }
      }
    }
  },
  "Description": ""
}

The BITS service was used here since it's a built-in Windows service.  It could be whatever service that you would like to start and verify that it started.

CloudFormation seems good overall.  It would be nice to have a local validator for it and / or a way to test the templates locally first.

I'd like to explore the Vagrant AWS provider when I have time (heard that there might be bugs though regarding Windows).  Please feel free to comment and share your experiences.  Cheers.

Friday, October 9, 2015

WPF path data for plus and minus signs

WPF path data seems not so straight-forward when you first look at it.

There are tools out there to edit it though.

Here are some examples of plus and minus signs if you're interested in something for prototypes and the like.  I didn't see a lot on the web so I thought that I'd share.

Minus (used within a canvas):
            <Canvas.LayoutTransform>
                <RotateTransform Angle="90"></RotateTransform>
            </Canvas.LayoutTransform>
            <Path Width="25" Height="25" Stretch="Uniform" Fill="DarkGray"
            Data="M0,0 L8,0 L8,47 L0,47 z"

Plus (again used within a canvas):
            <Path Width="25" Height="25" Stretch="Uniform" Fill="DarkGray"
            Data="M3.875,0 L5.125,0 5.125,3.875 9,3.875 9,5.125 5.125,5.125 5.125,9 3.875,9 3.875,5.125 0,5.125 0,3.875 3.875,3.875 3.875,0 z"

Cheers.