|
1 | 1 | import { Template } from '@aws-cdk/assertions';
|
| 2 | +import * as iam from '@aws-cdk/aws-iam'; |
2 | 3 | import * as kinesis from '@aws-cdk/aws-kinesis';
|
3 | 4 | import * as logs from '@aws-cdk/aws-logs';
|
4 | 5 | import * as cdk from '@aws-cdk/core';
|
@@ -136,3 +137,54 @@ test('stream can be subscription destination twice, without duplicating permissi
|
136 | 137 | },
|
137 | 138 | });
|
138 | 139 | });
|
| 140 | + |
| 141 | +test('an existing IAM role can be passed to new destination instance instead of auto-created ', ()=> { |
| 142 | + // GIVEN |
| 143 | + const stack = new cdk.Stack(); |
| 144 | + const stream = new kinesis.Stream(stack, 'MyStream'); |
| 145 | + const logGroup = new logs.LogGroup(stack, 'LogGroup'); |
| 146 | + |
| 147 | + const importedRole = iam.Role.fromRoleArn(stack, 'ImportedRole', 'arn:aws:iam::123456789012:role/ImportedRoleKinesisDestinationTest'); |
| 148 | + |
| 149 | + const kinesisDestination = new dests.KinesisDestination(stream, { role: importedRole }); |
| 150 | + |
| 151 | + new logs.SubscriptionFilter(logGroup, 'MySubscriptionFilter', { |
| 152 | + logGroup: logGroup, |
| 153 | + destination: kinesisDestination, |
| 154 | + filterPattern: logs.FilterPattern.allEvents(), |
| 155 | + }); |
| 156 | + |
| 157 | + // THEN |
| 158 | + const template = Template.fromStack(stack); |
| 159 | + template.resourceCountIs('AWS::IAM::Role', 0); |
| 160 | + template.hasResourceProperties('AWS::Logs::SubscriptionFilter', { |
| 161 | + RoleArn: importedRole.roleArn, |
| 162 | + }); |
| 163 | +}); |
| 164 | + |
| 165 | +test('creates a new IAM Role if not passed on new destination instance', ()=> { |
| 166 | + // GIVEN |
| 167 | + const stack = new cdk.Stack(); |
| 168 | + const stream = new kinesis.Stream(stack, 'MyStream'); |
| 169 | + const logGroup = new logs.LogGroup(stack, 'LogGroup'); |
| 170 | + |
| 171 | + const kinesisDestination = new dests.KinesisDestination(stream); |
| 172 | + |
| 173 | + new logs.SubscriptionFilter(logGroup, 'MySubscriptionFilter', { |
| 174 | + logGroup: logGroup, |
| 175 | + destination: kinesisDestination, |
| 176 | + filterPattern: logs.FilterPattern.allEvents(), |
| 177 | + }); |
| 178 | + |
| 179 | + // THEN |
| 180 | + const template = Template.fromStack(stack); |
| 181 | + template.resourceCountIs('AWS::IAM::Role', 1); |
| 182 | + template.hasResourceProperties('AWS::Logs::SubscriptionFilter', { |
| 183 | + RoleArn: { |
| 184 | + 'Fn::GetAtt': [ |
| 185 | + 'LogGroupMySubscriptionFilterCloudWatchLogsCanPutRecords9112BD02', |
| 186 | + 'Arn', |
| 187 | + ], |
| 188 | + }, |
| 189 | + }); |
| 190 | +}); |
0 commit comments