Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(synthetics): lifecycle rules for auto-generated artifact buckets #22863

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-synthetics/lib/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export interface ArtifactsBucketLocation {
* Properties for a canary
*/
export interface CanaryProps {
/**
* Lifecycle rules for the generated canary artifact bucket.
*
* @default - No rules applied. This has no effect if a bucket is passed
* to `artifactsBucketLocation`.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Lifecycle rules for the generated canary artifact bucket.
*
* @default - No rules applied. This has no effect if a bucket is passed
* to `artifactsBucketLocation`.
*/
* Lifecycle rules for the generated canary artifact bucket. Has no effect
* if a bucket is passed to `artifactsBucketLocation`. If you pass a bucket
* to `artifactsBucketLocation`, you can add lifecycle rules to the bucket
* itself.
*
* @default - no rules applied to the generated bucket.
*/

readonly artifactsBucketLifecycleRules?: Array<s3.LifecycleRule>;

/**
* The s3 location that stores the data of the canary runs.
*
Expand Down Expand Up @@ -260,6 +268,7 @@ export class Canary extends cdk.Resource implements ec2.IConnectable {
this.artifactsBucket = props.artifactsBucketLocation?.bucket ?? new s3.Bucket(this, 'ArtifactsBucket', {
encryption: s3.BucketEncryption.KMS_MANAGED,
enforceSSL: true,
lifecycleRules: props.artifactsBucketLifecycleRules,
});

this.role = props.role ?? this.createDefaultRole(props);
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-synthetics/test/canary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,37 @@ test('An existing bucket and prefix can be specified instead of auto-created', (
});
});

test('An auto-generated bucket has lifecycle rules', () => {
// GIVEN
const stack = new Stack();
const lifecycleRules: Array<s3.LifecycleRule> = [
{
expiration: Duration.days(30),
},
];

// WHEN
new synthetics.Canary(stack, 'Canary', {
artifactsBucketLifecycleRules: lifecycleRules,
test: synthetics.Test.custom({
handler: 'index.handler',
code: synthetics.Code.fromInline('/* Synthetics handler code */'),
}),
runtime: synthetics.Runtime.SYNTHETICS_1_0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
runtime: synthetics.Runtime.SYNTHETICS_1_0,
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,

});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
LifecycleConfiguration: {
Rules: [
{
ExpirationInDays: 30,
},
],
},
});
});

test('Runtime can be specified', () => {
// GIVEN
const stack = new Stack();
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-synthetics/test/integ.canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ new synthetics.Canary(stack, 'MyCanaryOne', {
code: synthetics.Code.fromAsset(path.join(__dirname, 'canaries')),
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_2,
artifactsBucketLifecycleRules: [
{
expiration: cdk.Duration.days(30),
},
],
});

new synthetics.Canary(stack, 'MyCanaryTwo', {
Expand Down