-
Notifications
You must be signed in to change notification settings - Fork 344
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: Add option to use CMK and set the resources retention #573
Changes from 4 commits
6b819bc
12d0701
1d4f281
90ceb8d
1781247
1d59dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import { Construct } from "constructs"; | ||
import * as s3 from "aws-cdk-lib/aws-s3"; | ||
import * as kms from "aws-cdk-lib/aws-kms"; | ||
import { NagSuppressions } from "cdk-nag"; | ||
|
||
export interface ChatBotS3BucketsProps { | ||
readonly retainOnDelete?: boolean; | ||
readonly kmsKey?: kms.Key; | ||
} | ||
|
||
export class ChatBotS3Buckets extends Construct { | ||
public readonly filesBucket: s3.Bucket; | ||
public readonly userFeedbackBucket: s3.Bucket; | ||
|
||
constructor(scope: Construct, id: string) { | ||
constructor(scope: Construct, id: string, props: ChatBotS3BucketsProps) { | ||
super(scope, id); | ||
|
||
const logsBucket = new s3.Bucket(this, "LogsBucket", { | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, | ||
removalPolicy: | ||
props.retainOnDelete === true | ||
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE | ||
: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: props.retainOnDelete !== true, | ||
enforceSSL: true, | ||
encryption: s3.BucketEncryption.S3_MANAGED, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does logs bucket encrypted with S3 managed key and files bucket has options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not supported. "You can use default bucket encryption on the destination bucket only if you use server-side encryption with Amazon S3 managed keys (SSE-S3), which uses the 256-bit Advanced Encryption Standard (AES-256). Default server-side encryption with AWS Key Management Service (AWS KMS) keys (SSE-KMS) is not supported." |
||
versioned: true, | ||
}); | ||
|
||
const filesBucket = new s3.Bucket(this, "FilesBucket", { | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, | ||
removalPolicy: | ||
props.retainOnDelete === true | ||
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE | ||
: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: props.retainOnDelete !== true, | ||
transferAcceleration: true, | ||
enforceSSL: true, | ||
serverAccessLogsBucket: logsBucket, | ||
encryption: props.kmsKey | ||
? s3.BucketEncryption.KMS | ||
: s3.BucketEncryption.S3_MANAGED, | ||
encryptionKey: props.kmsKey, | ||
versioned: true, | ||
cors: [ | ||
{ | ||
allowedHeaders: ["*"], | ||
|
@@ -42,10 +61,18 @@ export class ChatBotS3Buckets extends Construct { | |
|
||
const userFeedbackBucket = new s3.Bucket(this, "UserFeedbackBucket", { | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, | ||
removalPolicy: | ||
props.retainOnDelete === true | ||
? cdk.RemovalPolicy.RETAIN_ON_UPDATE_OR_DELETE | ||
: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: props.retainOnDelete !== true, | ||
enforceSSL: true, | ||
serverAccessLogsBucket: logsBucket, | ||
encryption: props.kmsKey | ||
? s3.BucketEncryption.KMS | ||
: s3.BucketEncryption.S3_MANAGED, | ||
encryptionKey: props.kmsKey, | ||
versioned: true, | ||
}); | ||
|
||
this.filesBucket = filesBucket; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if props.kmsKey does not exist? Same comment for other constructs like ChatBotS3Buckets, RealtimeResolvers, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes undefined. (property is ignored)