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

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

问题描述

我正在用 C# (.NET Core) 编写 Alexa 技能,以便从 AWS Lambda 函数(在 Amazon Linux 上运行)运行.当我编译项目 (dotnet publish) 时,出现错误:

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恢复
  2. 该项目未列出win10-x64、win81-x64、运行时"部分中的 win8-x64、win7-x64'.
  3. 您可能正在尝试发布一个不受支持的库.使用 dotnet 包分发库.

如果我指定一个 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 时,为什么它需要 Windows 运行时?我觉得我遗漏了一些明显的东西,当有人向我指出问题时,我会很高兴地面对手掌.

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/Release/netcoreapp1.0 目录中构建了一个 .zip 文件.通过 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天全站免登陆