I cannot use the provided Bucket construct if I want to enable CORS on my bucket as there is no way to pass it to the underlying CfnBucket.
And I'm not aware of techniques that would prevent me to add this without copy-pasting the whole Bucket class to just modify the constructor.
(
By the way, in order to enable easier customisation, it might worth writing provided constructs like this :
export class Bucket extends BucketBase {
constructor(scope: cdk.Construct, id: string, props: BucketProps = {}) {
super(scope, id);
this.construct(props)
}
private construct(props: BucketProps ) {
// construction code here
const resource = new CfnBucket(this, 'Resource', {...
}
}
So that if I want to customize how the CfnXXX resource is built from my params, I can just extends the Bucket class, overwrite only the construct method, and profit from the rest of the implementation, instead of duplicating the whole class
)
For those interested, I might have found a workaround for that :
this.bucket = new s3.Bucket(this, props.s3BucketName)
const cfnBucket = this.bucket.node.findChild('Resource') as s3.CfnBucket
cfnBucket.addPropertyOverride('CorsConfiguration', {
CorsRules: [
{
AllowedOrigins: ['*'],
AllowedMethods: ['HEAD', 'GET', 'PUT', 'POST', 'DELETE'],
MaxAge: '3000',
ExposedHeaders: [
'x-amz-server-side-encryption',
'x-amz-request-id',
'x-amz-id-2',
'ETag'
],
AllowedHeaders: ['*']
}
]
})
This should be closed by #2843. Let me know if this isn't the case. Closing now, please reopen if this is still a problem.
Most helpful comment
For those interested, I might have found a workaround for that :
this.bucket = new s3.Bucket(this, props.s3BucketName) const cfnBucket = this.bucket.node.findChild('Resource') as s3.CfnBucket cfnBucket.addPropertyOverride('CorsConfiguration', { CorsRules: [ { AllowedOrigins: ['*'], AllowedMethods: ['HEAD', 'GET', 'PUT', 'POST', 'DELETE'], MaxAge: '3000', ExposedHeaders: [ 'x-amz-server-side-encryption', 'x-amz-request-id', 'x-amz-id-2', 'ETag' ], AllowedHeaders: ['*'] } ] })