Skip to content

Commit

Permalink
feat: account region unique bucket name (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
thantos authored Oct 19, 2023
1 parent 87db126 commit 3388882
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
11 changes: 8 additions & 3 deletions packages/@eventual/aws-cdk/src/bucket-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class BucketService<Service> {
}

public grantReadWriteBuckets(grantee: IGrantable) {
const stack = Stack.of(this.props.systemScope);
// find any bucket names that were provided by the service and not computed
const bucketNameOverrides = this.props.bucketOverrides
? Object.values(
Expand All @@ -114,7 +115,7 @@ export class BucketService<Service> {
resources: [
serviceBucketArn(
this.props.serviceName,
bucketServiceBucketSuffix("*"),
bucketServiceBucketSuffix("*", stack.account, stack.region),
false
),
...bucketNameOverrides.map(formatBucketArn),
Expand All @@ -133,7 +134,7 @@ export class BucketService<Service> {
resources: [
`${serviceBucketArn(
this.props.serviceName,
bucketServiceBucketSuffix("*"),
bucketServiceBucketSuffix("*", stack.account, stack.region),
false
)}/*`,
...bucketNameOverrides.map((s) => formatBucketArn(`${s}/*`)),
Expand Down Expand Up @@ -173,6 +174,8 @@ class Bucket extends Construct implements IBucket {
constructor(scope: Construct, props: BucketProps) {
super(scope, props.bucket.name);

const stack = Stack.of(this);

const bucketOverrides =
props.serviceProps.bucketOverrides?.[props.bucket.name];

Expand Down Expand Up @@ -212,7 +215,9 @@ class Bucket extends Construct implements IBucket {
bucketOverrides?.bucketName ??
bucketServiceBucketName(
props.serviceProps.serviceName,
props.bucket.name
props.bucket.name,
stack.account,
stack.region
),
autoDeleteObjects: bucketOverrides?.autoDeleteObjects ?? true,
removalPolicy: bucketOverrides?.removalPolicy ?? RemovalPolicy.DESTROY,
Expand Down
2 changes: 2 additions & 0 deletions packages/@eventual/aws-runtime/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export const createBucketStore = memoize(
s3: s3(),
serviceName: env.serviceName,
bucketOverrides: env.bucketOverrides,
accountID: env.awsAccount,
region: env.awsRegion,
})
);

Expand Down
9 changes: 8 additions & 1 deletion packages/@eventual/aws-runtime/src/stores/bucket-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface AWSBucketStoreProps {
s3: S3Client;
serviceName: LazyValue<string>;
bucketOverrides: LazyValue<Record<string, BucketRuntimeOverrides>>;
accountID: LazyValue<string>;
region: LazyValue<string>;
}

export class AWSBucketStore implements BucketStore {
Expand Down Expand Up @@ -244,7 +246,12 @@ export class AWSBucketStore implements BucketStore {
const nameOverride = overrides[bucketName]?.bucketName;
return (
nameOverride ??
bucketServiceBucketName(getLazy(this.props.serviceName), bucketName)
bucketServiceBucketName(
getLazy(this.props.serviceName),
bucketName,
getLazy(this.props.accountID),
getLazy(this.props.region)
)
);
}
}
17 changes: 13 additions & 4 deletions packages/@eventual/aws-runtime/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@ export function entityServiceTableSuffix(entityName: string) {
return `entity-${entityName}`;
}

export function bucketServiceBucketSuffix(bucketName: string) {
return `bucket-${bucketName}`;
export function bucketServiceBucketSuffix(
bucketName: string,
accountID: string,
region: string
) {
return `${bucketName}-${accountID}-${region}`;
}

export function queueServiceQueueSuffix(queueName: string) {
Expand Down Expand Up @@ -314,9 +318,14 @@ export function entityServiceTableName(
*/
export function bucketServiceBucketName(
serviceName: string,
bucketName: string
bucketName: string,
accountID: string,
region: string
): string {
return serviceBucketName(serviceName, bucketServiceBucketSuffix(bucketName));
return serviceBucketName(
serviceName,
bucketServiceBucketSuffix(bucketName, accountID, region)
);
}

export function socketServiceSocketName(
Expand Down

0 comments on commit 3388882

Please sign in to comment.