-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gammarers/feature/first-happy-code
feat: first happy code
- Loading branch information
Showing
5 changed files
with
797 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
} |
Oops, something went wrong.