I'm creating a QLDB Ledger as part of my stack. I would like to not have to supply a Ledger Name (otherwise I can't create multiple envs because of name clashes).
I also need to know the Ledger Name as an output / returned value from my stack because later some lambda functions need to know it to be able to use the QLDB SDK.
Using the following code, ledger.name is always undefined
import * as qldb from '@aws-cdk/aws-qldb';
const ledger = new qldb.CfnLedger(this, 'Ledger', {
deletionProtection,
permissionsMode: 'STANDARD',
});
console.log(ledger.name)
This kind of makes sense because it doesn't seem that the ledger gets its generated name until the Ledger is created in AWS (though it does seem to be derived from the stack).
FYI, once it is created and I know its name, searching for the name in the cdk.out
folder finds nothing, so I don't believe it is included in the CFN template.
For now, I am generating a unique name with CDK using the following code but I just wonder if there's a cleaner way.
const name = cdk.Names.uniqueId(ledger);
ledger.name = name;
EDIT
This code often produced a name that was longer than the 32 char limit for the ledger name so I also ran a regex on it to get the last part of the unique name.
const name = cdk.Names.uniqueId(ledger);
ledger.name = name;