Skip to content

Instantly share code, notes, and snippets.

View sliedig's full-sized avatar

Stephen Liedig sliedig

  • Amazon Web Services
  • Perth, W. Australia
  • 18:23 (UTC +08:00)
  • X @sliedigaws
View GitHub Profile
@sliedig
sliedig / CloudWatch Logs Rule
Created July 28, 2021 04:17
This CloudFormation template shows and example of setting up an EventBridge event bus, a rule, and a CloudWatch Logs target, with a resource policy that accepts events from the created EventBridge rule. There is no need to provide an IAM role on the rule.
AWSTemplateFormatVersion: '2010-09-09'
Description: Sample template to deliver events from Amazon EventBridge to CloudWatch Logs
Resources:
TestEventBus:
Type: AWS::Events::EventBus
Properties:
Name: test-bus
LogsRule:
Type: AWS::Events::Rule
@sliedig
sliedig / install-pfx-certificates.ps1
Created December 4, 2015 03:39
Install pfx cert and applies permissions to service account
function Set-CertificatePermission()
{
[CmdletBinding()]
param
(
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$ThumbPrint,
[Parameter(Position=2, Mandatory=$true)]
# snapshotter.ps1 - Snapshots all volumes in current region, and trims existing snapshots back to the specified number.
#
# USAGE:
# snapshotter.ps1 [-region regionName] [-preserve numOfSnapshots]
#
# -region: Specify the region in which to find volumes and create snapshots. If not specified, must be specified by the environment
# variable AWS_DEFAULT_REGION.
# -preserve: Number of past snapshots to preserve. If not specified, defaults to 2.
param (
@sliedig
sliedig / aws-cloudwatch-httpmemory
Created March 19, 2015 07:13
Collects w3wp memory data and pushes it to AWS cloudwatch as custom metric
Write-Host "Getting memory usage for w3p"
$instanceId = (new-object net.webclient).DownloadString('http://169.254.169.254/latest/meta-data/instance-id')
$memUsed = Get-WmiObject Win32_process -ComputerName $env:COMPUTERNAME | where CommandLine -Match "w3wp" | ForEach { "{0}" -f $_.VM } | Measure-Object -Sum | Select -ExpandProperty Sum
Write-Host "W3WP memory = $memUsed on InstanceID = $instanceId"
Write-Host "Pushing metrics to Cloudwatch"
. aws cloudwatch put-metric-data --namespace HttpServerMetrics --metric-name HttpServerMemUtilization --dimension InstanceId=$instanceId --value $memUsed --unit "Kilobytes"
start /wait msiexec /i Octopus.Tentacle.<version>.msi /quiet INSTALLLOCATION=C:\Octopus
cd C:\Octopus\Agent
tentacle configure --appdir="C:\Applications" --port=10933 --trust=<server-thumbprint>
tentacle new-certificate
tentacle install
tentacle register-with --server=<server-url> --environment=<environment> --role=<role> --apikey=<some-user-apikey>
octo deploy-release --project=<project-name> --deployto=<environment-to-deploy> --version=<version-to-deploy> --server=<server-url> --apikey=<some-user-apikey>
@sliedig
sliedig / ps-encrypt-web-config
Last active August 29, 2015 13:56
Applies encryption to web.config file. For app.config, rename file to web.config, apply encryption and rename back to app.config.
$frameworkDirectory = $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
Set-Alias aspnet_regiis (Join-Path $frameworkDirectory "aspnet_regiis.exe")
aspnet_regiis -pef "connectionStrings" $WebsitePhysicalPath -prov "RsaProtectedConfigurationProvider"
@sliedig
sliedig / ps-iis
Last active January 2, 2016 02:08
Set-Location $PSScriptRoot
$config = (Get-Content .\run_config.json) -join "`n" | ConvertFrom-Json -ErrorAction Stop
# Create website root directory.
$rootExists = Test-Path -Path $config.WebsiteRootDirectory
if(!$rootExists) {
Write-Host "Creating root directory" -ForegroundColor Yellow -BackgroundColor Black
@sliedig
sliedig / cert
Created December 30, 2013 08:32
ps-cert
#$installedCert = Add-Certificate -pfxPath "C:\dev\certs\criminalinvestigationact-dev.pfx" -pfxPassword "TAIYe76GVaRNdqxSzSje"
#Write-Host $installedCert.ThumbPrint
#Set-CertificatePermission -pfxThumbPrint $installedCert.ThumbPrint -serviceAccount "police\svcCiaDev" #-$containerName $installedCert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
<#
.SYNOPSIS
Installs pfx certificate
.DESCRIPTION
@sliedig
sliedig / IDisposableImpl.cs
Last active December 12, 2015 12:48
Implementing IDisposable... the right way.
// Credit: Chris Patterson http://blog.phatboyg.com/2012/11/29/idisposable-done-right/
public class DisposableClass :
IDisposable
{
bool _disposed;
public void Dispose()
{
Dispose(true);