AWS Lambda C#CloudFormation配置

时间:2017-05-23 15:58:32

标签: c# amazon-web-services aws-lambda amazon-cloudformation

我尝试使用C#创建一个简单的lambda函数,并使用CloudFoundation

进行部署

我有这个配置:

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "My PoC.",

    "Resources": {
        "MyPocLambda": {
            "Type": "AWS::Lambda::Function",
            "Description": "Just a lambda for a Hello world",
            "Properties": {
                "Runtime": "dotnetcore1.0",
                "FunctionName": "HandleGet",
                "Handler": "MyPoc::MyPoc.Function::HandleGet",
                "MemorySize": 256,
                "Timeout": 30,
                "Role": { "Fn::GetAtt": ["LambdaExecutionRole", "Arn"]},
                "Code": {
                    "ZipFile": "./bin/Release/netcoreapp1.0/MyPoc.zip"
                }
            }
        },
        "LambdaExecutionRole": {
          "Type": "AWS::IAM::Role",
          "Properties": {
            "AssumeRolePolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [{
                "Effect": "Allow",
                "Principal": { "Service": ["lambda.amazonaws.com"] },
                "Action": ["sts:AssumeRole"]
              }]
            },
            "ManagedPolicyArns": ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"]
          }
        }
    }
}

由于代码属性,部署无效。我应该在C#中用它做什么?

由于

1 个答案:

答案 0 :(得分:0)

符号。我很相信你不能使用这个过程来使用Code的zipfile属性来部署dotnetcore1.0或除node.js之外的任何运行时。我知道有两个选项。

  1. 使用Visual Studio 2015 SP3 / 2017中提供的dotnet cli进行部署。这将是:
  2. dotnet lambda deploy-function

    使用此cli调用时,您应该确保项目中的aws-lambda-tools-defaults.json文件设置类似于以下内容:

    { 
      "Information" : [ some information ],
      "profile":"YourDefaultProfile",
      "region" : "us-east-1",
      "configuration" : "Release",
      "framework" : "netcoreapp1.0",
      "function-runtime":"dotnetcore1.0",
      "function-memory-size" : 256,
      "function-timeout" : 30,
      "function-handler" : "AWSLambdas::AWSLambdas.Function::FunctionHandler"
    }
    

    这将在您拥有项目文件和资源的文件夹中执行;不是bin文件夹。您还可以指定其他参数(如角色等),以缩短超出此默认cli调用以进行部署的提示。此次通话还有一条cli帮助热线:

    dotnet lambda help

    1. 有能力使用SAM部署Lambda;无服务器应用程序模型于2016年底前推出。示例CloudFormation部署在AWS网站上:
    2. http://docs.aws.amazon.com/lambda/latest/dg/deploying-lambda-apps.html

      祝你好运!