I made the RDS with this script by cdk.
It makes the user myname as admin, however where can I get the password?
And also, is there any way to set the default password by script?
const dbInstance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.mysql({
version: rds.MysqlEngineVersion.VER_8_0_19,
}),
vpc,
instanceIdentifier:`st-${targetEnv}-rds`,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
publiclyAccessible: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
databaseName:`stybot${targetEnv}`,
credentials: rds.Credentials.fromGeneratedSecret('myname')
});
CodePudding user response:
In your sample code, when you use:
credentials: rds.Credentials.fromGeneratedSecret('myname')
CDK will automatically create an AWS Secrets Manager secret and store it there. You can view the password generated by retrieving the secret.
If you want to specify your own password, you can use Credentials.fromPassword. The documentation recommends not to have the password directly exposed in your CDK code for security reasons. You can also use Credentials.fromSecret to read the value from a AWS Secrets Manager secret you have created separately.
