Adrián Mouly
09/12/2021, 8:48 AMRoss Coundon
09/12/2021, 8:49 AMAdrián Mouly
09/12/2021, 8:49 AMAdrián Mouly
09/12/2021, 8:50 AMAdrián Mouly
09/12/2021, 8:50 AMAdrián Mouly
09/12/2021, 8:50 AMAdrián Mouly
09/12/2021, 8:50 AMAdrián Mouly
09/12/2021, 8:50 AMRoss Coundon
09/12/2021, 8:52 AMAdrián Mouly
09/12/2021, 8:53 AMAdrián Mouly
09/12/2021, 8:53 AMRoss Coundon
09/12/2021, 9:30 AMAdrián Mouly
09/12/2021, 9:32 AMAdrián Mouly
09/12/2021, 9:32 AMRoss Coundon
09/12/2021, 9:35 AMAdrián Mouly
09/12/2021, 9:36 AMAdrián Mouly
09/12/2021, 9:36 AMRoss Coundon
09/12/2021, 9:36 AMthdxr
09/12/2021, 12:00 PMAdrián Mouly
09/12/2021, 12:40 PMSeth Geoghegan
12/21/2021, 4:32 PMsst start --stage <my_username>
should create any stage specific resources (API GW, Lambda, etc) and the dev RDS instance if it doesn't already exist.
sst remove --stage <my_username>
should remove all stage specific resources, but leave the should remove any stage specific resources and leave the dev RDS instance untouched.
It's not clear to me how to apply the above discussion to this use case. This is what I currently have, which does not prevent removing the dev RDS instance when a user executes sst remove --stage <my_username>
import * as sst from "@serverless-stack/resources";
import * as ec2 from '@aws-cdk/aws-ec2';
import * as secretsManager from '@aws-cdk/aws-secretsmanager';
import * as ssm from'@aws-cdk/aws-ssm';
import * as rds from '@aws-cdk/aws-rds';
import { SecurityGroup } from '@aws-cdk/aws-ec2';
import { RemovalPolicy } from "@aws-cdk/core";
export default class DbStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// if a DB ARN already exists in this environment, don't create the DB
if (process.env.DB_ARN){
return
}
// always use "dev" database when running locally
const stage = process.env.IS_LOCAL ? "dev" : scope.stage
const vpc = ec2.Vpc.fromLookup(...);
// generate a secret to be used as credentials for our database
const databaseCredentialsSecret = new secretsManager.Secret(...);
// get the default security group
const defaultSecurityGroup = SecurityGroup.fromSecurityGroupId(...)
// configure and create the database
const rdsConfig = {...}
// create the instance
const rdsInstance = new rds.DatabaseInstance(this, `${stage}-instance`, rdsConfig);
// output generated secret name and ARN
this.addOutputs({
"Secret Name": databaseCredentialsSecret.secretName,
"Secret ARN": databaseCredentialsSecret.secretArn,
"Secret Full ARN": databaseCredentialsSecret.secretFullArn,
"RDS Endpoint": rdsInstance.dbInstanceEndpointAddress
});
}
}