AWS最近宣布Lambda支持PowerShell Core。 引用网址 https://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/
按照 URL 中给出的步骤操作,并在 Powershell Core 脚本下部署为 Lambda 函数。
脚本:
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.335.0'}
$pw = convertto-securestring -AsPlainText -Force -String "Password"
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "UserID",$pw
$s = new-pssession -computername "AWSECS2DNS" -credential $cred
Invoke-Command -Session $s -ScriptBlock {Get-Service}
当我触发 Lambda 函数时,它失败了。此Powershell脚本尝试远程连接Windows EC2实例并运行Commandlet "Get-Service"。它在命令"新状态"中失败。相同的脚本在Windows Computer powershell中运行良好。但在作为 AWS Lambda 函数运行时失败。当 AWS Lambda 函数在 Linux 环境中运行时,就会发生这种情况。请帮忙。
错误:
{
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load shared library 'libpsrpclient' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibpsrpclient: cannot open shared object file: No such file or directory",
"stackTrace": [
"at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost.ExecuteFunction(Stream inputStream, ILambdaContext context)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
]
}
与 AWS 支持团队合作,得到以下响应:
"经过进一步测试,Lambda服务团队已经确认New-PSSession目前在lambda环境中不受支持。这与PS Remoting在Linux的PowerShell核心上的工作方式有关。
显然,这是路线图上的一项功能,因此我们最终可能会看到它。