awslabs / aws-lambda-powershell-runtime

This new PowerShell custom runtime for AWS Lambda makes it even easier to run Lambda functions written in PowerShell to process events.
Apache License 2.0
59 stars 20 forks source link

PowerShell deployment example #16

Open austoonz opened 1 year ago

austoonz commented 1 year ago

Provide an example for how to deploy the runtime using PowerShell (and only PowerShell).

Conrad-awaze commented 1 year ago

Is this a request to show how to deploy and use the runtime? This is what I'm after too so if there are any instructions I'd me most grateful.

gw-bcharboneau commented 1 year ago

Is this a request to show how to deploy and use the runtime? This is what I'm after too so if there are any instructions I'd me most grateful.

yes it is. It is to offer an example of how to deploy the custom runtime, using nothing but powershell cmdlets/modules.

I am patiently awaiting this.

austoonz commented 1 year ago

Every time we try to go down this route for a pure Windows PowerShell build, the underlying Lambda layer is not formatted correctly. For example the /opt/bootstrap file won't be marked with the executable bit in Linux. Or the CloudFormation template ends up UTF8 with BOM, even though we are forcing utf8 with the Set-Content cmdlet.

The only reliable way we've currently found to build from Windows is to use WSL from Windows, and the SAM CLI from within WSL.

mtboren commented 1 year ago

...reliable way we've currently found to build from Windows...

Greets. Firstly, still loving this Lambda PS runtime -- so good! Thx @austoonz and e'erbody that has made this

As for building/deploying a working runtime layer from Windows directly (as in, not from within WSL), I've been able to succeed in at least a couple of ways. In effort to see how I can help with this issue, I'll share those here to get feedback.

❓ My question to the group: what, beyond the descriptions below, will be most helpful in enabling people to succeed in this use case of, "new Lambda PS runtime layer built and deployed from directly within Windows"? Like, having a repo with steps/examples of end-to-end success? Or, me just submitting a PR to this current repo with a Docs update? Something else?

Success from Windows via each of:

Steps:

austoonz commented 1 year ago

Thank you for the details.

I will note that in both a Windows Workspace and a Windows EC2 Instance of mine, the above does not work from either PowerShell or Windows PowerShell (after changing the -Encoding parameter). Both end up failing with the following error, which is indicating the execute bit of the bootstrap file is not set correctly.

For me, using the PowerShell build script in PowerShell on Linux does not work either... same end result with a broken bootstrap.

{
  "errorType": "Runtime.InvalidEntrypoint",
  "errorMessage": "RequestId: 665609a7-17d4-496c-b052-1b0c463561b2 Error: fork/exec /opt/bootstrap: exec format error"
}
austoonz commented 1 year ago

For awareness from further testing, I think this error might have something to do with the pwsh binary, not the bootstrap file.

In my Linux testing, after building the layer with sam build, I can run ./.aws-sam/build/PwshRuntimeLayer/powershell/pwsh -version with success. However in the build using PowerShell, ./layers/runtimeLayer/powershell/pwsh -version results in layers/runtimeLayer/powershell/pwsh: cannot execute binary file.

That's where I'm now looking...

austoonz commented 1 year ago

Found what I think the issue is, will test further across Windows, Linux, and PowerShell/Windows PowerShell to confirm. The examples/demo-runtime-layer-function which I'm testing with is telling the PowerShell runtime build script to build using arm64, instead of x64.

...

New commits have been pushed to resolve the above issue.

I am leaving this issue open as I would still like to have complete PowerShell examples that do not depend on sam deploy if possible.

mtboren commented 1 year ago

...have complete PowerShell examples that do not depend on sam deploy...

Sounds good! @austoonz -- for the packaging portion of such an example, OK to use sam package for the {zip up local resources, upload to S3, and transform SAM template with resultant ContentUri: value}? Or are you picturing an example that uses a strictly CloudFormation template (no Transform: property, no SAM whatsoever)?

mtboren commented 1 year ago

...an example that uses a strictly CloudFormation template (no Transform: property, no SAM whatsoever..

In case this is the desire, I forked this repo and pushed a couple of commits that add such an example. See the comparison at https://github.com/awslabs/aws-lambda-powershell-runtime/compare/main..mtboren:aws-lambda-powershell-runtime_fork:feat_AddPShellDeployExample

How does that do for including a PowerShell-only deployment example, @austoonz?

austoonz commented 1 month ago

I've taken a few stabs at running through the details you've outlined, and both times I end up with execution errors. I have yet to get to the root of the issue (and honestly I haven't spent any real time trying to troubleshoot it).

{
  "errorType": "Runtime.InvalidEntrypoint",
  "errorMessage": "RequestId: 3782d50a-942c-46e9-988a-06653dc5815b Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"
}