Skip to content

Commit a7c79bc

Browse files
committed
incorporate PR feedback
1 parent 59dd286 commit a7c79bc

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

packages/@aws-cdk/aws-kinesis/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ const importedStream = Stream.fromStreamAttributes(
125125

126126
### Permission Grants
127127

128-
IAM roles, users or groups which need to be able to work with Amazon Kinesis streams at runtime will should be granted IAM permissions. Any object that implements the `IGrantable`
129-
interface (has an associated principal) can be granted permissions by calling:
128+
IAM roles, users or groups which need to be able to work with Amazon Kinesis streams at runtime should be granted IAM permissions.
129+
130+
Any object that implements the `IGrantable` interface (has an associated principal) can be granted permissions by calling:
130131

131132
- `grantRead(principal)` - grants the principal read access
132133
- `grantWrite(principal)` - grants the principal write permissions to a Stream

packages/@aws-cdk/aws-kinesis/lib/stream.ts

+18-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import { Aws, CfnCondition, Construct, Duration, Fn, IResource, Resource, Stack
44
import { IResolvable } from 'constructs';
55
import { CfnStream } from './kinesis.generated';
66

7+
const READ_OPERATIONS = [
8+
'kinesis:DescribeStream',
9+
'kinesis:DescribeStreamSummary',
10+
'kinesis:GetRecords',
11+
'kinesis:GetShardIterator',
12+
'kinesis:ListShards',
13+
'kinesis:SubscribeToShard'
14+
];
15+
16+
const WRITE_OPERATIONS = [
17+
'kinesis:ListShards',
18+
'kinesis:PutRecord',
19+
'kinesis:PutRecords'
20+
];
21+
722
/**
823
* A Kinesis Stream
924
*/
@@ -115,14 +130,7 @@ abstract class StreamBase extends Resource implements IStream {
115130
* contents of the stream will also be granted.
116131
*/
117132
public grantRead(grantee: iam.IGrantable) {
118-
const ret = this.grant(
119-
grantee,
120-
'kinesis:DescribeStream',
121-
'kinesis:DescribeStreamSummary',
122-
'kinesis:GetRecords',
123-
'kinesis:GetShardIterator',
124-
'kinesis:ListShards',
125-
'kinesis:SubscribeToShard');
133+
const ret = this.grant(grantee, ...READ_OPERATIONS);
126134

127135
if (this.encryptionKey) {
128136
this.encryptionKey.grantDecrypt(grantee);
@@ -139,11 +147,7 @@ abstract class StreamBase extends Resource implements IStream {
139147
* contents of the stream will also be granted.
140148
*/
141149
public grantWrite(grantee: iam.IGrantable) {
142-
const ret = this.grant(
143-
grantee,
144-
'kinesis:ListShards',
145-
'kinesis:PutRecord',
146-
'kinesis:PutRecords');
150+
const ret = this.grant(grantee, ...WRITE_OPERATIONS);
147151

148152
if (this.encryptionKey) {
149153
this.encryptionKey.grantEncrypt(grantee);
@@ -160,16 +164,7 @@ abstract class StreamBase extends Resource implements IStream {
160164
* encrypt/decrypt will also be granted.
161165
*/
162166
public grantReadWrite(grantee: iam.IGrantable) {
163-
const ret = this.grant(
164-
grantee,
165-
'kinesis:DescribeStream',
166-
'kinesis:DescribeStreamSummary',
167-
'kinesis:GetRecords',
168-
'kinesis:GetShardIterator',
169-
'kinesis:ListShards',
170-
'kinesis:PutRecord',
171-
'kinesis:PutRecords',
172-
'kinesis:SubscribeToShard');
167+
const ret = this.grant(grantee, ...Array.from(new Set([...READ_OPERATIONS, ...WRITE_OPERATIONS])));
173168

174169
if (this.encryptionKey) {
175170
this.encryptionKey.grantEncryptDecrypt(grantee);

packages/@aws-cdk/aws-kinesis/test/integ.stream.expected.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"kinesis:GetRecords",
4545
"kinesis:GetShardIterator",
4646
"kinesis:ListShards",
47+
"kinesis:SubscribeToShard",
4748
"kinesis:PutRecord",
48-
"kinesis:PutRecords",
49-
"kinesis:SubscribeToShard"
49+
"kinesis:PutRecords"
5050
],
5151
"Effect": "Allow",
5252
"Resource": {

packages/@aws-cdk/aws-kinesis/test/test.stream.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,9 @@ export = {
868868
'kinesis:GetRecords',
869869
'kinesis:GetShardIterator',
870870
'kinesis:ListShards',
871+
'kinesis:SubscribeToShard',
871872
'kinesis:PutRecord',
872-
'kinesis:PutRecords',
873-
'kinesis:SubscribeToShard'
873+
'kinesis:PutRecords'
874874
],
875875
Effect: 'Allow',
876876
Resource: {
@@ -1114,9 +1114,9 @@ export = {
11141114
'kinesis:GetRecords',
11151115
'kinesis:GetShardIterator',
11161116
'kinesis:ListShards',
1117+
'kinesis:SubscribeToShard',
11171118
'kinesis:PutRecord',
1118-
'kinesis:PutRecords',
1119-
'kinesis:SubscribeToShard'
1119+
'kinesis:PutRecords'
11201120
],
11211121
Effect: 'Allow',
11221122
Resource: {

0 commit comments

Comments
 (0)