作为 AWS Lambda 函数部署的 PowerShell 核心脚本无法使用 Commandlet new-pssession 远程连接到 Windows EC2 实例
PowerShell Core Script deployed as AWS Lambda function fails to remote connect into Windows EC2 Instance using the Commandlet new-pssession
AWS 最近宣布了对 PowerShell Core 的 Lambda 支持。
参考URLhttps://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/
按照 URL 中给出的步骤进行操作,并在 Powershell 核心脚本下部署为 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"。它在 Commandlet "new-pssession" 处失败。相同的脚本 运行 在 Windows 计算机 powershell 中没问题。但是当 运行 作为 AWS Lambda 函数时失败。这发生在 Linux 环境中的 AWS Lambda 函数 运行s。请帮忙。
错误:
{
"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 支持团队合作并获得以下回复:
"After further testing, Lambda service team has confirmed that New-PSSession is currently not supported in lambda environment. This has to do with the way PS Remoting works on PowerShell core for Linux."
显然这是路线图上的一个功能,所以我们可能会最终看到它。
AWS 最近宣布了对 PowerShell Core 的 Lambda 支持。 参考URLhttps://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/
按照 URL 中给出的步骤进行操作,并在 Powershell 核心脚本下部署为 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"。它在 Commandlet "new-pssession" 处失败。相同的脚本 运行 在 Windows 计算机 powershell 中没问题。但是当 运行 作为 AWS Lambda 函数时失败。这发生在 Linux 环境中的 AWS Lambda 函数 运行s。请帮忙。
错误:
{
"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 支持团队合作并获得以下回复:
"After further testing, Lambda service team has confirmed that New-PSSession is currently not supported in lambda environment. This has to do with the way PS Remoting works on PowerShell core for Linux."
显然这是路线图上的一个功能,所以我们可能会最终看到它。