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.

Dynamic Connection Settings

See original GitHub issue

Problem

When connecting to AWS RDS using IAM authentication, a token is generated that is used as the password for new connections. This token expires after 15 minutes. After that, the token can no longer be used to create new connections.

Existing connections are still valid.

With Prisma, it seems like connection settings including the password must be static, and can not be altered after the PrismaClient has been created.

Suggested solution

With Knex, the connection settings do not need to be static. An async function can also be passed in that will provide the connection settings when called. This can include an expiration checker that is called when a new connection is created. If the settings are expired, the connection settings provider can be called again to update the connection settings.

This should not close existing connections in the pool. It should only affect the settings of new connections that are created.

It might look like this in Prisma.

export prisma = new PrismaClient({dataSources: { db: generateConnectionSettings }})

async function generateConnectionSettings(){
    const token = await getIAMToken(auth)
    const expiresAt = Date.now() + 840000 // Expires in 14 minutes 
    return {
       url: <connection string with generated token>,
       expirationChecker: () => {
          return expiresAt <= Date.now()
       }
   }
}

Alternatives

We are currently creating a new PrismaClient for every http request, but this is only possible because we have an internal only tool with very low request volume. This is very wasteful.

Additional context

https://github.com/prisma/prisma/discussions/4147

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:30
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

16reactions
memarkcommented, May 6, 2022

Any update on this? Still highly needed.

15reactions
antoine-couloncommented, Jun 17, 2022

It would be great to have this feature which seems to be already implemented in other Node.js ORMs. We currently have the same issues working with Prisma and PostgreSQL on Azure with @azure/identity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Static vs. dynamic IP addresses - Google Fiber Help
Google Fiber provides two options. How to get a dynamic IP address. Use advanced settings for your network to configure dynamic DNS. When...
Read more >
Creating and Using Dynamic Connections - Logi Analytics
A dynamic connection is a group of connection properties that can be used to override the original data source connections in a catalog....
Read more >
Static and Dynamic IP Addresses - WatchGuard Technologies
Dynamic Host Configuration Protocol (DHCP) is an Internet protocol that computers on a network use to get IP addresses and other information such...
Read more >
Static vs. Dynamic IP Addresses: What's the Difference? | Avast
Static vs. Dynamic IP Addresses. The Internet and your network are linked together with Internet Protocol (IP) addresses.
Read more >
Dynamic Connections for Models - Looker Community
Is there a way to dynamically change a connection in a model so that we can take advantage of Snowflake secure views.
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