If anyone needs to build an API on top of resourc...
# sst
s
If anyone needs to build an API on top of resources within an existing VPC (e.g. an RDS DB that is not serverless), this is how I did it with SST
Copy code
import DbStack from "./DbStack";
import * as ec2 from '@aws-cdk/aws-ec2';

export default function main(app) {

  // Set default props for all functions
  app.setDefaultFunctionProps((stack) => ({
    runtime: "python3.6",
    srcPath: "src",
    vpc: ec2.Vpc.fromLookup(stack, 'apiVpc', {
      vpcName: process.env.VPC_NAME,
    })
  }));

  // this stack creates an RDS DB within an existing VPC
  const dbStack = new DbStack(app,'db-stack');  

  
  app.addDefaultFunctionEnv({
    DB_URI: dbStack.databaseURI
  })

  // Create the HTTP API
  const api = new sst.Api(this, "Api", {
    defaultFunctionProps: {
      srcPath: "src",
    },
    routes: {
      "GET /notes": "list.main",
      "GET /notes/{id}": "get.main",
      "PUT /notes/{id}": "update.main",
    },
  });

}