CDK - Escape Hatches

 높은 수준의 구문이나 낮은 수준의 CFN 리소스 구문에는 원하는 특정 기능이 없을 수 있습니다.

  1. AWS CloudFormation 을 통해 AWS Service를 사용할 수 있지만 서비스에 대한 생성 클래스가 없는 경우 
  2. AWS CloudFormation 을 통해 AWS Service를 사용할 수 있지만 서비스에 대한 생성 클래스가 있지만 아직 기능을 노출하지 않은 경우
  3. AWS CloudFormation 을 통해 AWS Service 기능을 아직 사용할 수 없는 경우

AWS CloudFormation을 통해 기능을 사용할 수 있는지 확인하려면 아래 링크를 참고하세요.

AWS Resource and Property Types Reference.

Using AWS CloudFormation Constructs Directly

서비스에 사용할 수 있는 생성 클래스가 없는경우 모든 AWS CloudFormation 리소스와 속성에 1:1 매핑되어 있는 CFN 리소스를 사용할 수 있습니다. 동등한 AWS CloudFormation 리소스를 사용하는 것과 똑같이 인스턴스를 생성합니다.

예를 들어 저수준 Amazon S3 버킷 CFN 리소스를 인스턴스화하려면 다음과 같이 작성합니다.

new s3.CfnBucket(this'MyBucket', {
  analyticsConfigurations: [
    {
      id: 'Config',
      // ...       
    }
  ]
});

Modifying the AWS CloudFormation Resource behind AWS Constructs

만약 construct에 기능이 없거나 문제를 해결하려는 경우 construct 에 의해 만들어진 CFN 리소스를 수정할 수 있습니다.

모든 construct 는 해당 CFN 리소스가 포함됩니다. CFN 리소스는 AWS CloudFormation 리소스에 직접 대응하므로 AWS CloudFormation을 통해 사용 가능한 모든 기능을 노출합니다. 

CFN 리소스 클래스에 액세스하기 위한 기본 접근 방식은 아래와 같습니다.

// Get the AWS CloudFormation resource
const cfnBucket = bucket.node.defaultChild as s3.CfnBucket;
 
// Change its properties
cfnBucket.analyticsConfiguration = [
  {
    id: 'Config',
    // ...       
  }
];

이 객체를 사용하여 Metadata 및 UpdatePolicy 와 같은 AWS CloudFormation 옵션을 변경할 수도 있습니다.

cfnBucket.cfnOptions.metadata = {
  MetadataKey: 'MetadataValue'
};

Raw Overrides

CFN 자원에서 누락 된 특성이 있는 경우 모든 입력을 무시할 수 있습니다.

또한 합성된 속성을 삭제할 수 있습니다.

다음은 addOverride 메소드를 사용한 예제입니다.

// Get the AWS CloudFormation resource
const cfnBucket = bucket.node.defaultChild as s3.CfnBucket;
 
// Use dot notation to address inside the resource template fragment
cfnBucket.addOverride('Properties.VersioningConfiguration.Status''NewStatus');
cfnBucket.addDeletionOverride('Properties.VersioningConfiguration.Status');
 
// addPropertyOverride is a convenience function, which implies the
// path starts with "Properties."
cfnBucket.addPropertyOverride('VersioningConfiguration.Status''NewStatus');
cfnBucket.addPropertyDeletionOverride('VersioningConfiguration.Status');

Custom Resources

AWS CloudFormation을 통해 구성할수 없는 인프라의 경우 AWS CloudFormation의 사용자 지정 리소스를 작성하는 것입니다.

사용자 지정 리소스를 작성하려면 리소스의 CREATE, UPDATE 및 DELETE 수명주기 이벤트에 응답하는 Lambda 함수를 작성해야합니다. 자세한 내용은 아래 링크를 확인하세요.


댓글

이 블로그의 인기 게시물

CDK - Assets

About VPC

dailyFocus - Frontend