部署为AWS Lambda函数的PowerShell Core脚本无法使用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支持.参考URL https://aws.amazon.com/blogs/developer/anuncuncing-lambda-support-for-powershell-core/
AWS Recently announced Lambda Support for PowerShell Core. Reference URL https://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/
按照URL中给出的步骤并作为Lambda函数部署在Powershell Core脚本下方.
Followed the steps given in the URL and deployed below Powershell Core script as a Lambda Function.
脚本:
#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函数运行时失败.当AWS Lambda函数在Linux环境中运行时,会发生这种情况.请帮忙.
When I trigger the Lambda function it fails. This Powershell script tries to remote connect a Windows EC2 Instance and run Commandlet "Get-Service". It fails at the Commandlet "new-pssession". Same script runs fine in Windows Computer powershell. But fails when run as AWS Lambda function. This happens as AWS Lambda function runs in Linux environment. Please help.
错误:
{
"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支持团队合作,并得到以下响应:
Worked with the AWS support team and got the following response:
经过进一步测试,Lambda服务团队已确认lambda环境当前不支持New-PSSession.这与PS Remoting在Linux的PowerShell核心上的工作方式有关."
"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."
显然,这是路线图上的功能,因此我们可能最终会看到它们.
Apparently it's a feature on the roadmap, so we may see it eventually.
这篇关于部署为AWS Lambda函数的PowerShell Core脚本无法使用Commandlet new-pssession远程连接到Windows EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!