Drago
Drago

Reputation: 58

Create a documentDB cluster in an aws-cdk TS file, and put it as a source of event with EventSourceMapping

I have a cdk (with the 2.61 version) application with CRUD Lambdas, a document DB cluster and an appsync api. I have to register in the same documentDB database the stream events that come from the CRUD operations the lambdas are doing. I enabled the stream events from the documentDB database but now i've got to configure the cluster to be a source of events for the lambda which will take these streams and register its. The construct EventSource for the lambda lib doesn't have a DocumentDB option so i'm using EventSourceMapping which, if i understood it well, allow to use any aws service as a source of event.

const lambdaRecordChangeStreams = new lambda.Function(this, `lambda-record_change_stream`, {
      code: lambda.Code.fromAsset(
        path.join(__dirname, '../backend/controllers/lambda-record_change_stream'),
      ),
      functionName: `lambda-record_change_stream`,
      layers: [mongooseLayer],
    }); 

const clusterStreamEventSource = new lambda.EventSourceMapping(this, `stream_event_source`,     {
       eventSourceArn: `arn:aws:rds:${region}:${env?.account}:cluster:${cluster.clusterIdentifier}`,
        target: lambdaRecordChangeStreams,
      },
    );

When i'm trying to deploy it, i've got the error : "Invalid request provided: Invalid parameters: databaseName, documentDBEventSourceConfig".

I saw that in the cdk documentation there was an object : "CfnEventSourceMapping" with a way to configure a cluster docdb as event source with in the props, the property DocumentDbEventSourceConfig, but when i try to implement it, i've got an error that the property doesn't exist. So i'm now i'm stuck.

If you could help me that would be great !

Upvotes: 2

Views: 1187

Answers (1)

fedonev
fedonev

Reputation: 25739

Looks like the L1 CfnEventSourceMapping construct is your only option at this time. See the documentDbEventSourceConfig prop.

Also see the Lambda docs for info on prerequisites and permissions. The DocumentDB docs lists additional considerations.


⚠️ Update the CDK to the latest version. Your CDK v2.61 was published in January, a month before Lambda support for DocumentDB change streams as an event source was announced.

Upvotes: 2

Related Questions