@@ -6,7 +6,7 @@ import { IUserGroup } from './user-group';
66import * as ec2 from 'aws-cdk-lib/aws-ec2' ;
77import * as events from 'aws-cdk-lib/aws-events' ;
88import * as kms from 'aws-cdk-lib/aws-kms' ;
9- import { ArnFormat , Stack , Size , Lazy , ValidationError } from 'aws-cdk-lib/core' ;
9+ import { ArnFormat , Stack , Size , Lazy , ValidationError , Names , Token } from 'aws-cdk-lib/core' ;
1010import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource' ;
1111import { propertyInjectable } from 'aws-cdk-lib/core/lib/prop-injectable' ;
1212
@@ -244,8 +244,8 @@ export class ServerlessCache extends ServerlessCacheBase {
244244 /**
245245 * Return whether the given object is a `ServerlessCache`
246246 */
247- public static isServerlessCache ( x : any ) : x is ServerlessCache {
248- return x !== null && typeof ( x ) === 'object' && ELASTICACHE_SERVERLESSCACHE_SYMBOL in x ;
247+ public static isServerlessCache ( x : any ) : x is ServerlessCache {
248+ return x !== null && typeof ( x ) === 'object' && ELASTICACHE_SERVERLESSCACHE_SYMBOL in x ;
249249 }
250250
251251 /**
@@ -325,13 +325,13 @@ export class ServerlessCache extends ServerlessCacheBase {
325325 if ( this . engine ) {
326326 let defaultPort : ec2 . Port ;
327327 switch ( this . engine ) {
328- case CacheEngine . VALKEY_DEFAULT :
328+ case CacheEngine . VALKEY_LATEST :
329329 case CacheEngine . VALKEY_7 :
330330 case CacheEngine . VALKEY_8 :
331- case CacheEngine . REDIS_DEFAULT :
331+ case CacheEngine . REDIS_LATEST :
332332 defaultPort = ec2 . Port . tcp ( 6379 ) ;
333333 break ;
334- case CacheEngine . MEMCACHED_DEFAULT :
334+ case CacheEngine . MEMCACHED_LATEST :
335335 defaultPort = ec2 . Port . tcp ( 11211 ) ;
336336 break ;
337337 default :
@@ -407,13 +407,13 @@ export class ServerlessCache extends ServerlessCacheBase {
407407
408408 constructor ( scope : Construct , id : string , props : ServerlessCacheProps ) {
409409 super ( scope , id , {
410- physicalName : props . serverlessCacheName ,
410+ physicalName : props . serverlessCacheName ?? Lazy . string ( { produce : ( ) => Names . uniqueId ( this ) } ) ,
411411 } ) ;
412412
413413 // Enhanced CDK Analytics Telemetry
414414 addConstructMetadata ( this , props ) ;
415415
416- this . engine = props . engine ?? CacheEngine . VALKEY_DEFAULT ;
416+ this . engine = props . engine ?? CacheEngine . VALKEY_LATEST ;
417417 this . serverlessCacheName = this . physicalName ;
418418 this . kmsKey = props . kmsKey ;
419419 this . vpc = props . vpc ;
@@ -433,7 +433,7 @@ export class ServerlessCache extends ServerlessCacheBase {
433433 const securityGroupIds = securityGroupConfig . securityGroupIds ;
434434 this . securityGroups = securityGroupConfig . securityGroups ;
435435
436- const { engine, version } = this . parseEngine ( this . engine ) ;
436+ const [ engine , version ] = this . engine . split ( '_' ) ;
437437
438438 const resource = new CfnServerlessCache ( this , 'Resource' , {
439439 engine : engine ,
@@ -498,17 +498,17 @@ export class ServerlessCache extends ServerlessCacheBase {
498498 if ( ! limits ) return ;
499499
500500 if ( limits . dataStorageMinimumSize && ! limits . dataStorageMinimumSize . isUnresolved ( ) &&
501- ( limits . dataStorageMinimumSize . toGibibytes ( ) < DATA_STORAGE_MIN_GB || limits . dataStorageMinimumSize . toGibibytes ( ) > DATA_STORAGE_MAX_GB ) ) {
501+ ( limits . dataStorageMinimumSize . toGibibytes ( ) < DATA_STORAGE_MIN_GB || limits . dataStorageMinimumSize . toGibibytes ( ) > DATA_STORAGE_MAX_GB ) ) {
502502 throw new ValidationError ( 'Data storage minimum must be between 1 and 5000 GB.' , this ) ;
503503 }
504504 if ( limits . dataStorageMaximumSize && ! limits . dataStorageMaximumSize . isUnresolved ( ) &&
505- ( limits . dataStorageMaximumSize . toGibibytes ( ) < DATA_STORAGE_MIN_GB || limits . dataStorageMaximumSize . toGibibytes ( ) > DATA_STORAGE_MAX_GB ) ) {
505+ ( limits . dataStorageMaximumSize . toGibibytes ( ) < DATA_STORAGE_MIN_GB || limits . dataStorageMaximumSize . toGibibytes ( ) > DATA_STORAGE_MAX_GB ) ) {
506506 throw new ValidationError ( 'Data storage maximum must be between 1 and 5000 GB.' , this ) ;
507507 }
508508
509509 if ( limits . dataStorageMinimumSize && limits . dataStorageMaximumSize &&
510- ! limits . dataStorageMinimumSize . isUnresolved ( ) && ! limits . dataStorageMaximumSize . isUnresolved ( ) &&
511- limits . dataStorageMinimumSize . toGibibytes ( ) > limits . dataStorageMaximumSize . toGibibytes ( ) ) {
510+ ! limits . dataStorageMinimumSize . isUnresolved ( ) && ! limits . dataStorageMaximumSize . isUnresolved ( ) &&
511+ limits . dataStorageMinimumSize . toGibibytes ( ) > limits . dataStorageMaximumSize . toGibibytes ( ) ) {
512512 throw new ValidationError ( 'Data storage minimum cannot be greater than maximum' , this ) ;
513513 }
514514 }
@@ -522,16 +522,16 @@ export class ServerlessCache extends ServerlessCacheBase {
522522 if ( ! limits ) return ;
523523
524524 if ( limits . requestRateLimitMinimum !== undefined &&
525- ( limits . requestRateLimitMinimum < REQUEST_RATE_MIN_ECPU || limits . requestRateLimitMinimum > REQUEST_RATE_MAX_ECPU ) ) {
525+ ( limits . requestRateLimitMinimum < REQUEST_RATE_MIN_ECPU || limits . requestRateLimitMinimum > REQUEST_RATE_MAX_ECPU ) ) {
526526 throw new ValidationError ( 'Request rate minimum must be between 1,000 and 15,000,000 ECPUs per second' , this ) ;
527527 }
528528 if ( limits . requestRateLimitMaximum !== undefined &&
529- ( limits . requestRateLimitMaximum < REQUEST_RATE_MIN_ECPU || limits . requestRateLimitMaximum > REQUEST_RATE_MAX_ECPU ) ) {
529+ ( limits . requestRateLimitMaximum < REQUEST_RATE_MIN_ECPU || limits . requestRateLimitMaximum > REQUEST_RATE_MAX_ECPU ) ) {
530530 throw new ValidationError ( 'Request rate maximum must be between 1,000 and 15,000,000 ECPUs per second' , this ) ;
531531 }
532532
533533 if ( limits . requestRateLimitMinimum !== undefined && limits . requestRateLimitMaximum !== undefined &&
534- limits . requestRateLimitMinimum > limits . requestRateLimitMaximum ) {
534+ limits . requestRateLimitMinimum > limits . requestRateLimitMaximum ) {
535535 throw new ValidationError ( 'Request rate minimum cannot be greater than maximum' , this ) ;
536536 }
537537 }
@@ -542,14 +542,14 @@ export class ServerlessCache extends ServerlessCacheBase {
542542 * @param backup The backup settings to validate
543543 */
544544 private validateBackupSettings ( backup ?: BackupSettings ) : void {
545- if ( backup ?. backupRetentionLimit !== undefined ) {
545+ if ( ! Token . isUnresolved ( backup ?. backupRetentionLimit ) && backup ?. backupRetentionLimit !== undefined ) {
546546 const limit = backup . backupRetentionLimit ;
547547 if ( limit < 1 || limit > 35 ) {
548548 throw new ValidationError ( 'Backup retention limit must be between 1 and 35 days' , this ) ;
549549 }
550550 }
551551
552- if ( backup ?. backupNameBeforeDeletion !== undefined ) {
552+ if ( ! Token . isUnresolved ( backup ?. backupNameBeforeDeletion ) && backup ?. backupNameBeforeDeletion !== undefined ) {
553553 const name = backup . backupNameBeforeDeletion ;
554554
555555 if ( ! / ^ [ a - z A - Z ] / . test ( name ) ) {
@@ -579,11 +579,11 @@ export class ServerlessCache extends ServerlessCacheBase {
579579 private validateUserGroupCompatibility ( engine : CacheEngine , userGroup ?: IUserGroup ) : void {
580580 if ( ! userGroup ) return ;
581581
582- if ( engine === CacheEngine . MEMCACHED_DEFAULT ) {
582+ if ( engine === CacheEngine . MEMCACHED_LATEST ) {
583583 throw new ValidationError ( 'User groups cannot be used with Memcached engines. Only Redis and Valkey engines support user groups.' , this ) ;
584584 }
585585
586- if ( engine === CacheEngine . REDIS_DEFAULT && userGroup . engine !== UserEngine . REDIS ) {
586+ if ( engine === CacheEngine . REDIS_LATEST && userGroup . engine !== UserEngine . REDIS ) {
587587 throw new ValidationError ( 'Redis cache can only use Redis user groups.' , this ) ;
588588 }
589589 }
@@ -682,18 +682,4 @@ export class ServerlessCache extends ServerlessCacheBase {
682682 }
683683 throw new ValidationError ( 'Invalid schedule format for backup time' , this ) ;
684684 }
685-
686- /**
687- * Parse engine string to extract engine name and version
688- *
689- * @param eng The cache engine enum value
690- * @returns Object with engine name and optional version
691- */
692- private parseEngine ( eng : CacheEngine ) : { engine : string ; version ?: string } {
693- const parts = eng . split ( '_' ) ;
694- const engine = parts [ 0 ] ;
695- const version = parts . length > 1 ? parts [ 1 ] : undefined ;
696-
697- return { engine, version } ;
698- }
699685}
0 commit comments