Make Your Id Unique

There are situations where you want uniqueness but you can not use numbers only letters to distinguish uniqueness, here's an example on how to achieve this:

export function makeUnique() {
    let text = '';
    const rangeChoice = 'abcdefghijklmnopqrstuvwxyz';
    for (let i = 0; i < 5; i++)
        text += rangeChoice.charAt(Math.floor(Math.random() * rangeChoice.length));
    return text;
}

Use it in your solution:

export class BucketStack extends Stack {
    private readonly artifactBucket: IBucket
    constructor(scope: Construct, id: string, props: BucketStackProps) {
        super(scope, id, props);

        this.artifactBucket = new aws_s3.Bucket(this, 'artifact-bucket', {
            bucketName: artifact-bucket-${makeUnique()}`,
            lifecycleRules: [{
                expiration: Duration.days(1),
                enabled: true,
            }],
            versioned: true,
            blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
            removalPolicy: RemovalPolicy.DESTROY,
            autoDeleteObjects: true,
            enforceSSL: true,
            serverAccessLogsBucket: resourcesBucket,
            encryption: BucketEncryption.S3_MANAGED,
        });
    }
}

Stay Safe ☘️