AWS CDK Constructs
Overview
AWS CDK(Cloud Development Kit) allows you to use common programming languages to model your application infrastructure.
A basic building block when using CDK is a construct. A construct represents a reusable "cloud component" encapsulating everything AWS needs to create the component. It can represent a single AWS resource, such as an Amazon Simple Storage Service (Amazon S3) bucket or be a higher-level abstraction consisting of multiple related AWS resources.
Stacktape allows you to extend your infrastructure by adding AWS CDK constructs to stacktape resources. AWS resources which are part of the construct are then deployed together with other AWS resources created by Stacktape.
To learn more about constructs refer to AWS docs. Furthermore, Construct Hub is a resource to help you discover additional constructs from AWS, third parties, and the open-source CDK community.
Usage
Currently, Stacktape supports using constructs written in Javascript or Typescript. You can create your custom construct
by extending Construct
class.
Copy
import { Duration } from 'aws-cdk-lib';import * as sns from 'aws-cdk-lib/aws-sns';import * as subs from 'aws-cdk-lib/aws-sns-subscriptions';import * as sqs from 'aws-cdk-lib/aws-sqs';import { Construct } from 'constructs';export class MyConstruct extends Construct {constructor(scope: Construct, id: string, props?: { visibilityTimeout: number }) {super(scope, id);const queue = new sqs.Queue(this, 'Queue', {visibilityTimeout: Duration.seconds(props?.visibilityTimeout || 300)});const topic = new sns.Topic(this, 'Topic');topic.addSubscription(new subs.SqsSubscription(queue));}}
Example construct (containing multiple AWS resources)
Copy
resources:myConstruct:type: aws-cdk-constructproperties:entryfilePath: my-construct.tsexportName: MyConstructconstructProperties:visibilityTimeout: 50
Referencing construct in Stacktape config