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

PowerShell deployment example #16

Open
austoonz opened this issue Apr 28, 2023 · 10 comments
Open

PowerShell deployment example #16

austoonz opened this issue Apr 28, 2023 · 10 comments

Comments

@austoonz
Copy link
Contributor

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

@Conrad-awaze
Copy link

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
Copy link

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
Copy link
Contributor Author

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
Copy link

mtboren commented Aug 30, 2023

...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:

  • perform all of the operations (listed below) from app "PowerShell" (v7.x) within Windows (I'm wondering if some failures for people have been due to legacy / PSv5 behaviors)
  • perform all of the same operations from app "Windows PowerShell" (v5.1) within Windows, with one modification of the /build-PwshRuntimeLayer.ps1:76 file:
    • change the -Encoding param value to Ascii from UTF8 (prevents the aforementioned BOM issue)

Steps:

  • git clone https://github.com/awslabs/aws-lambda-powershell-runtime
  • build local layer contents via powershell-runtime/build-PwshRuntimeLayer.ps1
  • deploy with SAM via sam deploy --template powershell-runtime/template.yml --<rest of "profile" and "s3bucket" params>
  • deploy a Lambda function stack with the new runtime layer as its layer
  • invoke Lambda function
  • profit 💰

@austoonz
Copy link
Contributor Author

austoonz commented Sep 1, 2023

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
Copy link
Contributor Author

austoonz commented Sep 1, 2023

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
Copy link
Contributor Author

austoonz commented Sep 1, 2023

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
Copy link

mtboren commented Sep 4, 2023

...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 added a commit to mtboren/aws-lambda-powershell-runtime_fork that referenced this issue Sep 8, 2023
mtboren added a commit to mtboren/aws-lambda-powershell-runtime_fork that referenced this issue Sep 8, 2023
@mtboren
Copy link

mtboren commented Sep 8, 2023

...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
Copy link
Contributor Author

austoonz commented Sep 3, 2024

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]"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants