skip to Main Content

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


  1. I think you have todo it the other way around:

    insertionLambda.addDependsOn(cfnRawTable);

    Login or Signup to reply.
  2.  Use CDK’s Construct dependencies instead:

    cfnRawTable.node.addDependency(insertionLambda);
    

    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.

    Login or Signup to reply.
  3. If you make any reference to the resource from another, it will automatically add the dependency.

    As an example, adding the cfnRawTable.attrArn to the properties argument for CustomResource will cause the dependency relationship to be created.

    cdk.CustomResource(
      ..., 
      {
        properties: {'tablearn': cfnRawTable.attrArn}
      },
    )
    

    Alternatively, you can declare a dependency without needing to make any reference using .node.addDependency

    insertionLambda.node.addDependency(CfnRawTable)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search