Skip to content

Instantly share code, notes, and snippets.

@amitsaha
Created November 16, 2018 02:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitsaha/7a4a4863184b0d2822b4a13cee49dcff to your computer and use it in GitHub Desktop.
Save amitsaha/7a4a4863184b0d2822b4a13cee49dcff to your computer and use it in GitHub Desktop.
Powershell + DynamoDB table scan
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