Hi in the postgres example, if I understand it cor...
# help
m
Hi in the postgres example, if I understand it correctly this deploys a new database per stage right?
Copy code
const cluster = new rds.ServerlessCluster(this, "CounterDBCluster", {
      vpc,
      defaultDatabaseName,
      // Set the engine to Postgres
      engine: rds.DatabaseClusterEngine.AURORA_POSTGRESQL,
      parameterGroup: rds.ParameterGroup.fromParameterGroupName(
        this,
        "ParameterGroup",
        "default.aurora-postgresql10"
      ),
      // Optional, disable the instance from pausing after 5 minutes
      scaling: { autoPause: cdk.Duration.seconds(0) },
    });
What I've been trying to do is create 2 database outside, prod and dev and I've been trying to import it. I've done
Copy code
const vpc = ec2.Vpc.fromLookup(this, "VPC", {
     vpcId: "vpc-xxxxxxx",
    });

and 

rds.DatabaseInstance.fromDatabaseInstanceAttributes

as well as 

 rds.DatabaseCluster.fromClusterAttributes
I couldn't seem to make anything work
f
Hey @Michael James Munar, we are actually in the middle of updating the example to use the new
RDS
construct https://docs.serverless-stack.com/constructs/RDS#examples
It builds on top of CDK’s serverless cluster, but has built-in support for DB migrations.
Do you have to create the dbs outside and import them? Can you create them in ur SST app?
m
Not really, I just quite can't wrap my head around how to not create a new db per stage
Or I'm just misunderstanding what a cluster is
f
I see. The standard way of doing this would be, in pseudo code:
Copy code
if (stage === "dev" or "prod") {
  cluster = new sst.RDS(...);
}
else {
  cluster = import existing cluster created in "dev"
}
m
Copy code
cluster = rds.DatabaseCluster.fromClusterAttributes(this, "Database", {
      clusterIdentifier: "cluster-name",
      instanceEndpointAddress: "cluster-endpoint",
      engine: rds.DatabaseClusterEngine.AURORA_POSTGRESQL,
      port: 5432,
    });
and this is the way to import the cluster right?
f
yeah that looks right
m
Will give this a try, thanks Frank.