I have the following problem that i cannot add dependsOn on a cfnResource for a CustomResource
const cfnRawTable = new timestream.CfnTable(this, 'MyCfnTableRaw', {
databaseName: dbName,
// the properties below are optional
magneticStoreWriteProperties: {
enableMagneticStoreWrites: true,
},
retentionProperties: {
magneticStoreRetentionPeriodInDays: '1825',
memoryStoreRetentionPeriodInHours: '8640',
},
tableName: rawtable,
})
let insertionLambda = new cdk.CustomResource(this, 'insertionlambda', {
serviceToken:
'arn:aws:lambda:' +
cdk.Fn.ref('region') +
'738234497474:function:timestreaminsertion-' +
cdk.Fn.ref('env'),
})
cfnRawTable.addDependsOn(insertionLambda)
I get the error Argument of type 'CustomResource' is not assignable to parameter of type 'CfnResource'
3
Answers
I think you have todo it the other way around:
insertionLambda.addDependsOn(cfnRawTable);
Use CDK’s Construct dependencies instead:
addDependsOn
is a low-level CloudFormation feature that is only available in L1 CloudFormation resources. The high-level.node.addDependency
is available with all Constructs.In this case, though, it does seem from the naming that your insertion lambda depends on the table, not the other way around, like @Martin Muller pointed out. You can still use the above, just swap them around. This guess an totally be incorrect, of course, maybe your lambda is not inserting into this particular table.
If you make any reference to the resource from another, it will automatically add the dependency.
As an example, adding the
cfnRawTable.attrArn
to theproperties
argument forCustomResource
will cause the dependency relationship to be created.Alternatively, you can declare a dependency without needing to make any reference using
.node.addDependency