Skip to content

Conversation

@ShadowCat567
Copy link
Contributor

@ShadowCat567 ShadowCat567 commented Nov 17, 2025

Reason for this change

Adds ground work for vended logs mixin.

Description of changes

Sets up mini-constructs to be used by the mixin that assists in setting up vended logs.
Max length of name for delivery destination is 60 characters (see: https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutDeliveryDestination.html).

Describe any new or updated permissions being added

Description of how you validated changes

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Nov 17, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 17, 2025 19:47
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Nov 17, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 17, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Nov 17, 2025
Comment on lines +11 to +13
interface IDeliveryDestination extends IResource {
readonly destinationArn: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this, we can use the existing IDeliveryDestinationRef

Suggested change
interface IDeliveryDestination extends IResource {
readonly destinationArn: string;
}
interface IDeliveryDestination extends IResource {
readonly destinationArn: string;
}

readonly destinationArn: string;
}

abstract class DeliveryDestinationBase extends Resource implements IDeliveryDestination {
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
abstract class DeliveryDestinationBase extends Resource implements IDeliveryDestination {
abstract class DeliveryDestinationBase extends Resource implements IDeliveryDestinationRef {


export class S3DeliveryDestination extends DeliveryDestinationBase {
public readonly destinationArn: string;
constructor(scope: Construct, id: string, props: DeliveryDestinationProps & Required<Pick<DeliveryDestinationProps, 's3Bucket'>>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't compile in jsii. Really we need 3 separate Props objects.

Comment on lines +70 to +73
const bucketPolicy = new CfnBucketPolicy(scope, 'S3Policy', {
bucket: props.s3Bucket.bucketName,
policyDocument: bucketPolicyDoc.toJSON(),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a fun side quest: We need a helper function, that for a given Stack and IBucketRef goes through the whole stack and tries to find an existing CfnBucketPolicy for that IBucketRef.

If we find one, we use that. Otherwise we create a new one.

const destinationNamePrefix = 's3-delivery-destination-';
const deliveryDestination = new CfnDeliveryDestination(scope, 'S3DeliveryDestination', {
destinationResourceArn: props.s3Bucket.bucketArn,
name: `${destinationNamePrefix}${Names.uniqueResourceName(props.s3Bucket, { maxLength: 60 - destinationNamePrefix.length })}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

policyDocument: bucketPolicyDoc.toJSON(),
});

const destinationNamePrefix = 's3-delivery-destination-';
Copy link
Contributor

Choose a reason for hiding this comment

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

let's find a shorter prefix. Maybe something with cdk

constructor(scope: Construct, id: string, props: DeliveryDestinationProps & Required<Pick<DeliveryDestinationProps, 'logGroup'>>) {
super(scope, id);

const logGroupPolicy = new CfnResourcePolicy(scope, 'CloudwatchDeliveryPolicy', {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this one I'd like us to create a new singleton resource policy for delivery destination. We will getOrCreate that policy and than add statements to it.

This is so that when a user has multiple CloudwatchDeliveryDestinations in their stack, we only ever add a single policy. Because they are limited to max 10 per account.

}
}

export class CloudwatchDeliveryDestination extends DeliveryDestinationBase {
Copy link
Contributor

@mrgrain mrgrain Nov 18, 2025

Choose a reason for hiding this comment

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

This one I think would be this though if we follow the service name plus stuff pattern.

Suggested change
export class CloudwatchDeliveryDestination extends DeliveryDestinationBase {
export class LogsDeliveryDestination extends DeliveryDestinationBase {

bucketPolicyDoc.addStatements(v1BucketPolicy);
}

const bucketPolicy = new CfnBucketPolicy(scope, 'S3Policy', {
Copy link
Contributor

Choose a reason for hiding this comment

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

you are allowed to use a L2 BucketPolicy here if it helps

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

Also needs unit tests ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK contribution/core This is a PR that came from AWS. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants