Skip to content

Instantly share code, notes, and snippets.

View austoonz's full-sized avatar

Andrew Pearce austoonz

View GitHub Profile
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
@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 / Lambda-SQS-Trigger
Last active January 15, 2019 03:38
A CloudFormation template sample to subscribe an AWS Lambda Function to an SQS Queue.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: SQS Queue with Lambda Trigger
Parameters:
LambdaS3BucketName:
Type: String
Description: S3 Bucket Name holding the Lambda Function Package
(Get-Item -Path 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').GetValue('HostName')
brew cask install quicklook-json
@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 / Write-SSMInventoryExample
Created January 25, 2019 06:09
Sample code for writing an AWS Systems Manager Inventory record.
$powerShellModules = Get-Module -ListAvailable
$date = Get-Date -UFormat '+%Y-%m-%dT%H:%M:%SZ'
$inventoryItems = [System.Collections.Generic.List[Amazon.SimpleSystemsManagement.Model.InventoryItem]]::new()
$contentList = [System.Collections.Generic.List[System.Collections.Generic.Dictionary[System.String,System.String]]]::new()
foreach ($moduleName in ($powerShellModules | Select-Object -Property Name -Unique).Name)
{
$module = $powerShellModules.Where({$_.Name -eq $moduleName}) | Sort-Object -Property Version -Descending | Select-Object -First 1
$contentDictionary = [System.Collections.Generic.Dictionary[System.String,System.String]]::new()
@austoonz
austoonz / get-arm64-ami-ids
Created January 25, 2019 06:11
Sample code for retrieving the AWS AMI IDs for ARM64 images.
aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended
@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))