|
1 | 1 | import iam = require('@aws-cdk/aws-iam');
|
2 | 2 | import kms = require('@aws-cdk/aws-kms');
|
3 |
| -import logs = require('@aws-cdk/aws-logs'); |
4 |
| -import { Construct, HashedAddressingScheme, IResource, Resource } from '@aws-cdk/cdk'; |
| 3 | +import { Construct, IResource, Resource } from '@aws-cdk/cdk'; |
5 | 4 | import { CfnStream } from './kinesis.generated';
|
6 | 5 |
|
7 |
| -export interface IStream extends IResource, logs.ILogSubscriptionDestination { |
| 6 | +export interface IStream extends IResource { |
8 | 7 | /**
|
9 | 8 | * The ARN of the stream.
|
10 | 9 | *
|
@@ -102,11 +101,6 @@ abstract class StreamBase extends Resource implements IStream {
|
102 | 101 | */
|
103 | 102 | public abstract readonly encryptionKey?: kms.IKey;
|
104 | 103 |
|
105 |
| - /** |
106 |
| - * The role that can be used by CloudWatch logs to write to this stream |
107 |
| - */ |
108 |
| - private cloudWatchLogsRole?: iam.Role; |
109 |
| - |
110 | 104 | /**
|
111 | 105 | * Grant write permissions for this stream and its contents to an IAM
|
112 | 106 | * principal (Role/Group/User).
|
@@ -164,66 +158,6 @@ abstract class StreamBase extends Resource implements IStream {
|
164 | 158 | return ret;
|
165 | 159 | }
|
166 | 160 |
|
167 |
| - public logSubscriptionDestination(sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestination { |
168 |
| - // Following example from https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#DestinationKinesisExample |
169 |
| - if (!this.cloudWatchLogsRole) { |
170 |
| - // Create a role to be assumed by CWL that can write to this stream and pass itself. |
171 |
| - this.cloudWatchLogsRole = new iam.Role(this, 'CloudWatchLogsCanPutRecords', { |
172 |
| - assumedBy: new iam.ServicePrincipal(`logs.${this.node.stack.region}.amazonaws.com`) |
173 |
| - }); |
174 |
| - this.cloudWatchLogsRole.addToPolicy(new iam.PolicyStatement().addAction('kinesis:PutRecord').addResource(this.streamArn)); |
175 |
| - this.cloudWatchLogsRole.addToPolicy(new iam.PolicyStatement().addAction('iam:PassRole').addResource(this.cloudWatchLogsRole.roleArn)); |
176 |
| - } |
177 |
| - |
178 |
| - // We've now made it possible for CloudWatch events to write to us. In case the LogGroup is in a |
179 |
| - // different account, we must add a Destination in between as well. |
180 |
| - const sourceStack = sourceLogGroup.node.stack; |
181 |
| - const thisStack = this.node.stack; |
182 |
| - |
183 |
| - // Case considered: if both accounts are undefined, we can't make any assumptions. Better |
184 |
| - // to assume we don't need to do anything special. |
185 |
| - const sameAccount = sourceStack.env.account === thisStack.env.account; |
186 |
| - |
187 |
| - if (!sameAccount) { |
188 |
| - return this.crossAccountLogSubscriptionDestination(sourceLogGroup); |
189 |
| - } |
190 |
| - |
191 |
| - return { arn: this.streamArn, role: this.cloudWatchLogsRole }; |
192 |
| - } |
193 |
| - |
194 |
| - /** |
195 |
| - * Generate a CloudWatch Logs Destination and return the properties in the form o a subscription destination |
196 |
| - */ |
197 |
| - private crossAccountLogSubscriptionDestination(sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestination { |
198 |
| - const sourceLogGroupConstruct: Construct = sourceLogGroup as any; |
199 |
| - const sourceStack = sourceLogGroupConstruct.node.stack; |
200 |
| - const thisStack = this.node.stack; |
201 |
| - |
202 |
| - if (!sourceStack.env.account || !thisStack.env.account) { |
203 |
| - throw new Error('SubscriptionFilter stack and Destination stack must either both have accounts defined, or both not have accounts'); |
204 |
| - } |
205 |
| - |
206 |
| - // Take some effort to construct a unique ID for the destination that is unique to the |
207 |
| - // combination of (stream, loggroup). |
208 |
| - const uniqueId = new HashedAddressingScheme().allocateAddress([ |
209 |
| - sourceLogGroupConstruct.node.path.replace('/', ''), |
210 |
| - sourceStack.env.account! |
211 |
| - ]); |
212 |
| - |
213 |
| - // The destination lives in the target account |
214 |
| - const dest = new logs.CrossAccountDestination(this, `CWLDestination${uniqueId}`, { |
215 |
| - targetArn: this.streamArn, |
216 |
| - role: this.cloudWatchLogsRole! |
217 |
| - }); |
218 |
| - |
219 |
| - dest.addToPolicy(new iam.PolicyStatement() |
220 |
| - .addAction('logs:PutSubscriptionFilter') |
221 |
| - .addAwsAccountPrincipal(sourceStack.env.account) |
222 |
| - .addAllResources()); |
223 |
| - |
224 |
| - return dest.logSubscriptionDestination(sourceLogGroup); |
225 |
| - } |
226 |
| - |
227 | 161 | private grant(grantee: iam.IGrantable, ...actions: string[]) {
|
228 | 162 | return iam.Grant.addToPrincipal({
|
229 | 163 | grantee,
|
|
0 commit comments