Issue with Memory Setting for Serverless Function

Hi everyone,

I’m encountering an issue with setting memory limits for my serverless function on Vercel. I’ve configured the memory allocation in my vercel.json as follows:

json

Копировать код

{
  "functions": {
    "api/main_flow.py": {
      "memory": 128
    }
  },
  "routes": [
    {
      "src": "/.*",
      "dest": "api/main_flow.py"
    }
  ]
}

Despite this configuration, the memory setting doesn’t seem to apply. When I check the logs after deployment, I see that the memory is still set to 1024 MB, as shown in the attached screenshot.

Could someone help me understand why my memory configuration isn’t taking effect? Am I missing something in my setup or configuration?

Thanks in advance for any guidance!

Hi @greatpika, welcome to the Vercel community. Thanks for posting your question here.

To debug this issue, could you share the following details:

  • Has there been a successful deployment after applying the change to the vercel.json file?
  • Does the directory path matches with the function glob pattern specified?

Looking forward to hearing from you and getting this issue resolved for you.

Hi Anshuman,


Thank you for your response and for helping me troubleshoot this issue.

I must apologize – the configuration I shared in my first message did not successfully deploy. I’ve since updated my configuration to the following:

{
  "version": 2,
  "builds": [
    {
      "src": "main_flow.py",
      "use": "@vercel/python",
      "config": {
        "maxLambdaSize": "15mb",
        "memory": 128
      }
    }
  ],
  "routes": [
    {
      "src": "/.*",
      "dest": "main_flow.py"
    }
  ]
}

This configuration successfully deploys, but the result remains the same: the memory is still set to 1024 MB, as shown in the logs (attached screenshot).

For additional context, I’m attaching a screenshot of my project structure as well. Could you please let me know if there’s something else I should adjust or check in this configuration?

Looking forward to your guidance, and thanks again for your support!

1 Like

Hi @greatpika, thanks for the detailed comment. It helped me research the issue better.

I’ve three suggestions for you:

  1. Use the functions config option instead of the the builds config. This is the recommended approach in the docs and makes research/debugging easier.
  2. Use the rewrites config option instead of the routes to send all requests to your main file.
  3. Keep the vercel.json at the root of the project instead of the /api folder.

This configuration and directory structure works as you intend, please try it out:

Output:

I hope this was helpful. Let me know if it works for your. Feel free to ask more questions.

1 Like