Reputation: 147
I have an accessor class that pulls required data from a Json file. The path seems ok when I tested a console application project in .Net FrameWork.
But when using the Lambda in Aws Lex there is an error only when I try to run this Json accessor function (even when not using the data that was returned whatsoever).
It seems to me like the relative path that was working locally is diffrent when the Lambda is uploaded to AWS.
This it the accessor class which works locally in a cosole application in a .NetFramwork project. Both the Json file and the DataAccess class are in a Folder that have the name "Accessors":
public class DataAccess
{
public static List<string> access(int maxPrice, string Shape)
{
List<string> diList = new List<string>();
string filepath = "../../../Accessors/DiData.json";
string result = string.Empty;
string str = string.Empty;
using (StreamReader r = new StreamReader(filepath))
{
var json = r.ReadToEnd();
JObject jObject = JObject.Parse(json);
JToken jUser = jObject["data"]["dResult"][0]["dID"];
var searchResults = from r1 in jObject["data"]["dResult"]
where r1["shape"].ToString() == Shape && r1["price"].Value<System.Int32>() <= maxPrice
select r1;
foreach (var r1 in searchResults)
{
diList.Add(r1["dID"].ToString());
}
}
return diList;
}
}
Here I am calling this function:
List<string>jsonDataList= Accessors.DataAccess.access(600, "Round");
This call alone brings an error in Amazon Lex after using this Lambda as code hook.
Upvotes: 0
Views: 2331
Reputation: 3177
It looks like you are loading the JSON file from your dev/source folder layout. In Lambda you are sending a zip version of the folder structure created from the dotnet publish
command on the Lambda project. This is your compiled project bits.
Make sure DiData.json is configured to be copied to the build output folder and then you can load the file relative from the root of the publish folder to where the DiData.json file gets copied to in the publish folder.
Upvotes: 1