seems like `this` isn't accepted as a construct
# sst
t
seems like
this
isn't accepted as a construct
f
Are you getting this error when you do
new rds.DatabaseInstance(this, …)
? Can you provide more context?
I had a super basic setup working from before
Copy code
import * as cdk from "@aws-cdk/core";
import * as ec2 from "@aws-cdk/aws-ec2";
import * as rds from "@aws-cdk/aws-rds";

import * as sst from "@serverless-stack/resources";

class MySampleStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // Create a VPC
    const vpc = new ec2.Vpc(this, "Vpc", {
      natGateways: 1,
    });

    // Create RDS
    const instance = new rds.DatabaseInstance(this, 'Instance', {
      engine: rds.DatabaseInstanceEngine.mysql({
        version: rds.MysqlEngineVersion.VER_8_0_19,
      }),
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.SMALL),
      defaultDatabaseName: 'default',
      vpc,
      vpcSubnets: {
        subnetType: ec2.SubnetType.PRIVATE
      }
    });

    new cdk.CfnOutput(this, "DBAddress", {
      value: instance.instanceEndpoint.socketAddress,
    });
  }
}
Not sure if it’s relevant to what are trying to put together
t
yeah this is what I have but let me try again
the following example doesn't work
Copy code
export default class Stack extends sst.Stack {
  constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
    super(scope, id, props)

    const vpc = new ec2.Vpc(this, "nori")
    const cluster = new rds.ServerlessCluster(this, "Postgres", {
      vpc,
      engine: rds.DatabaseClusterEngine.AURORA_POSTGRESQL,
      defaultDatabaseName: "nori",
    })
}
Copy code
lib/stack.ts:59:47 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'Stack' is not assignable to type 'Construct'.
    Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.

59     const cluster = new rds.ServerlessCluster(this, "Postgres", {
                                                 ~~~~
oh updating everything to latest maybe fixed it, trying it again
f
hmm.. I haven’t tried this with typescript. Let me know if it works for you.
t
Yep all set - also found out serverless pg can't be accessed publicly so I'm going to continue to use a local pg and swap to serverless just for deployment
f
But a local pg is probably easier if that’s the main thing inside a vpc