PSDynamoDB.psm1

<#
    Code in this file will be added to the beginning of the .psm1. For example,
    you should place any using statements here.
#>

Function Get-DdbTableItem {
    [cmdletbinding()]
    param (
        [string]$HashKey,
        [string]$RangeKey
    )
    if ($PSBoundParameters.Keys -contains 'RangeKey' ){
        [System.Threading.Tasks.Task]$task = $table.GetItemAsync([Amazon.DynamoDBv2.DocumentModel.Primitive]::new($HashKey),[Amazon.DynamoDBv2.DocumentModel.Primitive]::new($RangeKey))
    } else {
        [System.Threading.Tasks.Task]$task = $table.GetItemAsync([Amazon.DynamoDBv2.DocumentModel.Primitive]::new($HashKey))
    }
    $task.Wait()
    $task.Result
}
Function Initialize-DdbClient {
    [cmdletbinding()]
    param (
        [string]$TableName
    )
    $global:ddbClient = [Amazon.DynamoDBv2.AmazonDynamoDBClient]::new()
    $global:table = [Amazon.DynamoDBv2.DocumentModel.Table]::LoadTable($ddbClient, $TableName)
}
Function New-DdbTableItem {
    [cmdletbinding()]
    param (
        [Parameter(
            ParameterSetName = 'ByJson'
        )]
        [string]$Json,
        [Parameter(
            ParameterSetName = 'ByAttribMap'
        )]
        [hashtable]$AttributeMap
    )
    switch($PSCmdlet.ParameterSetName) {
        'ByJson' {
            $doc = [Amazon.DynamoDBv2.DocumentModel.Document]::FromJson($json)
        }
        'ByAttribMap' {
            $attribMap = New-Object 'System.Collections.Generic.Dictionary[string,Amazon.DynamoDBv2.Model.AttributeValue]'
            foreach ($key in $AttributeMap.Keys) {
                $attribMap.Add($key,$AttributeMap[$key])
            }
            $doc = [Amazon.DynamoDBv2.DocumentModel.Document]::FromAttributeMap($attribMap)
        }
    }
    [System.Threading.Tasks.Task]$task = $table.PutItemAsync($doc)
    $task.Wait()
    $task.Result
}
<#
    Code in this file will be added to the end of the .psm1. For example,
    you should set variables or other environment settings here.
#>

Write-Warning 'This module is in early development. Please use with caution. Contact me @theposhwolf with questions.'