Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badly scoped variables in AWSLambdaPSCore #1173

Closed
indented-automation opened this issue May 9, 2022 · 2 comments
Closed

Badly scoped variables in AWSLambdaPSCore #1173

indented-automation opened this issue May 9, 2022 · 2 comments
Assignees
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue queued

Comments

@indented-automation
Copy link

indented-automation commented May 9, 2022

Describe the bug

The private function _packageProject attempts to concatenate with a variable from a parent scope which is not declared in any intermediate scope.

https://github.com/aws/aws-lambda-dotnet/blob/master/PowerShell/Module/Private/_DeploymentFunctions.ps1#L253-L254

If $Name is defined with a type in global scope then the invocation of _packageProject can fail.

For example, if a variable is instantiated with a type that does not support op_Addition an error will be raised:

# That this is set is none of this modules business.
[IPAddress]$Name = '1.2.3.4'

Expected Behavior

That the lambda package would create successfully.

Current Behavior

The build fails because of an attempt to += based on the existing $Name variable from global scope.

16|PS> New-AWSPowerShellLambdaPackage @params
Staging deployment at c:\temp\stage\test
Configuring PowerShell to version 7.2.1
Generating C# project C:\temp\stage\test\test.csproj used to create Lambda function bundle.
Generating C:\temp\stage\test\Bootstrap.cs to load PowerShell script and required modules in Lambda environment.
Generating aws-lambda-tools-defaults.json config file with default values used when publishing project.
Copying PowerShell script to staging directory
Creating deployment package at c:\temp\test.zip
InvalidOperation: C:\Users\chris\Documents\PowerShell\Modules\AWSLambdaPSCore\3.0.1.0\Private\_DeploymentFunctions.ps1:254
Line |
 254 |          $arguments += " --configuration Release --framework $AwsPower …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.Net.IPAddress] does not contain a method named 'op_Addition'.

When deploying this package to AWS Lambda you will need to specify the function handler. The handler for this package is: test::test.Bootstrap::ExecuteFunction. To request Lambda to invoke a specific PowerShell function in your script specify the name of the PowerShell function in the environment variable AWS_POWERSHELL_FUNCTION_HANDLER when publishing the package.
Resolve-Path: C:\Users\chris\Documents\PowerShell\Modules\AWSLambdaPSCore\3.0.1.0\Public\New-AWSPowerShellLambdaPackage.ps1:198
Line |
 198 |  …   PathToPackage                   = Resolve-Path -Path $OutputPackage
     |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'C:\temp\test.zip' because it does not exist.

Reproduction Steps

# That this is set is none of this modules business.
[IPAddress]$Name = '1.2.3.4'

New-Item c:\temp\stage -ItemType Directory
Set-Content 'c:\temp\test.ps1' -Value 'Write-Host "Hello world"'
$params = @{
    ScriptPath       = 'c:\temp\test.ps1'
    StagingDirectory = 'c:\temp\stage'
    OutputPackage    = 'c:\temp\test.zip'
}
New-AWSPowerShellLambdaPackage @params

Possible Solution

Use parameters to pass variables between scopes. Properly declare variables in parent scopes.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSLambdaPSCore 3.0.1.0

Targeted .NET Platform

.NET Core 3.1

Operating System and version

Windows 11

@indented-automation indented-automation added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 9, 2022
@ashishdhingra ashishdhingra added B and removed needs-triage This issue or PR still needs to be triaged. labels May 20, 2022
@ashishdhingra ashishdhingra added queued p2 This is a standard priority issue and removed B labels Nov 2, 2022
@ashishdhingra ashishdhingra self-assigned this Oct 18, 2024
@ashishdhingra
Copy link
Contributor

Fixed in AWSLambdaPSCore 4.0.4.0

Copy link
Contributor

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants