将参数传递给AWS Lambda函数

Ron*_*ing 3 c# lambda amazon-web-services aws-lambda

我有一个Lambda函数,它假设需要3个参数

public async Task<string> FunctionHandler(string pName, string dictName, ILambdaContext context)
{
//code...
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual Studio 2015,我将其发布到AWS环境,我在示例输入框中放入什么来调用此函数? 在此输入图像描述

Zax*_*xon 7

就个人而言,我没有在Lambda入口点试验过异步任务,因此无法对此进行评论.

但是,另一种方法是将Lambda函数入口点更改为:

public async Task<string> FunctionHandler(JObject input, ILambdaContext context)
Run Code Online (Sandbox Code Playgroud)

然后将两个变量拉出来,如下所示:

string dictName = input["dictName"].ToString();
string pName = input["pName"].ToString();
Run Code Online (Sandbox Code Playgroud)

然后在AWS Web Console中输入:

{
  "dictName":"hello",
  "pName":"kitty"
}
Run Code Online (Sandbox Code Playgroud)

或者,可以使用JObject值并使用它,如以下示例代码所示:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace SimpleJsonTest
{
    [TestClass]
    public class JsonObjectTests
    {
        [TestMethod]
        public void ForgiveThisRunOnJsonTestJustShakeYourHeadSayUgghhhAndMoveOn()
        {
            //Need better names than dictName and pName.  Kept it as it is a good approximation of software potty talk.
            string json = "{\"dictName\":\"hello\",\"pName\":\"kitty\"}";

            JObject jsonObject = JObject.Parse(json);

            //Example Zero
            string dictName = jsonObject["dictName"].ToString();
            string pName = jsonObject["pName"].ToString();

            Assert.AreEqual("hello", dictName);
            Assert.AreEqual("kitty", pName);

            //Example One
            MeaningfulName exampleOne = jsonObject.ToObject<MeaningfulName>();

            Assert.AreEqual("hello", exampleOne.DictName);
            Assert.AreEqual("kitty", exampleOne.PName);

            //Example Two (or could just pass in json from above)
            MeaningfulName exampleTwo = JsonConvert.DeserializeObject<MeaningfulName>(jsonObject.ToString());

            Assert.AreEqual("hello", exampleTwo.DictName);
            Assert.AreEqual("kitty", exampleTwo.PName);
        }
    }
    public class MeaningfulName
    {
        public string PName { get; set; }

        [JsonProperty("dictName")] //Change this to suit your needs, or leave it off
        public string DictName { get; set; }
    }

}
Run Code Online (Sandbox Code Playgroud)

关键是我不知道您是否可以在AWS Lambda中拥有两个输入变量.赔率是你不能.除此之外,如果你坚持使用json字符串或对象传递一个需要的多个变量,这可能是最好的.