My colleagues and I were trying to deploy our .NET 6.0 API to an AWS Lambda the other day. The code deployed successfully and everything looked good until you actually try to hit the endpoints.
We were greeted with the following error message:
Error: .NET binaries for Lambda function are not correctly installed in the /var/task directory of the image when the image was built. The /var/task directory is missing the required .deps.json file.
We poured through stack overflow and some other sites that popped up on Google.
Here is one that we tried but had no effect on. Basically making sure our project files had this in them:
<PropertyGroup>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
</PropertyGroup>
We had two project files in our solution and one was missing the above config. We thought for sure this would solve the problem but alas we still had the issue.
We also have a shared library that was built in-house but was running a different version of .NET. Surely that was the issue. But again we upgraded the .NET version in that shared library and rebuilt and redeployed but again no luck in moving past this error.
The strangest thing is we downloaded the package from Lambda and there was no /var/task directory in the package. We downloaded other packages from other working Lambdas and they didn’t have that directory. This led me to believe the error message was misdirecting us. I find this to be the case of many weird error messages in AWS. They rarely give you the right error message.
Then we looked back at GIT commits. And I saw that in one commit I had renamed the project of the API to better reflect that it was an API for the convenience of others.
That was the problem!
Seems that in doing so the project name and namespace were in conflict and this caused the Lambda to not find the files it needed. We reverted the project back to the original name and deployed and the API worked as expected.
The lesson learned is to get your names correct early in the process. I suck at naming projects and usually leave that up to others. In this situation, I should have just left it alone.
What is a deps.json file?
According to Microsoft, a deps.json file is a JSON file that lists the dependencies of your library or application. If you are using .Net 6 and build your solution it should be producing a deps.json file.
The file should be located in the bin/debug folder of your solution.
If you are using the AWS Mock Lambda testing tool you can run into this same issue if for some reason your local project isn’t producing this file. For some of our developers, we added the following code that was missing to their launchsettings.json file under Properties.
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
}
This code should be added to the “profiles” array in the file. Once we had that added to the launchsettings.json file the AWS Mock Lambda testing tool was available and after building the project it seemed the project was properly getting the deps.json file created.
One thought on “AWS Lambda issue missing the required .deps.json file”