Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secretArn and clusterArn undefined AWS RDS, Next.js, Drizzle #1293

Open
lxhan opened this issue Oct 16, 2024 · 3 comments · May be fixed by #1263
Open

secretArn and clusterArn undefined AWS RDS, Next.js, Drizzle #1293

lxhan opened this issue Oct 16, 2024 · 3 comments · May be fixed by #1263

Comments

@lxhan
Copy link

lxhan commented Oct 16, 2024

Using AWS RDS, Next.js, Drizzle and getting this error when trying to do migration or open drizzle studio:

image image image

Everything deployed with no errors, just can't get ARN

Originally posted by @lxhan in #623 (comment)

@nhamilton1
Copy link
Contributor

What version of sst are you on? 3.1.70 and after uses RDS Postgres instead of aurora. You would have to change it to new sst.aws.Postgres.v1 to use aurora.

https://sst.dev/docs/component/aws/postgres-v1/

@ndaba1 ndaba1 linked a pull request Oct 17, 2024 that will close this issue
@lxhan
Copy link
Author

lxhan commented Oct 17, 2024

What version of sst are you on? 3.1.70 and after uses RDS Postgres instead of aurora. You would have to change it to new sst.aws.Postgres.v1 to use aurora.

https://sst.dev/docs/component/aws/postgres-v1/

I'm on sst version 3.2.26 and following this guide https://sst.dev/docs/start/aws/drizzle and this one from drizzle https://orm.drizzle.team/docs/connect-aws-data-api-pg.
So this part:

secretArn: Resource.MyPostgres.secretArn,
resourceArn: Resource.MyPostgres.clusterArn,

is for Aurora only? What should I do if I want to use RDS?

@nhamilton1
Copy link
Contributor

nhamilton1 commented Oct 17, 2024

The drizzle docs for this have not been updated yet and it's showing the old way of doing it. The new way would look something like this:

// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
import { Resource } from "sst";

export default defineConfig({
  dialect: "postgresql",
  dbCredentials: {
    user: Resource.MyDatabase.username,
    password: Resource.MyDatabase.password,
    host: Resource.MyDatabase.host,
    port: Resource.MyDatabase.port,
    database: Resource.MyDatabase.database,
  },
  schema: ["./src/**/*.sql.ts"],
  out: "../../migrations",
});
// sst.config.ts
/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
  app(input) {
    return {
      name: "project-name-here",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    const vpc = new sst.aws.Vpc("MyVpc", {
      bastion: true, // enable this if you want to use sst tunnel to connect to the database from your local machine
    });

    const database = new sst.aws.Postgres("MyDatabase", {
      vpc,
    });

    new sst.aws.Nextjs("MyWeb", {
      vpc,
      link: [database],
    });
  },
});
import { Resource } from "sst";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

const client = new Pool({
  user: Resource.MyDatabase.username,
  password: Resource.MyDatabase.password,
  database: Resource.MyDatabase.database,
  host: Resource.MyDatabase.host,
  port: Resource.MyDatabase.port,
});

export const db = drizzle(client, {
  logger:
    process.env.DRIZZLE_LOG === "true"
      ? {
          logQuery(query, params) {
            console.log("query:", query);
            console.log("params:", params);
          },
        }
      : undefined,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants