1 Answer
- Newest
- Most votes
- Most comments
1
This method worked well for creating RDS.
const cred = aws_rds.Credentials.fromGeneratedSecret('mysqlSecret2', {
secretName: 'mysql-secret2'
})
const rds = new aws_rds.DatabaseInstance(this, 'rds', {
vpc: new aws_ec2.Vpc(this, 'vpc'),
engine: aws_rds.DatabaseInstanceEngine.MARIADB,
instanceType: aws_ec2.InstanceType.of(aws_ec2.InstanceClass.T3, aws_ec2.InstanceSize.SMALL),
credentials: cred
})
new aws_lambda.Function(this, 'lambd2', {
environment: {
"SECRET_ARN": rds.secret!.secretArn
},
code: aws_lambda.Code.fromInline('print()'),
runtime: aws_lambda.Runtime.PYTHON_3_9,
handler: 'app.handler'
})
If you are not creating an RDS, using aws_secretsmanager.Secret instead of aws_rds.Credentials.fromGeneratedSecret worked.
const secret = new aws_secretsmanager.Secret(this, 'secret', {
secretName: 'mysql-secret',
generateSecretString: {
secretStringTemplate: JSON.stringify({ username: 'user' }),
generateStringKey: 'password',
},
})
new aws_lambda.Function(this, 'lambda', {
environment: {
"SECRET_ARN": secret.secretArn
},
code: aws_lambda.Code.fromInline('print()'),
runtime: aws_lambda.Runtime.PYTHON_3_9,
handler: 'app.handler'
})
I would be very happy if you could ACCEPTE ANSWER when you solve the problem😀😀😀
answered 2 years ago
Relevant content
- Accepted Answerasked 2 years ago
- asked 6 years ago
- Accepted Answerasked a month ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated a year ago
Thank you! it works for me.
In addition, when I create the secret (your second method) then pass into RDS, I got an error from CDK. Can't recall it.