question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query engine binary not found while deploying Next.js App to AWS using Serverless Framework

See original GitHub issue

Bug description

I’m using the serverless component for next.js to deploy my app to AWS. Unfortunately, things didn’t go smoothly as expected. While testing the cloudfront distribution will try to execute a query from the nextjs api routes through the lambda.

The cloudfront will throw the following error:

503 ERROR
The request could not be satisfied.
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
Generated by cloudfront (CloudFront)
Request ID: 63bKSGDPOK1vnJwOxPuvkR9dTEsqgqBFpeXpx3KKCiGMAeXfPtBt4w==

Looking inside the lambda logs I found out that the query engine binary was not found and the database couldn’t be reached. here’s the error thrown by the lambda:

        "stack": [
            "Error: Query engine binary for current platform \"rhel-openssl-1.0.x\" could not be found.",
            "This probably happens, because you built Prisma Client on a different platform.",
            "(Prisma Client looked in \"/query-engine-rhel-openssl-1.0.x\")",
            "",
            "Searched Locations:",
            "",
            "  /.prisma/client",
            "  /home/user/Documents/workspace/project/node_modules/@prisma/client",
            "  /",
            "  /var/task/node_modules/.prisma/client",
            "  /var/task",
            "  /var/task/node_modules/.prisma/client",
            "",
            "You already added the platforms \"native\", \"rhel-openssl-1.0.x\" to the \"generator\" block",
            "in the \"schema.prisma\" file as described in https://pris.ly/d/client-generator,",
            "but something went wrong. That's suboptimal.",
            "",
            "Please create an issue at https://github.com/prisma/prisma-client-js/issues/new",
            "    at PrismaClientFetcher.request (/var/task/pages/api/auth/[...nextauth].js:155205:15)"
        ]

What I tried

Following https://github.com/prisma/docs/issues/841 I tried to copy the relevant files during the deployment. I tried also to change the default location of the binary following https://github.com/serverless-nextjs/serverless-next.js/issues/843 but nothing worked.

How to reproduce

Steps to reproduce the behavior:

  1. Create a nextjs App with next-auth and prisma for passwordless login
  2. Deploy to aws using serverless. The exact component is '@sls-next/serverless-component@1.18.0'
  3. Test the login with the production environment
  4. See error

Expected behavior

The query engine binary will be correctly generated and be able to query the database without errors.

Prisma information

I think the following is the only relative information for the issue.

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

Environment & setup

  • OS: Linux Mint 20 Cinnamon
  • Database: PostgreSQL
  • Node.js version: v12.15.0
  • Prisma: 2.14.0
@prisma/cli          : 2.14.0
@prisma/client       : 2.14.0
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Studio               : 0.332.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
endlessdevcommented, May 24, 2021

@janpio Sorry for my late reply 🥲 Here are my serverless.yml codes below. It referenced #5392 (comment), -> https://github.com/millsp/prisma-serverless-nextjs

It has a difference from the build command, here some script meaning build process in my case. “clean”: “rm -rf dist”, “build”: “yarn clean && yarn generate && next build”, “generate”: “yarn generate:prisma && yarn generate:nexus”, “generate:prisma”: “prisma generate”, “generate:nexus”: “ts-node --transpile-only -P tsconfig.nexus.json ./graphql/schema/index.ts”,

Additionally in my cases, GraphQL Apollo server + Nexus + Prisma in Next.js (e.g. /api/graphql.ts)

goodocstore:
  component: "@sls-next/serverless-component"
  inputs:
    runtime: "nodejs14.x"
    timeout: 30
    memory: 2048
    minifyHandlers: true
    useServerlessTraceTarget: true
    build:
      cmd: 'yarn'
      args: ['build']
      postBuildCommands:
        - PDIR=node_modules/.prisma/client/;
          LDIR=.serverless_nextjs/api-lambda/;
          if [ "$(ls -A $LDIR)" ]; then
          mkdir -p $LDIR$PDIR;
          cp "$PDIR"query-engine-rhel-* $LDIR$PDIR;
          cp "$PDIR"schema.prisma $LDIR$PDIR;
          fi;
        - PDIR=node_modules/.prisma/client/;
          LDIR=.serverless_nextjs/default-lambda/;
          if [ "$(ls -A $LDIR)" ]; then
          mkdir -p $LDIR$PDIR;
          cp "$PDIR"query-engine-rhel-* $LDIR$PDIR;
          cp "$PDIR"schema.prisma $LDIR$PDIR;
          fi;
    bucketName: 'goodocstore-assets'
    bucketRegion: 'ap-northeast-2'
    cloudfront:
      distributionId: MASKING
    name:
      defaultLambda: 'goodocstore-lambda'
      apiLambda: 'goodocstore-api-lambda'
1reaction
millspcommented, May 10, 2021

This can be solved by adding a script that triggers before upload. I have set a template up for prisma + serverless-next.js which adds a postBuildCommands (serverless.yml) script to do just that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploying to AWS Lambda - Prisma
In this guide, you will set up and deploy a serverless Node.js REST API to AWS Lambda using the Serverless Framework. AWS Lambda...
Read more >
Query your AWS database from your serverless application
This post is intended for AWS database users who have no experience with AWS Lambda, Amazon API Gateway, or AWS CloudFormation, and limited ......
Read more >
Deploying a Prisma Client Application with the ... - YouTube
The Serverless architecture provides a way to deploy applications without the burden of managing servers. In this live stream, ...
Read more >
The State of Serverless | Datadog
In 2020, we reported that half of Datadog's customers using AWS had adopted Lambda to run ... fueled by serverless-oriented frameworks like Next.js....
Read more >
Troubleshooting Node.js Deploys - Heroku Dev Center
Setting the HTTP_PROXY or HTTPS_PROXY environment variables in the app's build will cause these types of failures. If the build or app does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found