ç®æ¬¡
å ã«ã¾ã¨ã
- 2024/12/7 ã«ãªãªã¼ã¹ããã AWS CDK ã® v2.172.0 㧠Aspects ã®ä»æ§ãå¤æ´ããã
- ãåªå
度(priority)ã 㨠ãStabilization ã«ã¼ãã ã¨ãã 2 ã¤ã®æ©è½ãå°å
¥ããã
- Stabilization ã«ã¼ãã¯ãæ©è½ãã©ã°ã true ã®å ´åã«æå¹ã«ãªãï¼åªå 度ã¯æ©è½ãã©ã°ã«é¢ãããå¹ãï¼
- ãã ããã®æ©è½ãã©ã°ã¯é常ã®æ©è½ãã©ã°ã¨éããæ¢åããã¸ã§ã¯ãã§ãè©²å½ CDK ãã¼ã¸ã§ã³ã«æããéã«èªåçã« true ã«ãªã
- Aspects ã« ãæ´æ°(Mutating)ã 㨠ãèªã¿åãå°ç¨(Readonly)ã ã¨ãã 2 種é¡ã®æ¦å¿µãçã¾ãã
Aspects ã¨ã¯
Aspects ã¨ã¯ãããã¹ã¿ãã¯ãã³ã³ã¹ãã©ã¯ãã¨ãã£ããç¹å®ã®ã¹ã³ã¼ãå ã®å ¨ã¦ã®æ§æã«æä½ãé©ç¨ããæ¹æ³ã§ãã
ä¾ãã°ããã¹ã¿ãã¯å ã®å ¨ã¦ã® S3 ãã±ããã«ãã¼ã¸ã§ãã³ã°è¨å®ãé©ç¨ããã¦ãããããªã©ã®ãããªããªãã¼ã·ã§ã³ãè¡ãããå ´åã«ä½¿ããã¨ãã§ãã¾ãã
â»æ¬è¨äºã§ã¯ãAspects èªä½ã®æ¦å¿µãæ©è½ããAspectsããAspects ã®å®è£ ã»ã¯ã©ã¹ããAspectãã¨è¡¨è¨ãã¦ãã¾ãã
import { App, Aspects, IAspect, Stack, Tokenization } from 'aws-cdk-lib'; import { CfnBucket } from 'aws-cdk-lib/aws-s3'; import { IConstruct } from 'constructs'; // Aspectã¯IAspectã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®è£ ãããã¨ã§å®ç¾ãã export class BucketVersioningChecker implements IAspect { // visitã¡ã½ããã«ããªãã¼ã·ã§ã³ã®å 容ãè¨è¿°ãã public visit(node: IConstruct) { // Aspectã«ãã£ã¦æ¸¡ãããConstructã®å é¨ã®ãªã½ã¼ã¹å ¨ã¦ã«visitã¡ã½ãããé©ç¨ãããã®ã§ãCfnBucketãªã½ã¼ã¹ã®å ´åã«ã®ã¿å®è¡ãããããæ¡ä»¶åå²ããã if (node instanceof CfnBucket) { // ãã±ããã®ãã¼ã¸ã§ãã³ã°è¨å®ãç¡å¹ã®å ´åãã¨ã©ã¼ãçºçããã if ( !node.versioningConfiguration || (!Tokenization.isResolvable(node.versioningConfiguration) && node.versioningConfiguration.status !== 'Enabled') ) { throw new Error('ãã¼ã¸ã§ãã³ã°ãæå¹ã«ãªã£ã¦ãã¾ãã'); } } } } const app = new App(); const stack = new Stack(app, 'MyStack'); // MyStackå ã®å ¨ã¦ã®ãªã½ã¼ã¹ã«å¯¾ãã¦BucketVersioningCheckerãé©ç¨ Aspects.of(stack).add(new BucketVersioningChecker());
CDK ã®ã©ã¤ããµã¤ã¯ã«
AWS CDK ã®ã©ã¤ããµã¤ã¯ã«ã«ã¯ã以ä¸ã® 4 ã¤ã®ãã§ã¼ãºãããã¾ãã
- Construct ãã§ã¼ãº
- Prepare ãã§ã¼ãº
- Validate ãã§ã¼ãº
- Synthesize ãã§ã¼ãº
ã¦ã¼ã¶ã¼ã®æ¸ã CDK ã³ã¼ãã®ã»ã¨ãã©ï¼ãªã½ã¼ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã®çæãªã©ï¼ã¯ Construct ãã§ã¼ãºã§å®è¡ããã¾ãã
Aspects 㯠Construct ãã§ã¼ãºãçµãã£ãå¾ã® Prepare ãã§ã¼ãºã§å®è¡ãããAspect ã¯ã©ã¹ã® visit ã¡ã½ãããã¤ã¾ã Aspect ã®å¦çãèµ°ãã¾ãã
ãã®ãããAspect ã¤ã³ã¹ã¿ã³ã¹ãçæãããã¿ã¤ãã³ã°ã§ã¯ Aspect ã®å¦çã¯å®è¡ãããªããã¨ã«æ³¨æãå¿ è¦ã§ããï¼Aspect ã¤ã³ã¹ã¿ã³ã¹çæãããå¾ã®ãªã½ã¼ã¹ã®ã¤ã³ã¹ã¿ã³ã¹çæãªã©ãå ¨ã¦çµãã£ãå¾ã«å®è¡ããããï¼
ã©ã¤ããµã¤ã¯ã«ã«é¢ãã詳細ã¯ä»¥ä¸ã®è¨äºãã覧ãã ããã
ä»æ§å¤æ´ã®èæ¯(åé¡ç¹)
ä»åã® Aspects ã®ä»æ§å¤æ´ãè¡ãããã¾ã§ã¯ã以ä¸ã® 2 ã¤ã®ã±ã¼ã¹ã§åé¡ãããã¾ããã
åé¡ 1. Aspect å ã§ä¸ä½ãã¼ãã«æ°ãããªã½ã¼ã¹ãä½æããã±ã¼ã¹
1 ã¤ç®ã®åé¡ã¨ã¯ããä¸ä½ãã¼ã(Construct ããè¦ãã¹ã¿ãã¯ãªã©)ã«ãªã½ã¼ã¹ã追å ãã Aspectãã¨ãããªã¼å ¨ä½ã®ãªã½ã¼ã¹ãèµ°æ»ãã Aspectãã¨ãããå ´åã«ãåè ã® Aspect ã§è¿½å ããããªã½ã¼ã¹ããããªã¼å ¨ä½ã辿ã£ã¦èµ°æ»ããå¾è ã® Aspect ã§èµ°æ»ãããªããã¨ããåé¡ã§ããã
å ·ä½çã«ã¯ã以ä¸ã®ãããªã±ã¼ã¹ã§çºçãã¦ãã¾ããã
- æ°ãããªã½ã¼ã¹ãã¹ã¿ãã¯ã«è¿½å ãã Aspect ããã¹ã¿ãã¯å ã® Construct ã«é©ç¨
- å ¨ã¦ã®ãªã½ã¼ã¹ãèµ°æ»ããå¥ã® Aspect ããã¹ã¿ãã¯ã«é©ç¨
ã¨ããã®ããä»ã¾ã§ã® Aspects ã¯ãã³ã³ã¹ãã©ã¯ãããªã¼ã®æä¸ä½ã®ãã¼ãã«é©ç¨ããã Aspect ãããããªã¼ã辿ãããã«ä¸ã®ãã¼ãããé çªã«ããããã®ãã¼ãã® Aspect ãå®è¡ãã¦ãããããªå é¨å®è£ ã«ãªã£ã¦ãã¾ããã
â»å½æã® CDK æ¬ä½ã®è©²å½ã³ã¼ã:
ã¤ã¾ããå¾è ã® Aspect ã¯ããä¸ä½ã§ããã¹ã¿ãã¯ã«é©ç¨ããã¦ããããå ã«å®è¡ãããå ¨ã¦ã®ãªã½ã¼ã¹ãèµ°æ»ãçµããå¾ã«åè ã® Aspect ã«ãã£ã¦æ°ãããªã½ã¼ã¹ã追å ãããããããã®ãããªåé¡ãçºçãã¦ãã¾ããã
ã¾ããã®äºè±¡ã«ã¯ãAspect ã«ãã£ã¦æ¢åã®ã³ã³ã¹ãã©ã¯ãããªã¼ã«æ°ãããã¼ãï¼ãªã½ã¼ã¹ï¼ã追å ãã¦ããä»ã® Aspect ã§ã¯ãã®æ°ãããã¼ãã追å ãããåã®ã³ã³ã¹ãã©ã¯ãããªã¼ã辿ãã¨ãããã¨ãé¢ä¿ãã¦ãã¾ãã
ã³ã¼ãä¾ã¨ãã¦ã¯ã以ä¸ã®ãããªã±ã¼ã¹ãæãããã¾ãã(â»å¾è¿°ãã issue ã«è¨è¼ã®ã³ã¼ãä¾ãå°ãå¤æ´ãã¦ä½¿ç¨ãã¦ãã¾ãã)
import { Aspects, Tags, IAspect, Stack, StackProps } from 'aws-cdk-lib'; import { Bucket } from 'aws-cdk-lib/aws-s3'; import { Construct, IConstruct } from 'constructs'; export class CdkIssueStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); // ã¹ã¿ãã¯å ¨ä½ãèµ°æ»ãã¦ã¿ã°ã追å (ã¿ã°ã追å ãã Aspect ãã¹ã¿ãã¯ã«é©ç¨) // ãããæåã«å®è¡ããã(addå ãä¸çªä¸ã®ãã¼ãã§ããã¹ã¿ãã¯ã®ãã) Tags.of(this).add('test-tag', 'test-value'); new MyConstruct(this, 'MyConstruct'); } } class MyConstruct extends Construct { constructor(scope: IConstruct, id: string) { super(scope, id); const stack = Stack.of(scope); // ã¹ã¿ãã¯ç´ä¸ã«ä½æ new Bucket(stack, 'BucketWithTags'); // ãªã½ã¼ã¹ãä¸ä½ãã¼ãã§ããã¹ã¿ãã¯ã«è¿½å ãã Aspect ããã® Construct ã«é©ç¨ // ããã 2 çªç®ã«å®è¡ããã(addå ãã¹ã¿ãã¯ããä¸ä½ãã¼ãã§ããConstructã®ãã) Aspects.of(this).add(new MyDynAspect()); } } class MyDynAspect implements IAspect { private processed = false; public visit(node: IConstruct): void { // ä¸åº¦ã ãå¼ã³åºãããã®æ¡ä»¶åå² if (!this.processed) { // ä¸ä½ãã¼ãã§ããã¹ã¿ãã¯ã®ç´ä¸ã« Bucket ãä½æ const stack = Stack.of(node); new Bucket(stack, 'BucketWithoutTagsThatShouldHave'); this.processed = true; } } }
ããã¯ä¸è¨ã§èª¬æããã©ã¤ããµã¤ã¯ã«ã«æ²¿ã£ã¦å®è¡ããã¾ããå ·ä½çã«ã¯ Construct ãã§ã¼ãºã§ BucketWithTags ãçæãããPrepare ãã§ã¼ãºã§ã¿ã°ã®ä»ä¸ã¨ BucketWithoutTagsThatShouldHave ã®çæãå®è¡ããã¾ããããã¯ãTags ã¯å é¨çã« Aspects ã使ç¨ããã¦ãã¦ããã®ã¨ãAspects 㯠Prepare ãã§ã¼ãºã§å®è¡ãããããã§ãã
ãã®ã³ã¼ãã«ããåæå¾ã®ããªã¼ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
- Stack
- BucketWithTags
- ã¿ã°æ
- BucketWithoutTagsThatShouldHave
- ã¿ã°ç¡
- BucketWithTags
ãããæ¬æ¥ã¯ BucketWithoutTagsThatShouldHave ã«ãã¿ã°ãé©ç¨ãããã¹ãã§ãããã¨ãããããªåé¡æèµ·ãããã¾ããã
åé¡ 2. è¤æ°ã® Aspect ãåãã³ã³ã¹ãã©ã¯ãã«é©ç¨ãããã±ã¼ã¹
ä¸è¨ã®åé¡ 1 ã¯ãã³ã³ã¹ãã©ã¯ãããªã¼ã«ãããåãã¼ãã®èµ°æ»é åº(ã¨ãAspect ã§è¿½å ããããªã½ã¼ã¹ã¯å¥ã® Aspect ã§ã¯èµ°æ»ãããªãç¹)ã«èµ·å ããåé¡ã§ããã
ä¸æ¹ã§ããã¡ãã®åé¡ 2 ã§æããåé¡ã¯ãAspect ã®å¼ã³åºãé åºã«èµ·å ããåé¡ã§ããã¤ã¾ããè¤æ°ã® Aspect ãåãã³ã³ã¹ãã©ã¯ãã«å¯¾ãã¦é©ç¨ããã¦ããå ´åã«ããããã® Aspect ã®å¼ã³åºãé åºã«é¢ããåé¡ã«ãªãã¾ãã
以ä¸ã® Aspect æ§æã®ãããªã±ã¼ã¹ããã£ãã¨ãã¾ãã
- ValidateEncryptionAspect
- å ¨ã¦ã® S3 ãã±ããã§æå·åãæå¹ããã¦ãããã¨ãæ¤è¨¼
- DefaultEncryptionAspect
- å ¨ã¦ã® S3 ãã±ããã«ããã©ã«ãæå·åãè¨å®
- EnvironmentBasedEncryptionAspect
- ç°å¢å¤æ°ã«åºã¥ã㦠S3 ãã±ããã®æå·åãå¤æ´
ãã®ã±ã¼ã¹ã§ã¯ã以ä¸ã®ãããªåé¡ãçºçããå¯è½æ§ãããã¾ãã
- ValidateEncryptionAspect ãæåã«å®è¡ãããããDefaultEncryptionAspect ãã¾ã é©ç¨ããã¦ããªããã失æãã
- DefaultEncryptionAspect 㯠EnvironmentBasedEncryptionAspect ã«ãã£ã¦ä¸æ¸ãããã
- ValidateEncryptionAspect 㯠EnvironmentBasedEncryptionAspect ã«ãã£ã¦è¨å®ãããæçµçãªæå·åæ§æã確èªã§ããªã
ããã¾ã§ã® Aspects ã¯ä¸è¨ã®ããã«é©ç¨ãããé ã«å®è¡ããã¦ãã¾ããããããæè»ã«ã³ã³ããã¼ã«ã§ããè¦ç´ ãããã¨è¯ãã¯ãã§ããä¾ãã°ä¸è¨ã®ä¾ã§ããã¨ãValidateEncryptionAspect ãä¸çªæåã« add ãããã©ãä¸çªæå¾ã«å®è¡ãããã±ã¼ã¹ãå®ç¾ãããã¨ã§ãã
æ°ããä»æ§
2024/12/7 ã«ãªãªã¼ã¹ããã v2.172.0 ã§ãä¸è¨ã®åé¡ã解決ããããã« Aspects ã®ä»æ§ãå¤æ´ããã¾ããã
ãã® Aspects ã®ä»æ§ã®å¤æ´ç¹ã¯ 2 ã¤ããã¾ãã
ä»æ§ 1. åªå 度(priority)ã®å°å ¥
ãåªå 度(priority)ã ã¨ããæ©è½ãå°å ¥ãããConstruct ããªã¼å ¨ä½ã«æ¸¡ã£ã¦ãåªå 度ã®é«ã(priority ã®æ°å¤ãå°ãã) Aspect ãåªå 度ã®ä½ã(priority ã®æ°å¤ã大ãã) Aspect ãããå ã«é©ç¨ããããã¨ãä¿è¨¼ãããããã«ãªãã¾ããã
ããã¯ã主ã«ä¸è¨ã§æããåé¡ 2 ã解決ããããã«å°å ¥ããããAspect ãé©ç¨ãããé çªãæå®ã§ããããã«ããããã®ä»æ§ã§ãã(â»åé¡ã®é çªãä»æ§ã®é çªãéãªã®ã§æ³¨æ)
ã¾ããã®ãåªå 度(priority)ãã«ä½µãã¦ãæ§ã 㪠Construct ã©ã¤ãã©ãªéã®ä¸è²«æ§ãæ ä¿ããããã«ãAspects ã«ãæ´æ°(Mutating)ãã¨ãèªã¿åãå°ç¨(Readonly)ãã® 2 種é¡ã®æ¦å¿µãæ°ãã«çã¾ãã¾ããã
ããã§ãã ãæ´æ°(Mutating)ã ã¨ã¯ãã³ã³ã¹ãã©ã¯ãããªã¼ã«æ°ãããã¼ã(ãªã½ã¼ã¹)ã追å ãããæ¢åã®ãã¼ããå¤æ´ãããã®ããèªã¿åãå°ç¨(Readonly)ã ã¯ããªã¼ã®å¤æ´ã¯ããªãæ¤æ»(æ¤è¨¼)ãªã©ã®ãã®ã§ãã
ãã® 2 種é¡ã®æ¦å¿µã®å®è£
ã¨ãã¦ãããã©ã«ãã®åªå
度ãã¾ãæ´æ°ç¨ Aspect ãèªã¿åãå°ç¨ Aspect ã®åªå
度ã¨ãã¦ã®æ°å¤ãAspectPriority
ã¯ã©ã¹ã® static ããããã£(CDK æ¬å®¶ã§ã¯ Enum-Like Class ã¨å¼ã°ãã¾ã)ã¨ãã¦å®ç¾©ããã¦ãã¾ãã
å ·ä½çãªå¤ã¯ä»¥ä¸ã®ããã«å®ç¾©ããã¦ããããæ´æ°(MUTATING)ãâãããã©ã«ã(DEFAULT)ãâãèªã¿åãå°ç¨(READONLY)ãã®é ã«é©ç¨ãããåªå 度ãæå®ããªãå ´åã¯æ´æ°ç¨ Aspect ã®å¾ã»èªã¿åãå°ç¨ Aspect ã®åã«å®è¡ããããã¨ã«ãªãã¾ãã
/** * Default Priority values for Aspects. */ export class AspectPriority { /** * Suggested priority for Aspects that mutate the construct tree. */ static readonly MUTATING: number = 200; /** * Suggested priority for Aspects that only read the construct tree. */ static readonly READONLY: number = 1000; /** * Default priority for Aspects that are applied without a priority. */ static readonly DEFAULT: number = 500; }
ããã«åé¡ 2 ã®ãããªãåãã³ã³ã¹ãã©ã¯ãã«å¯¾ããè¤æ°ã® Aspect ã®é©ç¨é åºãã ãã§ãªããConstruct ããªã¼å ¨ä½ãéãã¦ã® Aspect ã®é©ç¨é åºãã³ã³ããã¼ã«ãããã¨ãã§ãã¾ãã
ä¾ãã°ä»¥åã¾ã§ã®ä»æ§ã ã¨ã以ä¸ã®ããã«ãããªã½ã¼ã¹ãæ¤æ»ãã Aspectï¼èªã¿åãå°ç¨ï¼ããä¸ä½ãã¼ãã§ããã¹ã¿ãã¯ã«é©ç¨ããããªã½ã¼ã¹ãæ´æ°ãã Aspectï¼æ´æ°ï¼ããä¸ä½ãã¼ãã§ããã³ã³ã¹ãã©ã¯ãã«é©ç¨ããå ´åãã³ã³ã¹ãã©ã¯ãããªã¼ã®ä¸ä½ã§ããåè ã®ãªã½ã¼ã¹æ¤æ»ã® Aspect ãæåã«èµ°ã£ã¦ãã¾ãã¾ããã
ãããä»åå°å
¥ãããåªå
度ãå©ç¨ãã¦ãåè
ã®ãªã½ã¼ã¹æ¤æ» Aspect ã®åªå
度ããå¾è
ã®ãªã½ã¼ã¹æ´æ° Aspect ãããä½ã(READONLY
㯠MUTATING
ããåªå
度ãä½ã/æ°å¤ã¯å¤§ãã)ãã¦ããããã¨ã§ãä¸ä½ãã¼ãã«é©ç¨ãããèªã¿åãå°ç¨ã§ãããªã½ã¼ã¹æ¤æ»ã® Aspect ãæå¾ã«èµ°ããããã¨ãã§ããããã«ãªãã¾ããã
import { Aspects, IAspect, Stack, StackProps, Tokenization, AspectPriority } from 'aws-cdk-lib'; import { Bucket, CfnBucket } from 'aws-cdk-lib/aws-s3'; import { Construct, IConstruct } from 'constructs'; export class CdkIssueStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); new MyConstruct(this, 'MyConstruct'); Aspects.of(this).add(new VersioningCheckAspect(), { priority: AspectPriority.READONLY }); } } class MyConstruct extends Construct { constructor(scope: IConstruct, id: string) { super(scope, id); new Bucket(this, 'BucketWithTags'); Aspects.of(this).add(new VersioningAspect(), { priority: AspectPriority.MUTATING }); } } class VersioningCheckAspect implements IAspect { public visit(node: IConstruct) { if (node instanceof CfnBucket) { if ( !node.versioningConfiguration || (!Tokenization.isResolvable(node.versioningConfiguration) && node.versioningConfiguration.status !== 'Enabled') ) { throw new Error('ãã¼ã¸ã§ãã³ã°ãæå¹ã«ãªã£ã¦ãã¾ãã'); } } } } class VersioningAspect implements IAspect { public visit(node: IConstruct): void { if (node instanceof CfnBucket) { if ( !node.versioningConfiguration || (!Tokenization.isResolvable(node.versioningConfiguration) && node.versioningConfiguration.status !== 'Enabled') ) { node.versioningConfiguration = { status: 'Enabled', }; } } } }
ä»æ§ 2. Stabilization ã«ã¼ãã®å°å ¥
Stabilization ã«ã¼ãã¨ã¯ãä¸è¨ã§æããåé¡ 1 ã解決ããããã®ãã®ã§ãAspects ã®å¼ã³åºãæã«ã³ã³ã¹ãã©ã¯ãããªã¼ã¸ã®é©ç¨ãè¤æ°åå®è¡ããä»çµã¿ã®ãã¨ã§ãã
主ã«ä»¥ä¸ã®ç¹å¾´ãããã¾ãã
- ã³ã³ã¹ãã©ã¯ãã«é©ç¨ããã Aspect ã§ãã®ã³ã³ã¹ãã©ã¯ããããä¸ä½ã®ãã¼ãã«æ°ãããªã½ã¼ã¹ãä½æããå ´åããå ã«å®è¡ãããä¸ä½ãã¼ã(ã¹ã¿ãã¯ãªã©) ã«é©ç¨ããã Aspect ã§ãã®è¿½å ãªã½ã¼ã¹ã®æ¤æ»ãã§ãã
- ä»ã® Aspect ã«ãã£ã¦ä½æããã Aspect ãå®è¡ã§ããï¼Aspect ã®ãã¹ãå®è¡ï¼
ç¹ã«åè ãåé¡ 1 ã®å¯¾å¿ã«å½ããã¾ãã
ä¸æ¹ãå¾è ã«é¢ãã¦ã§ãããå®ã¯ä»ã¾ã§ã¯ Aspect ã®ãã¹ãå®è¡ã¯ã§ããªãã£ãã®ã§ãã
å¾è ã® Aspect ã®ãã¹ãå®è¡ã®ä¾ã¨ãã¦ã以ä¸ã®ãããªã³ã¼ããæãããã¾ãã
class MyConstruct extends Construct { constructor(scope: IConstruct, id: string) { super(scope, id); Aspects.of(this).add(new ParentAspect()); } } class ParentAspect implements IAspect { public visit(node: IConstruct): void { Aspects.of(node).add(new MyDynAspect()); } } class MyDynAspect implements IAspect { private processed = false; public visit(node: IConstruct): void { if (!this.processed) { const stack = Stack.of(node); new Bucket(stack, 'BucketWithoutTagsThatShouldHave'); this.processed = true; } } }
ä¸è¨ã§ã¯ Stabilization ã«ã¼ãã¨ã¯ã³ã³ã¹ãã©ã¯ãããªã¼ã¸ã®é©ç¨ãè¤æ°åå®è¡ããä»çµã¿ã¨ãã説æããã¾ããããåããªã½ã¼ã¹ã«åã Aspect ã¯ä¸åº¦ããé©ç¨(å®è¡)ãããªãã®ã§å®å¿ãã¦ãã ããã
Aspect ã®å®è¡é åºã¯ã以ä¸ã®ç»åï¼RFC ã§æ示ãããç»åï¼ãåèã«ãªãã¾ãã
è£è¶³
Aspect æ å ±ã®åå¾ã¨åªå 度ã®ä¸æ¸ã
Aspect ãé©ç¨ããå¾ã«ããã®ã¹ã³ã¼ãã«é©ç¨ããã Aspect ã®ä¸è¦§ã¨ãã®æ
å ±ãAspects.of(scope).applied
ã§åå¾ã§ãã¾ãã
ãããã¯AspectApplication
ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã§ãaspect
ãconstruct
ãpriority
ã® 3 ã¤ã®ããããã£ãããã¾ãã
ã¾ããã®ã¤ã³ã¹ã¿ã³ã¹ãéãã¦ãAspect 宣è¨å¾ã«åªå 度ã®å¤ã®ä¸æ¸ããã§ãã¾ããä¸è¨ 3 ã¤ã®ããããã£ããããªã«ä½¿ã£ã¦æ¯è¼ãªã©ããã¦åªå 度ã®ä¸æ¸ãã«ä½¿ãã®ãè¯ãã§ãããã
const app = new App(); const stack = new MyStack(app, 'MyStack'); Aspects.of(stack).add(new MyAspect()); let aspectApplications: AspectApplication[] = Aspects.of(stack).applied; for (const aspectApplication of aspectApplications) { // The aspect we are applying console.log(aspectApplication.aspect); // The construct we are applying the aspect to console.log(aspectApplication.construct); // The priority it was applied with console.log(aspectApplication.priority); // Change the priority aspectApplication.priority = 700; }
æ©è½ãã©ã°
ä¸è¨ã§æãã 2 ã¤ã®ä»æ§å¤æ´ç¹ã®ãã¡ã2 ã¤ç®ã® ãStabilization ã«ã¼ãã®å°å ¥ãã¯æ©è½ãã©ã°ã true ã®å ´åã«é©ç¨ããã¾ããï¼â»1 ã¤ç®ã®ãåªå 度ãæ©è½ã¯æ©è½ãã©ã°ã®æç¡ã«é¢ãããé©ç¨ããããï¼
â»æ©è½ãã©ã°ã«é¢ãã¦ã¯ãå ¬å¼ããã¥ã¡ã³ããåç §ãã¦ãã ããã
é常ãæ©è½ãã©ã°ã¯ãæ°è¦ CDK ããã¸ã§ã¯ã(該å½æ©è½ãã©ã°ãå°å
¥ããã以éã®ãã¼ã¸ã§ã³ã® CDK ã§cdk init
ãããå ´å)ã§ã¯ããã©ã«ã㧠true ã«ãªããæ¢åã® CDK ããã¸ã§ã¯ãã§ã¯æ示çã«ãã®æ©è½ãã©ã°ã true ã§æå®ããªãéã false æ±ãã«ãªãã®ã§ããã®æ©è½ãæå¹ã«ããããã«ã¯èªåã§æå®ããå¿
è¦ãããã¾ãã
ãããããã® Stabilization ã«ã¼ãã®ããã®æ©è½ãã©ã°ã¯é常ã®æ©è½ãã©ã°ã¨éããæ¢åããã¸ã§ã¯ãã§ãè©²å½ CDK ãã¼ã¸ã§ã³ã«æããéã«ãèªåçã«ãtrue æ±ãã«ãªãã®ã§ã注æãå¿ è¦ã§ãã
â»ã½ã¼ã¹ã¯ä»¥ä¸ã®ãªã³ã¯ã«ãªãã¾ãã
ã¤ã¾ãä»åã® Stabilization ã«ã¼ãã¯ãæ°è¦ããã¸ã§ã¯ãã§ãæ¢åããã¸ã§ã¯ãã§ã CDK ãã¼ã¸ã§ã³ãä¸ããã¨èªåçã«æå¹ã«ãªããå¾æ¥éãã® 1 åã®ã¿ã®ã³ã³ã¹ãã©ã¯ãããªã¼ã®èµ°æ»ã«åãæ¿ããããã«ã¯æ示çã«æ©è½ãã©ã°ã false ã«ããå¿ è¦ãããã¾ãã
æ¢åã® CDK ããã¸ã§ã¯ã㧠AWS CDK ã®ãã¼ã¸ã§ã³ã v2.172.0 以ä¸ã«ãããã¤ãStabilization ã«ã¼ãã®å°å ¥ãã®æ©è½ãã©ã°ãããªãã«ãè¨å®ãããå ´åã以ä¸ã®ããã«ãã¾ããï¼æå¹ã«ãããå ´åãCDK ãã¼ã¸ã§ã³ãä¸ãã以å¤ã«ä½ãããå¿ è¦ã¯ããã¾ãããï¼
cdk.json
ã®context
ã«"@aws-cdk/core:aspectStabilization": false
ã追å ãã
{ // ... // ... "context": { // ... // ... "@aws-cdk/core:aspectStabilization": false } }
åç §
ä»åã® Aspects ã®ä»æ§å¤æ´ã«é¢ãã¦ãå ã¨ãªã£ã issue ããããã«å¯¾ãã¦æåºããã RFCããã㦠PR ãããã¾ãããèå³ãããã¾ããããã²ã覧ãã ããã
issue
PR
RFC
æå¾ã«
Aspects 㯠CDK ã®ä¸ã§ãç¹ã«ä¾¿å©ãªæ©è½ã§ãããä»åã®ä»æ§å¤æ´ã«ãã£ã¦ãããæè»ã«ã³ã³ã¹ãã©ã¯ãããªã¼ãèµ°æ»ã§ããããã«ãªãã¾ããã
ãã®ãããAspects ã使ã£ã¦ããã³ã¼ããè¦ããããããã²ãã®è¨äºãåèã«ãã¦ã¿ã¦ãã ããã