Created
November 16, 2018 02:32
-
-
Save amitsaha/7a4a4863184b0d2822b4a13cee49dcff to your computer and use it in GitHub Desktop.
Powershell + DynamoDB table scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DynamoByPrefix($table, $keyPrefix) | |
{ | |
$region = "ap-southeast-2" | |
$regionEndpoint=[Amazon.RegionEndPoint]::GetBySystemName($region) | |
$client = New-Object Amazon.DynamoDBv2.AmazonDynamoDBClient($regionEndpoint) | |
$req = New-Object Amazon.DynamoDBv2.Model.ScanRequest | |
$req.TableName = $table | |
$result = $client.Scan($req) | |
$result.Items | Where-Object {$_.Key.S.StartsWith($keyPrefix)} | ForEach-Object { | |
$_.Key.S.Replace($keyPrefix,"") | |
} | |
} | |
# Usage | |
Get-DynamoByPreix "Table" "keyPrefix:" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment