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.51k stars 3.85k forks source link

aws-dynamodb: Unable to set resource policy on DDB streams #31229

Open grbinho opened 2 weeks ago

grbinho commented 2 weeks ago

Describe the bug

There does not seem to be a way to set resource policy on DynamoDB stream through L2 constructs. addReplica method does not allow setting stream resource policy nor is it available in TableOptionsV2. We can only set resource policy for the table itself.

Regression Issue

Last Known Working CDK Version

No response

Expected Behavior

I expect to be able to set a resource policy for DDB streams via L2 constructs.

Current Behavior

Currently it's is not possible to set resource policy for DDB streams via L2 constructs.

Reproduction Steps

Try creating DynamoDB table and set resource policy for DDB streams (not table).

Possible Solution

Expose streamResourcePolicy in TableOptionsV2.

Additional Information/Context

I'm currently setting the policy by getting the L1 construct and resolving the replicas property.

 const cfnTable = table.node.defaultChild as CfnGlobalTable
      if (cfnTable && props.streamResourcePolicy) {
        // At this stage, cfnTable.replicas is a Lazy.any() and needs to be resolved for us to be able to set new properties.
        const replicas = Stack.of(this).resolve(cfnTable.replicas) as CfnGlobalTable.ReplicaSpecificationProperty[]
        if (Array.isArray(replicas)) {
          cfnTable.replicas = replicas.map(replica => {
            return {
              ...replica,
              replicaStreamSpecification: {
                resourcePolicy: {
                  policyDocument: props.streamResourcePolicy,
                },
              },
            }
          })
        }
      }

CDK CLI Version

2.154.1

Framework Version

No response

Node.js Version

v20.15.0

OS

MacOS Sonoma 14.5 (23F79)

Language

TypeScript

Language Version

5.4.5

Other information

No response

LeeroyHannigan commented 2 weeks ago

Streams is not yet implemented as an L2 construct. I will take this as an action item.

ashishdhingra commented 2 weeks ago

Appears to be a feature request.