Search code examples
powershellamazon-web-servicesaws-lambdaaws-powershell

Publish Lambda Function in AWS


I am attempting to publish a new Lambda function if it doesn't already exist. The Update seems to be working great, and I can update it at will. However when I try to do the Publish command I keep getting the error Member must not be null

$zipFilePath = "E:\ProductName-Dev\release.zip"
$zipFileItem = Get-Item -Path $zipFilePath
$fileStream = $zipFileItem.OpenRead()
$memoryStream = New-Object System.IO.MemoryStream
$fileStream.CopyTo($memoryStream)   

$cmdOutput = Get-LMFunction -FunctionName new-extract;

try{
    if($?) {
        "lambda function already in AWS"               
        Update-LMFunctionCode -FunctionName new-extract -ZipFile $memoryStream -Publish 1

    } else {
        "need to publish new lambda function"           
        Publish-LMFunction -FunctionName new-extract -FunctionZip $zipFilePath -Handler exports.handler -Role arn:aws:iam::0000000:role/my-extract -Region us-east-1 
    }
}
finally {
    $fileStream.Close()
}

If I run the Publish-LMFunction without all of the parameters and enter things manually I still get the error. Is there something obvious I'm messing? I believe I have all 4 required fields added to my Publish function. I can also create these within the webconsole, so I don't think it's a credentials issue.


Solution

  • I was simply missing the Runtime parameter

    Publish-LMFunction -FunctionName $FunctionName -FunctionZip $zipFilePath -Handler exports.handler -Role arn:aws:iam:$AccountNumber:role/$RoleName -Region $Region -Runtime nodejs4.3
    

    Their documentation shows it as required but when you are writing in the Powershell ISE it does not put an asterisk by the field.