@@ -253,6 +253,7 @@ export class BucketDeployment extends Construct {
253
253
private readonly cr : cdk . CustomResource ;
254
254
private _deployedBucket ?: s3 . IBucket ;
255
255
private requestDestinationArn : boolean = false ;
256
+ private readonly destinationBucket : s3 . IBucket ;
256
257
private readonly sources : SourceConfig [ ] ;
257
258
private readonly handlerRole : iam . IRole ;
258
259
@@ -274,6 +275,8 @@ export class BucketDeployment extends Construct {
274
275
throw new Error ( 'Vpc must be specified if useEfs is set' ) ;
275
276
}
276
277
278
+ this . destinationBucket = props . destinationBucket ;
279
+
277
280
const accessPointPath = '/lambda' ;
278
281
let accessPoint ;
279
282
if ( props . useEfs && props . vpc ) {
@@ -333,9 +336,9 @@ export class BucketDeployment extends Construct {
333
336
334
337
this . sources = props . sources . map ( ( source : ISource ) => source . bind ( this , { handlerRole : this . handlerRole } ) ) ;
335
338
336
- props . destinationBucket . grantReadWrite ( handler ) ;
339
+ this . destinationBucket . grantReadWrite ( handler ) ;
337
340
if ( props . accessControl ) {
338
- props . destinationBucket . grantPutAcl ( handler ) ;
341
+ this . destinationBucket . grantPutAcl ( handler ) ;
339
342
}
340
343
if ( props . distribution ) {
341
344
handler . addToRolePolicy ( new iam . PolicyStatement ( {
@@ -378,7 +381,7 @@ export class BucketDeployment extends Construct {
378
381
} , [ ] as Array < Record < string , any > > ) ;
379
382
} ,
380
383
} , { omitEmptyArray : true } ) ,
381
- DestinationBucketName : props . destinationBucket . bucketName ,
384
+ DestinationBucketName : this . destinationBucket . bucketName ,
382
385
DestinationBucketKeyPrefix : props . destinationKeyPrefix ,
383
386
RetainOnDelete : props . retainOnDelete ,
384
387
Extract : props . extract ,
@@ -389,8 +392,8 @@ export class BucketDeployment extends Construct {
389
392
SystemMetadata : mapSystemMetadata ( props ) ,
390
393
DistributionId : props . distribution ?. distributionId ,
391
394
DistributionPaths : props . distributionPaths ,
392
- // Passing through the ARN sequences dependencees on the deployment
393
- DestinationBucketArn : cdk . Lazy . string ( { produce : ( ) => this . requestDestinationArn ? props . destinationBucket . bucketArn : undefined } ) ,
395
+ // Passing through the ARN sequences dependency on the deployment
396
+ DestinationBucketArn : cdk . Lazy . string ( { produce : ( ) => this . requestDestinationArn ? this . destinationBucket . bucketArn : undefined } ) ,
394
397
} ,
395
398
} ) ;
396
399
@@ -447,7 +450,7 @@ export class BucketDeployment extends Construct {
447
450
* want the contents of the bucket to be removed on bucket deletion, then `autoDeleteObjects` property should
448
451
* be set to true on the Bucket.
449
452
*/
450
- cdk . Tags . of ( props . destinationBucket ) . add ( tagKey , 'true' ) ;
453
+ cdk . Tags . of ( this . destinationBucket ) . add ( tagKey , 'true' ) ;
451
454
452
455
}
453
456
@@ -458,11 +461,18 @@ export class BucketDeployment extends Construct {
458
461
* bucket deployment has happened before the next operation is started, pass the other construct
459
462
* a reference to `deployment.deployedBucket`.
460
463
*
461
- * Doing this replaces calling `otherResource.node.addDependency(deployment)`.
464
+ * Note that this only returns an immutable reference to the destination bucket.
465
+ * If sequenced access to the original destination bucket is required, you may add a dependency
466
+ * on the bucket deployment instead: `otherResource.node.addDependency(deployment)`
462
467
*/
463
468
public get deployedBucket ( ) : s3 . IBucket {
464
469
this . requestDestinationArn = true ;
465
- this . _deployedBucket = this . _deployedBucket ?? s3 . Bucket . fromBucketArn ( this , 'DestinationBucket' , cdk . Token . asString ( this . cr . getAtt ( 'DestinationBucketArn' ) ) ) ;
470
+ this . _deployedBucket = this . _deployedBucket ?? s3 . Bucket . fromBucketAttributes ( this , 'DestinationBucket' , {
471
+ bucketArn : cdk . Token . asString ( this . cr . getAtt ( 'DestinationBucketArn' ) ) ,
472
+ region : this . destinationBucket . env . region ,
473
+ account : this . destinationBucket . env . account ,
474
+ isWebsite : this . destinationBucket . isWebsite ,
475
+ } ) ;
466
476
return this . _deployedBucket ;
467
477
}
468
478
0 commit comments