Skip to content

Commit 77c5be3

Browse files
committed
fixes
1 parent cee0245 commit 77c5be3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

.tools/test/stacks/plugin/typescript/plugin_stack.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ g
234234
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
235235
});
236236

237+
// Execution role for AWS Lambda function to use
238+
// To get logs and ship them to the Admin account.
239+
// This role is referenced in the Admin stack configuration.
240+
// Modifying it will sever cross-account connection.
237241
const executionRole = new iam.Role(this, "CloudWatchExecutionRole", {
238242
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
239243
description: "Allows Lambda function to get logs from CloudWatch",
@@ -245,6 +249,7 @@ g
245249
],
246250
});
247251

252+
// Update bucket permissions to allow Lambda
248253
const statement = new iam.PolicyStatement({
249254
actions: [
250255
"s3:PutObject",
@@ -261,13 +266,15 @@ g
261266
statement.addArnPrincipal(`arn:aws:iam::${cdk.Aws.ACCOUNT_ID}:root`);
262267
bucket.addToResourcePolicy(statement);
263268

269+
// Attach custom policy to allow Lambda to get logs from CloudWatch.
264270
executionRole.addToPolicy(
265271
new iam.PolicyStatement({
266272
actions: ["logs:GetLogEvents", "logs:DescribeLogStreams"],
267273
resources: [`arn:aws:logs:${this.awsRegion}:${cdk.Aws.ACCOUNT_ID}:*`],
268274
}),
269275
);
270276

277+
// Attach custom policy to allow Lambda to get and put to local logs bucket.
271278
executionRole.addToPolicy(
272279
new iam.PolicyStatement({
273280
actions: [
@@ -297,6 +304,7 @@ g
297304
}),
298305
);
299306

307+
// Define the Lambda function.
300308
const lambdaFunction = new lambda.Function(this, "BatchJobCompleteLambda", {
301309
runtime: lambda.Runtime.PYTHON_3_8,
302310
handler: "export_logs.handler",
@@ -310,12 +318,14 @@ g
310318
},
311319
});
312320

321+
// CloudWatch Event Rule to trigger the Lambda function.
313322
const batchRule = new events.Rule(this, "BatchAllEventsRule", {
314323
eventPattern: {
315324
source: ["aws.batch"],
316325
},
317326
});
318327

328+
// Add the Lambda function as a target for the CloudWatch Event Rule.
319329
batchRule.addTarget(new targets.LambdaFunction(lambdaFunction));
320330
}
321331
}

0 commit comments

Comments
 (0)