AWS Lambda和.NET Core-使用Linux运行时吗? [英] AWS Lambda and .NET Core - Using a Linux Runtime?

查看:178
本文介绍了AWS Lambda和.NET Core-使用Linux运行时吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写C#(.NET Core)中的Alexa技能,该技能可通过AWS Lambda函数(在Amazon Linux上运行)运行。当我编译项目( dotnet发布)时,出现错误:

I am writing an Alexa skill in C# (.NET Core) to be run from an AWS Lambda function (which runs on Amazon Linux). When I compile the project (dotnet publish), I get the error:


找不到运行时目标框架'.NETCoreApp,Version = v1.0'
与目标运行时之一兼容:'win10- x64,win81-x64,
win8-x64,win7-x64'。可能的原因:

Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10- x64, win81-x64, win8-x64, win7-x64'. Possible causes:


  1. 项目尚未还原或还原失败-运行dotnet
    restore

  2. 该项目未在运行时部分中列出 win10-x64,win81-x64,
    win8-x64,win7-x64之一。

  3. 您可能试图
    发布不支持的库。使用dotnet pack来
    分发库。


如果我指定Windows运行时(例如作为 win10-x64 ),它将可以很好地编译,但是我的依赖项之一(Google Sheets API)由于位于基于Linux的Lambda上而在运行时出现了问题。使用Linux运行时(例如debian.8-x64)将导致相同的编译错误。

If I specify a Windows runtime (such as win10-x64), it will compile fine, however one of my dependencies (Google Sheets API) has problems at runtime due to being on the Linux-based Lambda. Using a Linux runtime (such as debian.8-x64) will cause the same compile error.

当AWS开发工具包自身的平台为Linux的?我觉得我缺少明显的东西,一旦有人向我指出这个问题,我就会高兴地面对。

Why would the AWS SDK require a Windows runtime, when its own platform is Linux? I feel like I'm missing something obvious and will happily face palm the moment someone points the issue out to me.

我的project.json文件(主应用程序和)。 NET Core类库项目):

My project.json files (main app, and .NET Core class library project):

AlexaProj

{
  "version": "1.0.0-*",
  "buildOptions": {
  },

  "dependencies": {
    "Microsoft.NETCore.App": "1.1.1",
    "Amazon.Lambda.Core": "1.0.0*",
    "Amazon.Lambda.Serialization.Json": "1.0.1",
    "Amazon.Lambda.Tools": {
      "type": "build",
      "version": "1.3.0-preview1"
    },
    "Slight.Alexa.Core": "1.0.10-beta",
    "AlexaProjLib": "1.0.0-*"
  },

  "tools": {
    "Amazon.Lambda.Tools": "1.3.0-preview1"
  },

  "runtimes": {
    "win10-x64": { }  <--- Compiles, but fails at runtime
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

AlexaProjLib

{
  "version": "1.0.0-*",

  "dependencies": {
    "Google.Apis": "1.21.0",
    "Google.Apis.Core": "1.21.0",
    "Google.Apis.Oauth2.v2": "1.21.0.672",
    "Google.Apis.Sheets.v4": "1.21.0.798",
    "NETStandard.Library": "1.6.1"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}


推荐答案

我发现 JeffRCorp在AWS论坛上发布了有关类似问题的信息,他们的步骤也对我有用。

I found JeffRCorp posted on the AWS forums about having a similar issue, and their steps worked for me too.

首先,我编辑了 project.json 并将 Microsoft.NETCore.App 依赖项移至了 frameworks 部分(尽管我不确定这是否会有所作为)。我还删除了运行时部分。最终project.json:

First I edited project.json and moved the Microsoft.NETCore.App dependency into the frameworks section (although I'm not sure if this makes a difference). I also removed the runtimes section. Final project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
  },

  "dependencies": {
    "Amazon.Lambda.Core": "1.0.0*",
    "Amazon.Lambda.Serialization.Json": "1.0.1",
    "Amazon.Lambda.Tools": {
      "type": "build",
      "version": "1.3.0-preview1"
    },
    "Slight.Alexa.Core": "1.0.10-beta",
    "AlexaProjLib": "1.0.0-*"
  },

  "tools": {
    "Amazon.Lambda.Tools": "1.3.0-preview1"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50",
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.1"
        }
      }
    }
  }
}

然后我运行了 dotnet lambda软件包,该软件包在 bin中构建了一个.zip文件/Release/netcoreapp1.0 目录。通过AWS控制台将此文件上传到AWS Lambda,瞧!

I then ran dotnet lambda package which built a .zip file in the bin/Release/netcoreapp1.0 directory. Uploaded this to AWS Lambda via the AWS Console and voila!

这篇关于AWS Lambda和.NET Core-使用Linux运行时吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆