Search code examples
aws-lambda.net-6.0

AWS Lambda - Could not determine an appropriate location for storing user secrets


We published our Net6 web API to an AWS Lambda but when we make a request it fails.

Status: 502 Bad Gateway

{
  "message": "Internal server error"
}

We get this on CloudWatch:

  2022-09-01T10:42:07.359-03:00 Unhandled exception. System.InvalidOperationException: Could not determine an appropriate location for storing user secrets. Set the DOTNET_USER_SECRETS_FALLBACK_DIR environment variable to a folder where user secrets should be stored.
  2022-09-01T10:42:07.359-03:00 at Program.<Main>$(String[] args) in C:\repository\codetria\palier\backend\backend-palier\Src\Presentation\Palier.API\Program.cs:line 12

Program.cs - line 12:

var builder = WebApplication.CreateBuilder(args);

It's not the first time that we published an API in this way and we've never had to set this environment variable.

This's the command we use to publish the API

dotnet lambda deploy-function lambda-name `
  --region us-east-2 `
  --project-location $API_LOCATION `
  --profile profile `
  --function-runtime dotnet6

Any thoughts?


Solution

  • I just a similar error trying to deploy to AWS, for me it turned out to be that I a UserSecretsId in my csproj by mistake. The error went away when I remove this value. Here is a reference on how to use UserSecrets in deployed environments https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&tabs=windows

    enter image description here