Skip to content

Commit b60dc63

Browse files
authoredDec 3, 2021
feat(aws-s3-deployment): log retention option (#17779)
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c524307 commit b60dc63

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed
 

‎packages/@aws-cdk/aws-s3-deployment/README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,18 @@ This is what happens under the hood:
4444
`websiteBucket`). If there is more than one source, the sources will be
4545
downloaded and merged pre-deployment at this step.
4646

47-
4847
## Supported sources
4948

5049
The following source types are supported for bucket deployments:
5150

52-
- Local .zip file: `s3deploy.Source.asset('/path/to/local/file.zip')`
53-
- Local directory: `s3deploy.Source.asset('/path/to/local/directory')`
54-
- Another bucket: `s3deploy.Source.bucket(bucket, zipObjectKey)`
51+
- Local .zip file: `s3deploy.Source.asset('/path/to/local/file.zip')`
52+
- Local directory: `s3deploy.Source.asset('/path/to/local/directory')`
53+
- Another bucket: `s3deploy.Source.bucket(bucket, zipObjectKey)`
5554

5655
To create a source from a single file, you can pass `AssetOptions` to exclude
5756
all but a single file:
5857

59-
- Single file: `s3deploy.Source.asset('/path/to/local/directory', { exclude: ['**', '!onlyThisFile.txt'] })`
58+
- Single file: `s3deploy.Source.asset('/path/to/local/directory', { exclude: ['**', '!onlyThisFile.txt'] })`
6059

6160
**IMPORTANT** The `aws-s3-deployment` module is only intended to be used with
6261
zip files from trusted sources. Directories bundled by the CDK CLI (by using
@@ -243,7 +242,7 @@ size of the AWS Lambda resource handler.
243242
244243
## EFS Support
245244

246-
If your workflow needs more disk space than default (512 MB) disk space, you may attach an EFS storage to underlying
245+
If your workflow needs more disk space than default (512 MB) disk space, you may attach an EFS storage to underlying
247246
lambda function. To Enable EFS support set `efs` and `vpc` props for BucketDeployment.
248247

249248
Check sample usage below.
@@ -288,4 +287,4 @@ might be tricky to build on Windows.
288287

289288
## Roadmap
290289

291-
- [ ] Support "blue/green" deployments ([#954](https://github.com/aws/aws-cdk/issues/954))
290+
- [ ] Support "blue/green" deployments ([#954](https://github.com/aws/aws-cdk/issues/954))

‎packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as ec2 from '@aws-cdk/aws-ec2';
44
import * as efs from '@aws-cdk/aws-efs';
55
import * as iam from '@aws-cdk/aws-iam';
66
import * as lambda from '@aws-cdk/aws-lambda';
7+
import * as logs from '@aws-cdk/aws-logs';
78
import * as s3 from '@aws-cdk/aws-s3';
89
import * as cdk from '@aws-cdk/core';
910
import { AwsCliLayer } from '@aws-cdk/lambda-layer-awscli';
@@ -101,6 +102,14 @@ export interface BucketDeploymentProps {
101102
*/
102103
readonly distributionPaths?: string[];
103104

105+
106+
/**
107+
* The number of days that the lambda function's log events are kept in CloudWatch Logs.
108+
*
109+
* @default logs.RetentionDays.INFINITE
110+
*/
111+
readonly logRetention?: logs.RetentionDays;
112+
104113
/**
105114
* The amount of memory (in MiB) to allocate to the AWS Lambda function which
106115
* replicates the files from the CDK bucket to the destination bucket.
@@ -297,6 +306,7 @@ export class BucketDeployment extends CoreConstruct {
297306
accessPoint,
298307
mountPath,
299308
) : undefined,
309+
logRetention: props.logRetention,
300310
});
301311

302312
const handlerRole = handler.role;

‎packages/@aws-cdk/aws-s3-deployment/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"@aws-cdk/aws-efs": "0.0.0",
9393
"@aws-cdk/aws-iam": "0.0.0",
9494
"@aws-cdk/aws-lambda": "0.0.0",
95+
"@aws-cdk/aws-logs": "0.0.0",
9596
"@aws-cdk/aws-s3": "0.0.0",
9697
"@aws-cdk/aws-s3-assets": "0.0.0",
9798
"@aws-cdk/core": "0.0.0",
@@ -106,6 +107,7 @@
106107
"@aws-cdk/aws-efs": "0.0.0",
107108
"@aws-cdk/aws-iam": "0.0.0",
108109
"@aws-cdk/aws-lambda": "0.0.0",
110+
"@aws-cdk/aws-logs": "0.0.0",
109111
"@aws-cdk/aws-s3": "0.0.0",
110112
"@aws-cdk/aws-s3-assets": "0.0.0",
111113
"@aws-cdk/core": "0.0.0",

‎packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import '@aws-cdk/assert-internal/jest';
21
import * as path from 'path';
32
import { MatchStyle, objectLike } from '@aws-cdk/assert-internal';
3+
import '@aws-cdk/assert-internal/jest';
44
import * as cloudfront from '@aws-cdk/aws-cloudfront';
55
import * as ec2 from '@aws-cdk/aws-ec2';
66
import * as iam from '@aws-cdk/aws-iam';
7+
import * as logs from '@aws-cdk/aws-logs';
78
import * as s3 from '@aws-cdk/aws-s3';
89
import { testDeprecated, testFutureBehavior } from '@aws-cdk/cdk-build-tools';
910
import * as cdk from '@aws-cdk/core';
@@ -75,6 +76,22 @@ test('deploy from local directory asset', () => {
7576
});
7677
});
7778

79+
test('deploy with configured log retention', () => {
80+
// GIVEN
81+
const stack = new cdk.Stack();
82+
const bucket = new s3.Bucket(stack, 'Dest');
83+
84+
// WHEN
85+
new s3deploy.BucketDeployment(stack, 'Deploy', {
86+
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
87+
destinationBucket: bucket,
88+
logRetention: logs.RetentionDays.ONE_WEEK,
89+
});
90+
91+
// THEN
92+
expect(stack).toHaveResourceLike('Custom::LogRetention', { RetentionInDays: 7 });
93+
});
94+
7895
test('deploy from local directory assets', () => {
7996
// GIVEN
8097
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)
Please sign in to comment.