aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.41k stars 3.8k forks source link

(aws-cdk/aws-cloudtrail): Support DynamoDB as a DataResourceType in CloudTrail #14886

Open Parker-Ledoux opened 3 years ago

Parker-Ledoux commented 3 years ago

About two months ago, AWS CloudTrail officially announced support for audit logging and monitoring of DynamoDb. More information about that here. Today the aws-cdk only supports S3 and Lambda as data resource types and it would be super useful to be able to use cdk to construct our CloudTrail trails for DynamoDB as well.


This is a :rocket: Feature Request

TheRealAmazonKendra commented 1 year ago

This is currently blocked by another issue. We will update here when it is unblocked and reopen @peterwoodworth's pr.

cowsandmilk commented 1 year ago

Is there an update on this?

issakr commented 1 year ago

any update please

scott-korin commented 1 year ago

Any update?

lurumad commented 1 year ago

Any update on this?

Is there any workaround at that moment?

peterwoodworth commented 1 year ago

We're still blocked on implementing l2 support. You'll need to use L1s, or implement escape hatches to use this feature in the meantime

holomekc commented 1 year ago

An example in Java via escape hatches.

final List<String> tableArns = dbStack.getTableArns();

final CfnTrail cfnTrail = (CfnTrail) trail.getNode().getDefaultChild();

final CfnTrail.DataResourceProperty dataResource =
        CfnTrail.DataResourceProperty.builder().type("AWS::DynamoDB::Table").values(tableArns).build();
final CfnTrail.EventSelectorProperty selector =
        CfnTrail.EventSelectorProperty.builder().dataResources(List.of(dataResource))
                .includeManagementEvents(false).readWriteType("All").build();

cfnTrail.setEventSelectors(List.of(selector));

Other languages regarding escape hatches here: https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html

eiva commented 8 months ago

Any progress on this?

matthiasbruns commented 8 months ago

same here - tried to setup cloudtrail with dynamo, but still no support

    trail := awscloudtrail.NewTrail(
        scope,
        jsii.String(fmt.Sprintf(trailName)),
        &awscloudtrail.TrailProps{
            TrailName:                  jsii.String(trailName),
            Bucket:                     trailBucket,
            IsMultiRegionTrail:         jsii.Bool(true),
            IncludeGlobalServiceEvents: jsii.Bool(true),
        },
    )

    trailDataSource := &awscloudtrail.CfnTrail_DataResourceProperty{
        Type: jsii.String("AWS::DynamoDB::Table"),
        Values: &[]*string{
            props.DB.TableArn(),
        },
    }

    trailDataSelector := awscloudtrail.CfnTrail_EventSelectorProperty{
        DataResources:           trailDataSource,
        IncludeManagementEvents: jsii.Bool(false),
        ReadWriteType:           jsii.String(string(awscloudtrail.ReadWriteType_WRITE_ONLY)),
    }

    trail.Node().DefaultChild().(awscloudtrail.CfnTrail).SetEventSelectors([]interface{}{trailDataSelector})

the version in Go, in the meantime

gshpychka commented 7 months ago

@peterwoodworth could you clarify what's blocking you? Seems straightforward to implement on the surface

peterwoodworth commented 7 months ago

Hey Glib, I'm not sure we can get into the specifics here, however I am still keeping tabs on this and will push to merge this feature once we're able to.

Just a heads up, I'm not with the CDK team anymore (however am still with Amazon). It was very pleasant working with you here 🙂

dparish commented 2 months ago

In case someone else needs this:

Here is how I was able to get this to work with Typescript and the CDK. Thank you to @holomekc for the inspiration on how to do this.

    const dynamoTrail = new Trail(this, 'some-trail', {
      trailName: 'some-trail',
    });

    const cfnTrail = dynamoTrail.node.defaultChild as CfnTrail;
    cfnTrail.eventSelectors = [
      {
        dataResources: [
          {
            type: 'AWS::DynamoDB::Table',
            values: [mytable.tableArn],
          },
        ],
        includeManagementEvents: false,
        readWriteType: 'All',
      },
    ];