0 votes
1 view
in AWS by (19.2k points)

I've been trying to use the AWS Update-LMFunctionCode to deploy my file to an existing lambda function in AWS.

Differing from the Publish-LMFunction where I can provide just a path to the zipFile (-FunctionZip), the Update-LMFunction wants a memorystream for its -Zipfile argument.

is there an example of loading a local zip file from disk into a memory stream that works? My initial calls are getting errors that the file can't be unzipped... 

$deployedFn =  Get-LMFunction -FunctionName $functionname

        "Function Exists - trying to update"


            [system.io.stream]$zipStream = [system.io.File]::OpenRead($zipFile)

        [byte[]]$filebytes = New-Object byte[] $zipStream.length

        [void] $zipStream.Read($filebytes, 0, $zipStream.Length)



        $zipString =  [System.Convert]::ToBase64String($filebytes)

        $ms = new-Object IO.MemoryStream

        $sw = new-Object IO.StreamWriter $ms


        Update-LMFunctionCode -FunctionName $functionname -ZipFile $ms



             $ErrorMessage = $_.Exception.Message

            Write-Host $ErrorMessage



docs for the Powershell function is here: http://docs.aws.amazon.com/powershell/latest/reference/items/Update-LMFunctionCode.html although it wants to live in a frame...

1 Answer

0 votes
by (44.6k points)

To copy from one stream to another, use the CopyTo method:

try {

    $zipFilePath = "index.zip"

    $zipFileItem = Get-Item -Path $zipFilePath

    $fileStream = $zipFileItem.OpenRead()

    $memoryStream = New-Object System.IO.MemoryStream



    Update-LMFunctionCode -FunctionName "PSDeployed" -ZipFile $memoryStream


finally {



Welcome to Intellipaat Community. Get your technical queries answered by top developers !