Skip to content

Commit

Permalink
fix: rename buckets (#11481)
Browse files Browse the repository at this point in the history
* fix: change bucket names

* fix: resolved bucket names

* refactor: change physical name gen method for s3 bucket
  • Loading branch information
bashleigh authored Oct 21, 2024
1 parent f33570c commit 0c5cbd8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/deployment-service/cdk/lib/create-S3-bucket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Stack, Bucket, createBucket, BucketOptions } from '@reapit/ts-scripts/src/cdk'
import { Stack, Bucket, BucketOptions, PolicyStatement } from '@reapit/ts-scripts/src/cdk'
import { aws_s3, PhysicalName, aws_iam } from 'aws-cdk-lib'

export enum BucketNames {
LIVE = 'v2-cloud-deployment-live',
Expand All @@ -7,6 +8,34 @@ export enum BucketNames {
REPO_CACHE = 'v2-cloud-deployment-repo-cache',
}

export const createBucket = (stack: Stack, bucketName: string, options?: BucketOptions): aws_s3.Bucket => {
const bucket = new aws_s3.Bucket(options?.stack || stack, bucketName, {
publicReadAccess: options?.public,
websiteIndexDocument: options?.public ? 'index.html' : undefined,
bucketName: bucketName || PhysicalName.GENERATE_IF_NEEDED,
})
const actions: string[] = []
if (options?.get) {
actions.push('s3:Get*')
}
if (options?.list) {
actions.push('s3:List*')
}
if (options?.put) {
actions.push('s3:Put*')
}

bucket.addToResourcePolicy(
new PolicyStatement({
effect: aws_iam.Effect.ALLOW,
actions,
resources: [bucket.arnForObjects('*')],
principals: [new aws_iam.ArnPrincipal('*')],
}),
)
return bucket
}

export const createS3Buckets = (stack: Stack, usercodeStack: Stack, envStage: string): Record<BucketNames, Bucket> => {
const bucketOptions: {
[k in BucketNames]: BucketOptions
Expand Down

0 comments on commit 0c5cbd8

Please sign in to comment.