Skip to content

Commit

Permalink
feat: Support log retention setting for Lambda packager (#233)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: CDK 2.123.0 and above is required
  • Loading branch information
kichik authored Nov 24, 2024
1 parent 66d9a77 commit 67b402a
Show file tree
Hide file tree
Showing 9 changed files with 1,601 additions and 2,942 deletions.
2 changes: 1 addition & 1 deletion .projen/deps.json

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

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
author: 'Amir Szekely',
authorAddress: 'amir@cloudsnorkel.com',
stability: Stability.EXPERIMENTAL,
cdkVersion: '2.87.0', // 2.54.0 for https://github.com/aws/aws-cdk/pull/22124, 2.77.0 for removing node 14, 2.87.0 for node 18 on CodeBuild
cdkVersion: '2.123.0', // 2.54.0 for https://github.com/aws/aws-cdk/pull/22124, 2.77.0 for removing node 14, 2.87.0 for node 18 on CodeBuild, 2.123.0 for lambda logs
defaultReleaseBranch: 'main',
name: '@cloudsnorkel/cdk-turbo-layers',
repositoryUrl: 'https://github.com/CloudSnorkel/cdk-turbo-layers.git',
Expand Down
2 changes: 1 addition & 1 deletion API.md

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

4 changes: 2 additions & 2 deletions package.json

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

24 changes: 12 additions & 12 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface DependencyPackagerProps {
readonly logRetention?: logs.RetentionDays;

/**
* Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way the CodeBuild logs can still be viewed, and you can see why the build failed.
* Removal policy for logs of image builds. If deployment fails on the custom resource, try setting this to `RemovalPolicy.RETAIN`. This way logs can still be viewed, and you can see why the build failed.
*
* We try to not leave anything behind when removed. But sometimes a log staying behind is useful.
*
Expand Down Expand Up @@ -152,17 +152,17 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
this.targetDirectory = internalProps.targetDirectory;
this.architecture = internalProps.props?.architecture ?? lambda.Architecture.X86_64;

const logGroup = new logs.LogGroup(
this,
'Logs',
{
retention: internalProps.props?.logRetention ?? RetentionDays.ONE_MONTH,
removalPolicy: internalProps.props?.logRemovalPolicy ?? RemovalPolicy.DESTROY,
},
);

this.type = this.internalProps.props?.type ?? DependencyPackagerType.LAMBDA;
if (this.type == DependencyPackagerType.CODEBUILD) {
const logGroup = new logs.LogGroup(
this,
'Logs',
{
retention: internalProps.props?.logRetention ?? RetentionDays.ONE_MONTH,
removalPolicy: internalProps.props?.logRemovalPolicy ?? RemovalPolicy.DESTROY,
},
);

this.project = new codebuild.Project(this, 'Packager', {
description: `Lambda dependency packager for ${this.runtime} in ${Stack.of(this).stackName}`,
vpc: internalProps.props?.vpc,
Expand Down Expand Up @@ -200,7 +200,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
resources: [this.project.projectArn],
}),
],
logRetention: RetentionDays.ONE_MONTH,
logGroup: logGroup,
});
this.provider.node.addDependency(this.packagesBucket); // wait for everything, including auto deleter
this.provider.node.addDependency(this.project);
Expand All @@ -212,7 +212,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
timeout: Duration.minutes(15),
memorySize: 1024,
ephemeralStorageSize: Size.gibibytes(10),
logRetention: RetentionDays.ONE_MONTH,
logGroup: logGroup,
architecture: this.architecture,
vpc: internalProps.props?.vpc,
vpcSubnets: internalProps.props?.subnetSelection,
Expand Down
31 changes: 9 additions & 22 deletions test/default.integ.snapshot/Turbo-Layer-Test.assets.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"version": "36.0.0",
"files": {
"d28a3fa64d0bd6c7c6f1d6fd707d3e6dc5c81fe8f47891b89459b6492586997f": {
"b7f33614a69548d6bafe224d751a7ef238cde19097415e553fe8b63a4c8fd8a6": {
"source": {
"path": "asset.d28a3fa64d0bd6c7c6f1d6fd707d3e6dc5c81fe8f47891b89459b6492586997f",
"path": "asset.b7f33614a69548d6bafe224d751a7ef238cde19097415e553fe8b63a4c8fd8a6",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "d28a3fa64d0bd6c7c6f1d6fd707d3e6dc5c81fe8f47891b89459b6492586997f.zip",
"objectKey": "b7f33614a69548d6bafe224d751a7ef238cde19097415e553fe8b63a4c8fd8a6.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand All @@ -27,19 +27,6 @@
}
}
},
"5fa1330271b8967d9254ba2d4a07144f8acefe8b77e6d6bba38261373a50d5f8": {
"source": {
"path": "asset.5fa1330271b8967d9254ba2d4a07144f8acefe8b77e6d6bba38261373a50d5f8",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "5fa1330271b8967d9254ba2d4a07144f8acefe8b77e6d6bba38261373a50d5f8.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"9afa25b7aaac0f1e5c0a217c2ca3d8f0927ff079339a8514309eb1b4645571eb": {
"source": {
"path": "asset.9afa25b7aaac0f1e5c0a217c2ca3d8f0927ff079339a8514309eb1b4645571eb",
Expand All @@ -53,15 +40,15 @@
}
}
},
"61b977bd2ad84e98e78440b618c2decfff23ec89f32908ad25d182c090bf6bec": {
"ac4a1bd8c7c7879385a212db2c46b2cb8f9e23b91c993d826d478bff7dbc0af3": {
"source": {
"path": "asset.61b977bd2ad84e98e78440b618c2decfff23ec89f32908ad25d182c090bf6bec",
"path": "asset.ac4a1bd8c7c7879385a212db2c46b2cb8f9e23b91c993d826d478bff7dbc0af3",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "61b977bd2ad84e98e78440b618c2decfff23ec89f32908ad25d182c090bf6bec.zip",
"objectKey": "ac4a1bd8c7c7879385a212db2c46b2cb8f9e23b91c993d826d478bff7dbc0af3.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down Expand Up @@ -235,15 +222,15 @@
}
}
},
"79275bb63494b562d625c125fb625a0ceb1369a1a6efa409a3ea077d2c1fc371": {
"df1ff032892b896925f5b4c51f977e19893c505394b78f7aac4baa31e17fadf8": {
"source": {
"path": "Turbo-Layer-Test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "79275bb63494b562d625c125fb625a0ceb1369a1a6efa409a3ea077d2c1fc371.json",
"objectKey": "df1ff032892b896925f5b4c51f977e19893c505394b78f7aac4baa31e17fadf8.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Loading

0 comments on commit 67b402a

Please sign in to comment.