Skip to content

Commit

Permalink
feat(kinesis): support stream consumers (#32087)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes #32050

### Reason for this change

Support Enhanced fan-out consumers via `AWS::Kinesis::StreamConsumer` and facilitate cross-account stream consumption via Lambda

### Description of changes



- introduce `StreamConsumer` construct to model `AWS::Kinesis::StreamConsumer`
  - introduce `addToResourcePolicy` to enable creating/configuring a resource policy for the consumer
  - introduce `grant` and `grantRead` for granting permissions
  - leverage `iam.Grant.addToPrincipalOrResource` in `grant` to be able to use `grant` methods cross environments to update the grantee's iam policy and the consumer's resource policy as needed
- update `ResourcePolicy` to support both `Stream` and `StreamConsumer`
- update `Stream`'s `grant` to leverage `iam.Grant.addToPrincipalOrResource` for cross-environment support
- introduce `KinesisConsumerEventSource` to `lambda-event-sources` for use with the newly introduced `StreamConsumer`

#### Useful links
- https://docs.aws.amazon.com/streams/latest/dev/enhanced-consumers.html
- https://aws.amazon.com/blogs/big-data/invoke-aws-lambda-functions-from-cross-account-amazon-kinesis-data-streams/

### Description of how you validated changes

unit and integration tests

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
humanzz authored Feb 18, 2025
1 parent 8eeb8e4 commit f4453c7
Show file tree
Hide file tree
Showing 46 changed files with 4,163 additions and 47 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"Resources": {
"CrossAccountRoleFACE29D1": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::234567890123:root"
]
]
}
}
}
],
"Version": "2012-10-17"
},
"RoleName": "stream-cross-account-consumer-role"
}
},
"CrossAccountRoleDefaultPolicy212A317F": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"kinesis:DescribeStream",
"kinesis:DescribeStreamConsumer",
"kinesis:DescribeStreamSummary",
"kinesis:GetRecords",
"kinesis:GetShardIterator",
"kinesis:ListShards",
"kinesis:ListStreams",
"kinesis:PutRecord",
"kinesis:PutRecords",
"kinesis:SubscribeToShard"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":kinesis:test-region:12345678:stream/test-stream"
]
]
}
},
{
"Action": [
"kinesis:DescribeStreamConsumer",
"kinesis:SubscribeToShard"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":kinesis:test-region:12345678:stream/test-stream/consumer/test-stream-consumer:*"
]
]
}
}
],
"Version": "2012-10-17"
},
"PolicyName": "CrossAccountRoleDefaultPolicy212A317F",
"Roles": [
{
"Ref": "CrossAccountRoleFACE29D1"
}
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
["1", "2", "3", "4", "5"],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f4453c7

Please sign in to comment.