normj / LambdaNETCoreSamples

Example .NET Core Lambda functions.
Apache License 2.0
49 stars 10 forks source link

Self Contained project requires RuntimeIdentifier to be specified #2

Closed badcommandorfilename closed 3 years ago

badcommandorfilename commented 5 years ago

Great resource, thanks for making this! I just hit one snag when trying to deploy a netcore2.2 serverless project to Lambda/ApiGateway. I got the error:

/var/task/bootstrap: line 6: /var/task/projectname: cannot execute binary file

The .csproj <PropertyGroup> needs to have <RuntimeIdentifier>ubuntu.16.10-x64</RuntimeIdentifier> specified to deploy to lambda correctly.

Possibly this is just needed for Windows/Visual Studio 2019 development, but this is needed to generate the linux executable in /var/task/ that the bootstrap script runs.

Hopefully this helps someone. I'd make a pull request, but I'm too lazy =P

abukres commented 5 years ago

Thanks. This helped with not getting the 'No such file or directory' error anymore from the bootstrap file.

However locally I am not getting the .exe file anymore and it's causing an "ANCM In-Process Handler Load Failure" error. I see the .dll only. Plus the files now are under a 'ubuntu.16.10-x64' subfolder under netcoreapp3.0 folder.

badcommandorfilename commented 4 years ago

Hi @abukres - I'm developing on Windows too and then deploying to serverless (ubuntu) as well.

What you need is a <RuntimeIdentifier Condition=" '$(Configuration)' == 'Local' ">win10-x64</RuntimeIdentifier>:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <Configurations>Debug;Release</Configurations>
    <RuntimeIdentifier>ubuntu.16.10-x64</RuntimeIdentifier>
    <RuntimeIdentifier Condition=" '$(Configuration)' == 'Debug' ">win10-x64</RuntimeIdentifier>
    <NoWin32Manifest>true</NoWin32Manifest>
  </PropertyGroup>

Also as a sidenote, the Amazon Visual Studio Plugin only supports "Debug" or "Release" configurations when deploying.

normj commented 3 years ago

Sorry I never responded to this sooner but this is now out of date. To reduce cold starts the blueprint was custom runtime samples have been reworked to have the .NET assembly be called bootstrap instead of having a script called bootstrap. That avoids having to start up 2 separate processes.