问题
AWS Recently announced Lambda Support for PowerShell Core. Reference URL https://aws.amazon.com/blogs/developer/announcing-lambda-support-for-powershell-core/
Followed the steps given in the URL and deployed below Powershell Core script as a Lambda Function.
Script:
#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}
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.
Error:
{
"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 )"
]
}
回答1:
Worked with the AWS support team and got the following response:
"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.
来源:https://stackoverflow.com/questions/52654841/powershell-core-script-deployed-as-aws-lambda-function-fails-to-remote-connect-i