Search code examples
amazon-web-servicesaws-lambda.net-6.0

AWS Lambda - Unable to access the files and folder from lambda layer


I have a lambda function written in .NET 6 to which I have attached a lambda layer which is a zip file with many JSON files inside different folders in it.

I want to read each JSON file in my lambda function.

When I do this I get an error saying Could not find a part of the path '/var/task/geojson-files/UK.json':

var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "geojson-files", "UK.json");
var geojson = await File.ReadAllTextAsync(filePath);

I also tried /opt/geojson-files/UK.json. But still unable to read the file.

Is there any way to read the file in a lambda function from a lambda layer?


Solution

  • Thanks to @jarmod for his suggestion in the comments to enumerate the contents of /opt

    I iterated over the /opt folder and could get the root cause of my problem i.e. unable to read files from the lambda layer.

    I zipped the contents of geojson-files from inside that folder. So when I enumerated /opt, I could directly see /opt/UK.json file. So then I zipped the geojson-files folder and now I can see /opt/geojson-files/UK.json file.