I'm trying to run a dotnet core 1.0 console app inside AWS lambda. This is just something I was doing for interest sake, however I've ran into a few issues.
my dotnet core app looks like this:
using System;
namespace ConsoleApplication
{
public class Program
{
public static int Main(string[] args)
{
Console.WriteLine("Hello from dotnet!");
return 0;
}
}
}
I compiled the dotnet app on Ubuntu 14.04 using:
dotnet build --native --output out --framework dnxcore50
This gives me a native app that I can run on Linux. This all works!
From here I wanted to see if I could get this running inside AWS lambda. Since lambda doesn't support dotnet, I found some nodejs to execute my dotnet app:
var exec = require('child_process').exec;
exports.handler = function(event, context) {
console.log('Hello from nodejs!');
child = exec("./hwapp", function(error) {
context.done(error, 'done');
});
child.stdout.on('data', console.log);
child.stderr.on('data', console.error);
};
I created a Lambda function by uploading a zip file containing my dotnet core 1.0 app and the nodejs file - index.js. When I test the lambda function I'm getting an error as follows:
{
"errorMessage": "Command failed: /bin/sh -c ./hwapp\n",
"errorType": "Error",
"stackTrace": [
"",
"ChildProcess.exithandler (child_process.js:213:12)",
"emitTwo (events.js:87:13)",
"ChildProcess.emit (events.js:172:7)",
"maybeClose (internal/child_process.js:821:16)",
"Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)"
]
}
I've tried quite a few different things, but I'm stuck. I'm thinking it might be due to building the dotnet app on Ubuntu and not Amazon Linux, but really I'm not sure... Can anybody help me?
Thanks.
I had the exactly same error. I suspect this is because the binary was compiled on Ubuntu, not on Amazon Linux.
I also setup Amazon Linux that AWS Lambda (based on Red Hat) actually runs on. However, build wasn't successful. Here's the error message I've got:
[ec2-user@ip-172-31-35-226 helloworld]$ sudo dotnet build
Project helloworld (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling helloworld for .NETCoreApp,Version=v1.0
/home/ec2-user/helloworld/project.json(7,31): error NU1002: The dependency Microsoft.CodeAnalysis.Common 1.2.0-beta1-20160202-02 does not support framework .NETCoreApp,Version=v1.0.
/home/ec2-user/helloworld/project.json(7,31): error NU1002: The dependency Microsoft.CodeAnalysis.CSharp 1.2.0-beta1-20160202-02 does not support framework .NETCoreApp,Version=v1.0.
/home/ec2-user/helloworld/project.json(7,31): warning NU1007: Dependency specified was Microsoft.NETCore.App >= 1.0.0-rc2-002673 but ended up with Microsoft.NETCore.App 1.0.0-rc2-23910.
Compilation failed.
1 Warning(s)
2 Error(s)
Time elapsed 00:00:00.0318055
[ec2-user@ip-172-31-35-226 helloworld]$
Message says that some of dependencies don't support RHEL yet at the time of writing this answer (2016-5-6). We might have to wait until dependent packages support.
You may also be running into an issue where the executable within your zip uploaded to lambda is not assigned the linux execute permission. You won't be able to spawn your child process and execute it without this permission.
Unfortunately this is difficult to assign with standard zip utilities available on Windows. So, if you're building your deployment zip on a Windows machine, you might look at using a grunt / grunt-contrib-compress and a grunt configuration that looks similar to:
compress: {
main: {
options: {
archive: 'dist/lambda.zip'
},
files: [
...
{src: 'pathToExecutable', mode: 777} //this mode sets the execute flag
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With