Skip to content

Commit

Permalink
Merge pull request #3 from gammarers/feature/first-happy-code
Browse files Browse the repository at this point in the history
feat: first happy code
  • Loading branch information
yicr authored Dec 20, 2024
2 parents ba6f2b9 + bc2efc4 commit 14f4b1f
Show file tree
Hide file tree
Showing 5 changed files with 797 additions and 3 deletions.
127 changes: 126 additions & 1 deletion API.md

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

73 changes: 72 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,78 @@
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { RelocatorStateMachine } from './resources/relocate-state-machine';

export interface AccessLogSource {
readonly bucket: s3.IBucket;
readonly objectPrefix: string;
}

// export enum PartitioningFormatType {
// /** yyyy/mm/dd */
// HIERARCHICAL_DATE_PARTITIONING_FORMAT, Default
// /** y=yyyy/m=mm/d=dd */
// KEY_VALUE_DATE_PARTITIONING_FORMAT, Hive Type
// }

export interface AccessLogDestination {
readonly bucket: s3.IBucket;
readonly objectPrefix: string;
// readonly partitioningFormatType: PartitioningFormatType;
}

export interface CloudFrontAccessLogRelocaterProps {
readonly accessLogSource: AccessLogSource;
readonly accessLogDestination: AccessLogDestination;
}

export class CloudFrontAccessLogRelocater extends Construct {
constructor(scope: Construct, id: string) {
constructor(scope: Construct, id: string, props: CloudFrontAccessLogRelocaterProps) {
super(scope, id);

// 👇 relocate state machine(bukect object copy & delete)
const machine = new RelocatorStateMachine(this, 'RelocatorStateMachine', {
accessLogSource: props.accessLogSource,
accessLogDestination: props.accessLogDestination,
});

// 👇 access log created event catch rule
new events.Rule(this, 'EventRule', {
// ruleName: `hac-cloudfront-log-output-${props.random}-event-rule`,
description: 'event rule.',
eventPattern: {
source: ['aws.s3'],
detailType: ['Object Created'],
detail: {
bucket: {
name: [props.accessLogSource.bucket.bucketName],
},
object: {
key: [
{
wildcard: `${props.accessLogSource.objectPrefix}/*.gz`,
},
],
},
},
},
targets: [
new targets.SfnStateMachine(machine, {
input: events.RuleTargetInput.fromObject({
event: events.EventField.fromPath('$'),
params: {
accessLogDestination: {
bucketName: props.accessLogDestination.bucket.bucketName,
objectPrifix: props.accessLogDestination.objectPrefix,
},
},
}),
}),
],
});
// input: events.RuleTargetInput.fromObject({
// event: events.RuleTargetInput.fromEventPath('$'),
// customKey: 'customValue',
}
}
Loading

0 comments on commit 14f4b1f

Please sign in to comment.