How to: Option Group for RDS in CDK

30 July 2020 — Written by Edwin
#CDK#AWS#Typescript#RDS

For an RDS MS SQL database I wanted to use the native S3 restore and backup option. It took me some time to figure out the correct syntax so this is how I created the option group.

Copy/Paste

    const optionGroupRDS = new rds.OptionGroup(this, 'optionGroup',{
      engine: rds.DatabaseInstanceEngine.SQL_SERVER_SE,
      configurations: [{
        name: 'SQLSERVER_BACKUP_RESTORE',
        settings:{'IAM_ROLE_ARN':'ARN:::of::backuprole'}
      }]
    })
    const instance = new rds.DatabaseInstance(this, 'mssql',{
      engine: rds.DatabaseInstanceEngine.SQL_SERVER_SE,
      vpc: VPCID,
      masterUsername: 'cdkuser',
      databaseName: '',
      optionGroup: optionGroupRDS
    })

How to read the docs

Under the RDS construct you can see optionGroup as a parameter:

RDS CDK Docs

optionGroup?🔹 IOptionGroup The option group to associate with the instance.

Click on IOptionGroup to see interface options and thats just plain confusing.

In this case you create a new OptionGroup Construct that implements the IOptionGroup. You find the details to an option group on the left under constructs in the RDS docs: Option Group

    const optionGroupRDS = new rds.OptionGroup(this, 'optionGroup',{
      //config here
    })

These are the parameters that are mandatory:

Name Type
configurations🔹 Array OptionConfiguration
engine🔹 IInstanceEngine

The engine IInstanceEngine is again the same that you used for your RDS instance already.

    const optionGroupRDS = new rds.OptionGroup(this, 'optionGroup',{
      engine: rds.DatabaseInstanceEngine.SQL_SERVER_SE,
    })

Lastly the configuration array: Configuration array

    const optionGroupRDS = new rds.OptionGroup(this, 'optionGroup',{
      engine: rds.DatabaseInstanceEngine.SQL_SERVER_SE,
      configurations: [{
        name: 'SQLSERVER_BACKUP_RESTORE',
        settings:{'IAM_ROLE_ARN':'ARN:::of::backuprole'}
      }]
    })

And you finished your option group.🚀

© 2020 Built with ❤️