CDKã®L2ã³ã³ã¹ãã©ã¯ããè¨è¨ããä¸ã§ãå¼æ°ã®åå®ç¾©ã«æ©ããã¨ã¯å¤ãã¨æãã¾ããã©ãã«ãã¦ã¼ã¶ã®ä½¿ãããã(L1ã®è¤éããé²åºãããªã)åå®ç¾©ã«ãããã§ãããã
ãããªæãã¡ããã¡ããã¯ã©ã¹å¼æ°ãæ´»ç¨ãããã¨ãããã¾ãã ããã¤ãã®ãã¿ã¼ã³ã§çµé¨ãã¦ããã®ã§ãå®éã®è¨è¨æ¦ç¥ä¾ã®ãããªãã®ãã¾ã¨ãã¦ã¿ããã¨æãã¾ãã
ä»ã®æç¹ã§ã®é ã®ä¸ã®æ´çã¡ã¢ãªã®ã§ãããè¯ãã¢ã¤ãã¢ãè¨è¨æ¹éãªã©ããã°ãã²ãã£ã¼ãããã¯é ããã°ã¨æãã¾ãï¼
Enum-like classes
ã¨ã³ã¸ã³ãã¼ã¸ã§ã³ãªã©ã«ããã¦ããã決ã¾ã£ãããªã¨ã¼ã·ã§ã³ã®stringåã®å¼æ°ã渡ããã¨ãããã¾ãã ãã®æãåç´ã«stringã渡ãããããEnum-like classesãå©ç¨ããã®ãããããã§ãã
æ¦è¦
ä¾ã¨ãã¦ãRDSã®TLSéä¿¡ç¨CA証ææ¸ã®å®ç¾©ãããã¾ãã
export class CaCertificate {  // Enum likeãªãã¡ã¯ããªã¼ã¡ã½ãã  public static readonly RDS_CA_2019 = CaCertificate.of('rds-ca-2019');  // ã³ã³ã¹ãã©ã¯ã¿ä»£ããã®æè»ãªãã¡ã¯ããªã¼ã¡ã½ãã   public static of(identifier: string) { return new CaCertificate(identifier); } // constructorå®ç¾©  // constructorã¯privateãªããã.of()çµç±ã§ã®ã¤ã³ã¹ã¿ã³ã¹çæã®ã¿è¡ãã  private constructor(private readonly identifier: string);  // ã¡ã³ãå¤æ°ã®getter  public toString(): string { return this.identifier;  } }
ã¦ã¼ã¶ã¼ã¯ä»¥ä¸ã®ããã«ä½¿ããã¨ãã§ãã¾ãã
// äºåã«å®ç¾©ããããã¼ã¸ã§ã³ã®è¨¼ææ¸ãä½æ const ca2019Cert1 = CaCertificate.RDS_CA_2019; // æªå®ç¾©ã®è¨¼ææ¸ã使ãããå ´åãstringãã¿æ¸ãã§å®ç¾© const ca2019Cert2 = CaCertificate.of('rds-ca-2019');
ãã®ããã«Enumã®ããã«ã«äºåå®ç¾©ããããã¼ã¸ã§ã³ã®ãã¡ã¯ããªã¼ã¡ã½ãããå¼ã³åºãã¾ããã.of()
ã使ããã¨ã§èªç±ãªstringã渡ããã¨ãã§ãã¾ãã
åç´ãªEnumã§ãä¼¼ããã¨ã¯å®ç¾ã§ãã¾ããã.of()
ã«ããæªå®ç¾©ã®stringãè¨å®ã§ããã®ãEnum like classã®å¼·ã¿ã§ãããã¼ã¸ã§ã³ã追å ãæ¿ããenumã®æ´æ°ãéã«åããªããããªã±ã¼ã¹ã«å½¹ç«ã¤ã¨æãã¾ãã
.of()ã¨ãgetterã£ã¦å¿ è¦ï¼
åæ§ãªãã¨ã¯ãconstructorãpublicã«ãããã¨ã§ãå®ç¾ã§ãã¾ãã
export class CaCertificate {  public static readonly RDS_CA_2019 = new CaCertificate('rds-ca-2019'); // constructorå®ç¾©  public constructor(public readonly identifier: string); }
CDKã®ãã¶ã¤ã³ã¬ã¤ãã§ã¯ãã¡ãã®æ¸ãæ¹ãç´¹ä»ãã¦ãã¾ããããå®è£ éãå°ãªãã®ã§ããã§ããããããªãããªãã¨æã£ã¦ã¾ãã
ã¡ãã£ã¨å°è©±
æ¬å®¶CDKã§ã¯ãæ°ãã¼ã¸ã§ã³åºããã³ã«ãã¡ã¯ããªã¼ã¡ã½ãã追å ãã¦ããã®ã£ã¦ããªãªããªãï¼ãããããªãï¼ãã¨ããã¡ã³ããããã¾ãããä»ã®ã¨ããã¯æ°ãã¼ã¸ã§ã³ã追å ããPRãã©ãã©ããã¼ã¸ããã¦ãã¾ãã ãã®ã¿ã¤ãã®PRã¯ã¨ã£ã¦ãç°¡åãªã®ã§ãæªå¯¾å¿ãªãã®ã«æ°ã¥ããããã²ã³ã³ããªãã¥ã¼ããã¦ã¿ã¾ãããï¼
è¤æ°ã®å¼æ°ãã¾ã¨ããclass
L1ã«è¤æ°ã®å¼æ°ã渡ãã¨ãããããããå¯æ¥ã«é¢ããåããããªã±ã¼ã¹ãåå¨ãã¾ãã ãã®è¤éæ§ãclasså ã«éãè¾¼ããã¦ã¼ã¶ã¼ã«ä½è¨ãªè² æ ããããªããã¨ãç®æãã¾ãã
ãã¡ããå®ä¾ãå ã«èª¬æãã¾ãã
 EFSã®ã¬ããªã±ã¼ã·ã§ã³è¨å®
EFS(Elastic File System)ã§ã¯å¥ã®ãã¡ã¤ã«ã·ã¹ãã ã¸ã®èªåã¬ããªã±ã¼ã·ã§ã³è¨å®ãè¡ããã¨ãã§ãã¾ãã ã¬ããªã±ã¼ã·ã§ã³å ã®ãã¡ã¤ã«ã·ã¹ãã ã¨ãã¦ã¯ä»¥ä¸ã®3ãã¿ã¼ã³ãããã¾ãã
- EFSããã¼ã¸ããªMulti AZãã¡ã¤ã«ã·ã¹ãã (Regional)
- EFSããã¼ã¸ããªSingle AZãã¡ã¤ã«ã·ã¹ãã (One Zone)
- ã¦ã¼ã¶ã¼ç®¡çã®ãã¡ã¤ã«ã·ã¹ãã (Existing)
ããããã®å ´åã«ããã¦ãL1ã§ã®ãã©ã¡ã¼ã¿ã«ã¯ä»¥ä¸ã®å¤ãè¨å®ãã¾ãã
ã¬ããªã±ã¼ã·ã§ã³ã¿ã¤ã | fileSystemId | region | availabilityZoneName |
---|---|---|---|
Regional | undefined | ãªã¼ã¸ã§ã³å | undefined |
One Zone | undefined | ãªã¼ã¸ã§ã³å | AZå |
Existing | ã¬ããªã±ã¼ã·ã§ã³å ã®ãã¡ã¤ã«ã·ã¹ãã ID | undefined | undefined |
åç´ã«ãããã®L1ããããã£ãL2ã®ããããã£ã¨ãã¦å ¨ã¦é²åºãããå ´åãã¦ã¼ã¶ã¼ã¯ãã®çµã¿åããéãã®å¼æ°ãèªèº«ã§ä½æããå¿ è¦ãããã¾ãã
// Regional const regionalConfig = { region: 'ap-northeast-1' }; // One Zone const oneZoneConfig = { region: 'ap-northeast-1', availabilityZoneName: 'ap-northeast-1a' }; // Existing const existingConfig = { fileSystemId: 'file-system-id' };
ãã®ãªãã¸ã§ã¯ãã«å¯¾ãã¦ãä¸é©åãªçµã¿åããã«å¯¾ããL2å ã§ã®ããªãã¼ã·ã§ã³ããã£ããå®è£ ã¯ãã¾ããããã¾ã使ãããããã®ã§ããã¨ã¯è¨ããªãããã§ãã ããã§ããã®è¤éããã¯ã©ã¹å ã«éãè¾¼ããç´æçãªãã¡ã¯ããªã¼ã¡ã½ããã§è¨å®ãä½æã§ããããã«ãã¾ãã
æçµçãªã¦ã¼ã¶ã¼å´ã§ã®ä½¿ãæ¹ã¯ãã¡ãã§ãã
// Regional File System // å¼æ°ã®regionåã¯çç¥å¯è½ããã®å ´åãã¹ã¿ãã¯ããããã¤ããããªã¼ã¸ã§ã³ãèªåã§æå®ãããã const regionalCofig = efs.ReplicationConfiguration.regionalFileSystem('ap-northeast-1'); // One Zone File System const efsManagedSingleAzCofig = efs.ReplicationConfiguration.oneZoneFileSystem('us-east-1', 'us-east-1a'); // Existing File System declare const destinationFileSystem: efs.FileSystem; const userManagedConfig = efs.ReplicationConfiguration.existingFileSystem(destinationFileSystem);
åãã¿ã¼ã³ãã¨ã«public static
ãªãã¡ã¯ããªã¼ã¡ã½ãããç¨æãããã¨ã§ãå¿
è¦ãªå¼æ°ã ããæ£ç¢ºã«è¨å®ãããã¨ãã§ãã¾ãã
èªåã§è¨å®ãä½æãããããé¥ãã«ä½¿ãããããªã¼ã¨æã£ã¦ããã ããã§ããããã
ãããå®ç¾ããããã®å®è£
ã¯ä»¥ä¸ã®ã¨ããã§ããèªç±ãªè¨å®ã§ã®ã¤ã³ã¹ã¿ã³ã¹ãä½ãããªããããæ½è±¡ã¯ã©ã¹(ReplicationConfig
class)ã¨ãã¦å®ç¾©ããä¸ã§ãåè¨å®ç¨ã®ã¯ã©ã¹ã¯æ½è±¡ã¯ã©ã¹ã®å
·è±¡ã¯ã©ã¹ã¨ãã¦å®ç¾©ãã¦ãã¾ãã
// ã¬ããªã±ã¼ã·ã§ã³è¨å®ç¨ã®æ½è±¡ã¯ã©ã¹ãå®ç¾© export abstract class ReplicationConfiguration { public static existingFileSystem(destinationFileSystem: IFileSystem): ReplicationConfiguration { return new ExistingFileSystem({ destinationFileSystem }); } public static regionalFileSystem(region?: string): ReplicationConfiguration { return new RegionalFileSystem({ region }); } public static oneZoneFileSystem(region: string, availabilityZone: string): ReplicationConfiguration { return new OneZoneFileSystem({ region, availabilityZone }); } public readonly destinationFileSystem?: IFileSystem; public readonly region?: string; public readonly availabilityZone?: string; constructor(options: ReplicationConfigurationProps) { this.destinationFileSystem = options.destinationFileSystem; this.region = options.region; this.availabilityZone = options.availabilityZone; } } // æ½è±¡ã¯ã©ã¹ãextendsããåãã¿ã¼ã³ãã¨ã®classãå®ç¾© // ã¦ã¼ã¶ã¼ç®¡çãã¡ã¤ã«ã·ã¹ãã ç¨ class ExistingFileSystem extends ReplicationConfiguration { constructor(props: ExistingFileSystemProps) { super(props); } } // EFS管çMultiAZãã¡ã¤ã«ã·ã¹ãã class RegionalFileSystem extends ReplicationConfiguration { constructor(props: RegionalFileSystemProps) { super(props); } } // EFS管çSingleAZãã¡ã¤ã«ã·ã¹ãã class OneZoneFileSystem extends ReplicationConfiguration { constructor(props: OneZoneFileSystemProps) { super(props); } }
åçãªãã¨ã¯ãæ½è±¡ã¯ã©ã¹ã使ããã¨ãconstructor
é¢æ°ãprivateã«ãããã¨ã§ãå®ç¾ã§ãã¾ãããã¡ãã®æ¹ãå®è£
éã¯æ¸ãã®ã§è¦éãã¯ç«ã¡ãããã¨æãã¾ãã
export class ReplicationConfiguration { public static existingFileSystem(destinationFileSystem: IFileSystem): ReplicationConfiguration { return new ReplicationConfiguration({ destinationFileSystem }); } public static regionalFileSystem(region?: string): ReplicationConfiguration { return new ReplicationConfiguration({ region }); } public static oneZoneFileSystem(region: string, availabilityZone: string): ReplicationConfiguration { return new ReplicationConfiguration({ region, availabilityZone }); } public readonly destinationFileSystem?: IFileSystem; public readonly region?: string; public readonly availabilityZone?: string; private constructor(options: ReplicationConfigurationProps) { this.destinationFileSystem = options.destinationFileSystem; this.region = options.region; this.availabilityZone = options.availabilityZone; } }
å人çã«ã¯å¾è ã好ããªã®ã§ãããã¡ã³ããã«ã¯åè ã®æ¹æ³ãæ¨å¥¨ããã¾ããããªã«ãçç±ãããããããã¾ããã
ãã¶ã¤ã³ã¬ã¤ãã¨ã®ä¹é¢
CDKã®ãã¶ã¤ã³ã¬ã¤ãã§ã¯ãå¯è½ãªéãå¼æ°ã¯ä¸¦åã«å®ç¾©ããããªãã¼ã·ã§ã³ã§å®ç¾©ãã¿ã¼ã³ãä¿è¨¼ããã®ãæ¨å¥¨ããã¦ãã¾ãã(synthã§ä¸é©åãªè¨å®ãåãã)
ããããå®éåé¡ã¨ãã¦ã¯ã¯ã©ã¹ã«å¶ç´ãéãè¾¼ããã»ãããTypeScriptã®éç解æã®æç¹ã§ããªãã¼ã·ã§ã³ãè¡ããããé¥ãã«ä½¿ããããã¨æã£ã¦ãã¾ãã æ¬æ¥ã¯Javaãªã©ã®å¥è¨èªã«å¤æããã¨ãã«ä½¿ãããã(ï¼)ãã¨ãçç±ãããã§ãããæå¤ã¨CDKã®ã¡ã³ããããã¶ã¤ã³ã¬ã¤ãã¨ã¯éã®ææãããæ¹éã«ãªãã¤ã¤ããã¾ããå人çã«ãããã¶ã¤ã³ã¬ã¤ãã«å¼ã£å¼µãããããã«PRãéã£ã¦ããã¨è¯ãããªã¨æãã¾ãã
ãã®ä»ã®å®è£ ä¾ãããããããã¾ãããããã«public staticãªã¡ã½ããã§ç´æçã«ã¤ã³ã¹ã¿ã³ã¹ãä½ããããã«ãªãããå ±éãããã¤ã³ãã§ãã
å人çã«å¥½ããªåèå®è£ ä¾ãããã¤ãç½®ãã¦ããã¾ãã
-
- ããçã®ããstringã®çæããé常ã«ç´æçãªå¼æ°ã§å®ç¾ãã¦ãã¾ãã
-
- æ¥é ããççã«
Duration.minutes(5)
ã¨å¼ã³åºãã¦ãã¾ããããpublic staticãªãã¡ã¯ããªã¼ã¡ã½ããã§ãããã¨ãæè¿ã¾ã§æèãã¦ãã¾ããã§ãããã
- æ¥é ããççã«
æå¾ã«
è¨äºå ã§ç´¹ä»ããEFSã®ã¬ããªã±ã¼ã·ã§ã³è¨å®ã«ã¤ãã¦ã¯ãAWSCDKã®å ¬å¼Roadmapå ã§"åªããã³ãã¥ããã£ããã®è²¢ç®"ã¨ãã¦ç´¹ä»ããã¾ããããã¼ãï¼
"""Below are some of the great contributions from the community! """
åç´ã«L1ã®å¼æ°ããã®ã¾ã¾L2ã«é²åºãããã ãã§ã¯ãªããä»åç´¹ä»ããããã«ã¦ã¼ã¶ãã¬ã³ããªã¼ãªãã¡ã¯ããªã¼ã¡ã½ãããç¨æããã¨ãããè©ä¾¡ããã ããã®ããªã¨æã£ã¦ãã¾ãã
ãã¼ããããã«ç¶ç¶ãã¦PRãç´¹ä»ãã¦ãããããããå¼ãç¶ãã¡ããã¡ããã¨ã³ã³ããªãã¥ã¼ããã¦ãããããªã¨æã£ã¦ãã¾ãã
追è¨
CDKã®ãã¶ã¤ã³ã¬ã¤ãã«ãããFlatã«ã¼ã«ã¯ããã¹ãããå¼æ°ãè¨å®ãããã¨ãé¿ããã¨ãããã®ã§ããã
// For example, instead of: new Bucket(this, 'MyBucket', { bucketWebSiteConfiguration: { errorDocument: '404.html', indexDocument: 'index.html', } }); // Prefer: new Bucket(this, 'MyBucket', { websiteErrorDocument: '404.html', websiteIndexDocument: 'index.html' });
ä»åã®EFSã®ã±ã¼ã¹ã§ã¯Interfaceã§å®ç¾©ããreplicationConfigurationã1ã¤ã®ã¯ã©ã¹ã§åãåãããã«ããã®ã§ãããããã¶ã¤ã³ã¬ã¤ãã«åã£ã¦ããã®ããããã¾ãã(ï¼)ã
// before new FileSystem(this, 'FileSystem', { replicationConfiguration: { region: 'us-east-1', availabilityZoneName: 'us-east-1a' }, }), // after new FileSystem(this, 'FileSystem', { replicationConfiguration: ReplicationConfiguration.oneZoneFileSystem('us-east-1', 'ud-east-1a'), }),