PowerShell Universal Dashboard and AWS Elastic Beanstalk

PowerShell Universal Dashboard and AWS Elastic Beanstalk

PowerShell UD is a powerful PowerShell frontend framework and I highly recommend you to try it out. I played with PowerShell Universal Dashboard (UD) when it was released in beta by Adam Driscoll. At that time I hosted a dashboard on Raspberry Pi to show some sensor data. I really like UD as it enables PowerShell developer to create a beautiful, interactive and usable webpage with just a few lines of PowerShell code.

Fast forward. A few days ago while showering, I was wondering how would one run UD using AWS, and most importantly without managing the server. (Shower is one of the best activities to inspire innovation, btw. 😎) I won't bore you with the attempts I tried. In the end, I decided to use AWS Elastic Beanstalk (Beanstalk) and it worked nicely. In this post, I will share with you about how to run PowerShell Universal Dashboard (UD) with AWS Elastic Beanstalk (Beanstalk). Beanstalk is an orchestration service for deploying web applications including .NET/ IIS based ones. Beanstalk has rich load balancing, blue-green deployment and auto-scaling capabilities and you can look into those when scaling your application.

As UD can run as an IIS web application., it is fairly straight forward to a) make the deployment bundle and then b) deploy the bundle to Beanstalk.

a: Create the Beanstalk Deployment Package

TL;DR

  1. Create Beanstalk Deployment Manifest (aws-windows-deployment-manifest.json). The manifest tells how you want Beanstalk to deploy the application. Manifest doc
  2. IIS application (psud.zip). This file will contain the downloaded Universal Dashboard Community module files at the folder root. Your dashboard.ps1should be here.
  3. The two files are again zipped together as the final artifact: mypsud.zip. We will later upload the mypsud.zip to Beanstalk.

Details

i. Deployment Manifest

As for the Deployment Manifest, you can use the following as an example or reference the manifest doc. I changed the appBundle property to point to the psud.zip. I then save this as aws-windows-deployment-manifest.json in my computer's c:\temp\src folder to help me organize.

{
    "manifestVersion": 1,
    "deployments": {
        "aspNetCoreWeb": [
        {
            "name": "mypsud",
            "parameters": {
                "appBundle": "psud.zip",
                "iisPath": "/",
                "iisWebSite": "Default Web Site"
            }
        }
        ]
    }
}

ii. IIS Application (UD)

I saved the UD community module to my local computer's c:\temp directory.

Save-Module UniversalDashboard.Community -path c:\temp -AcceptLicense

Hint: You might need to update your PowerShellGet module version and then restart your PowerShell console.
Install-Module powershellget -Force

The version is 2.4.1 at the time of writing.

I then update the C:\temp\UniversalDashboard.Community\2.4.1\dashboard.ps1 to what I want. When the version changes, yours will be in a different module version path.

dashboard.ps1
Here is my test dashboard code. Note, you will need to add the -Wait switch to the Start-UDDashboard function for the IIS deployment.

Start-UDDashboard -Wait -Dashboard (
  New-UDDashboard -Title "This is a test" -Content {
    New-UDCard -Title "Hello, test test"
  }
)

iii. Deployment Package

I then use the following PowerShell commands to package things up correctly. The folder structure is VERY important and using Windows Explorer can sometimes create an additional layer of folder in the zip file.

$ProgressPreference = 'SilentlyContinue' # turning the progrss bar speeds up the process
Compress-Archive -Path 'C:\temp\UniversalDashboard.Community\2.4.1\*' -DestinationPath 'C:\temp\src\psud.zip'
Compress-Archive -Path 'C:\temp\src\*' -DestinationPath 'C:\temp\artifact\mypsud.zip'

Sweet!!!! we now have the deployment package: mypsud.zip! Moving on to the next step.

b. Create the Beanstalk/ Universal Dashboard App

Let's create our Beanstalk/ Universal Dashboard app now. I assume you already have an AWS account. If you would like to create one, follow the steps in this article. I use my personal AWS account and the us-east-1 region in the following steps:
  1. Log into the AWS account and open the Elastic Beanstalk console. Click on the "Get started" button.
  2. In the Create a web app page, I enter the application name, select .NET (Windows IIS) as the platform. while I have the code I select the Sample applications, to begin with. Then I choose Configure more options.
  3. In the additional options, I find the "Instances" card and click on "Modify".
  4. I changed Instance type to t2.micro to use the free tier instance hours included in my AWS account (for the first year only). I don't need additional space so I picked the default and click on "Save" and then create the environment.
  5. The environment creation takes a few minutes. And I can see my website/ dashboard's URL here as well.
  6. Once deployment completed, I see this page with the green healthy checkmark. Now it the time to upload our dashboard code. I click on "Upload and Deploy"
  7. I choose the mypsud.zip created in previous steps.
  8. Beanstalk automatically updates the IIS for me without me managing the instances/ IIS site.
  9. And once deployed, I can navigate to the URL and voila! The dashboard is up and running! (In the test here I use HTTP only, please use HTTPS if you are going to host any formal workload)
  10. To change the dashboard, I can update the dashboard.ps1, re-compress the zips, and then simply upload the zip to Beanstalk.
  11. When I am done with the exploration, I terminate the environment so I don't exceed my free tier limit.


That's it! You now know how to create the bundle for deploying PowerShell UD in AWS Elastic Beanstalk! PowerShell UD is a powerful framework and I highly recommend you to try it out. You can run it locally on your computer to begin with. 👍👍👍

Note

  • There might be some restrictions when running in Beanstalk as I wasn't able to get the CPU usage to show in one of my attempts. I didn't spend more time looking into the reasons. If you ever find out more, please share it as well. :D

Appendix

Comments

Popular posts from this blog

PowerShell tip: Using the -OutVariable

When TLS 1.2 breaks Invoke-Webrequest

PowerShell codes in PowerCLI's Invoke-VMScript