Skip to content

Instantly share code, notes, and snippets.

View austoonz's full-sized avatar

Andrew Pearce austoonz

View GitHub Profile
@austoonz
austoonz / Simple-S3Bucket-SNS
Last active February 9, 2024 02:38
A CloudFormation template sample for creating an S3 Bucket with an SNS Trigger.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple S3 Bucket with SNS Trigger
Parameters:
BucketName:
Type: String
Description: The name of the S3 Bucket to create
@austoonz
austoonz / SQS-SNS-Subscription
Last active January 23, 2024 22:35
A CloudFormation template sample to subscribe an SQS Queue to an SNS Topic.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: SQS Queue subscribed to an SNS Topic
Parameters:
SourceSNSTopicArn:
Type: String
Description: SNS Topic Arn to subscribe the SQS Queue to
@austoonz
austoonz / SSMAssociation
Created February 6, 2019 17:29
A CloudFormation template to create a PowerShell based AWS Systems Manager Association with inline PowerShell.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: "Systems Manager Association"
Resources:
Association:
Type: AWS::SSM::Association
Properties:
@austoonz
austoonz / Get-AWSCommandsFromFile.ps1
Last active April 21, 2022 05:39
This function will use the PowerShell Parser, and the Get-AWSCmdletName cmdlet (found in AWS.Tools.Common, AWSPowerShell or AWSPowerShell.NetCore) to find and output all AWS Cmdlets from a script. This can be used to assist with migrations to the modular AWS Tools for PowerShell.
function Get-AWSCommandsFromFile {
[CmdletBinding()]
param (
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
$FilePath
)
$awsCommands = @{}
$tokens = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $FilePath -Raw), [ref]$null)
@austoonz
austoonz / Get-AWSRegionLatency
Last active April 12, 2022 15:58
Sample PowerShell function to identify the closest AWS Region using AWS Service Endpoints.
function Get-AWSRegionLatency {
param (
[ValidateSet('dynamodb')]
[String] $ServiceForMeasurement = 'dynamodb'
)
$endpoints = [System.Collections.ArrayList]::new()
$regions = (Get-AWSRegion | Where-Object {$_.Region -notlike 'us-iso*'}).Region
foreach ($region in $regions) {
$null = $endpoints.Add(('{0}.{1}.amazonaws.com' -f $ServiceForMeasurement, $region))
@austoonz
austoonz / AWS-ApplyDSCMofs
Last active December 30, 2021 16:17
Samples for deploying an AWS Systems Manager Association using the 'AWS-ApplyDSCMofs' Document.
# Overview
This Gist provides samples to simplify the usage of the AWS Systems Manager Document, "AWS-ApplyDSCMofs".
@austoonz
austoonz / Get-EpochTimeFrom.ps1
Last active June 1, 2021 15:47
PowerShell snippets for dealing with epoch ('01-01-1970')
function Get-EpochTimeFrom {
param (
[int]$Seconds
)
(Get-Date -Date '01-01-1970') + ([System.TimeSpan]::FromSeconds($Seconds))
}
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
@austoonz
austoonz / Write-SSMComplianceItemExample
Last active April 5, 2019 22:31
Sample code for writing an AWS Systems Manager Compliance Item.
$managedInstanceId = (Get-Content -Path 'C:\ProgramData\Amazon\SSM\InstanceData\Vault\Store\RegistrationKey' -Raw | ConvertFrom-Json).instanceID
$moduleNames = @(
'AWSPowerShell',
'ClipboardText',
'Convert',
'PSWindowsUpdate'
)
$complianceItems = [System.Collections.Generic.List[Amazon.SimpleSystemsManagement.Model.ComplianceItemEntry]]::new()
foreach ($moduleName in $moduleNames)
@austoonz
austoonz / Invoke-FastPing
Last active March 1, 2019 17:02
A PowerShell Function that uses asynchronous ping commands to quickly ping a fleet of target machines.
# This has been replaced by the FastPing PowerShell Module.
## Source
[GitHub](]https://github.com/austoonz/FastPing)
## Installation
```powershell
Install-Module -Name FastPing -Scope CurrentUser