A utility for defining constructs without ever needing to think about scope. "Concise" constructs are interoperable with classical constructs. The difference is cosmetic; if concise constructs better-jive with your API-design sensibilities, great! Otherwise, classical constructs are still state of the art.
NOTE: this repo follows SemVer and there is yet to be a major release; the public API can still change.
NOTE: JSII cannot yet package concise constructs for consumption in non-TypeScript CDK projects.
- Guide →
An explanation of the mechanics - Rest API Example →
Using Lambda & API Gateway - GraphQL API →
Using AppSync, Lambda Resolvers & DynamoDB
To execute an example, run
npm run example [example-dir] [command](for example,npm run example graphql-api deploy)
Node users can install with npm.
npm install concise-constructsPackaged as CommonJS, alongside corresponding type definitions.
import{C}from"concise-constructs";import*ascdkfrom"@aws-cdk/core";import*aslambdafrom"@aws-cdk/aws-lambda";importpathfrom"path";constcode=newlambda.AssetCode(path.resolve(__dirname,"lambda"));constStack=C(cdk.Stack,(define)=>({fn: define`my-fn`(lambda.Function,{
code,handler: "index.handler",runtime: lambda.Runtime.NODEJS_12_X,}),}));constApp=C(cdk.App,(define)=>{define`my-stack`(Stack);});newApp().synth();... is equivalent to the following.
import*ascdkfrom"@aws-cdk/core";import*aslambdafrom"@aws-cdk/aws-lambda";importpathfrom"path";constcode=newlambda.AssetCode(path.resolve(__dirname,"lambda"));classStackextendscdk.Stack{fn;constructor(scope: cdk.App,id: string){super(scope,id);this.fn=newlambda.Function(this,"my-fn",{
code,handler: "index.handler",runtime: lambda.Runtime.NODEJS_12_X,});}}classAppextendscdk.App{constructor(){super();newStack(this,"my-stack");}}newApp().synth();import{C}from"concise-constructs";import*ascdkfrom"@aws-cdk/core";import*assqsfrom"@aws-cdk/aws-sqs";import*assnsfrom"@aws-cdk/aws-sns";constStack=C(cdk.Stack,(define)=>{constqueue=define`HelloCdkQueue`(sqs.Queue,{visibilityTimeout: cdk.Duration.seconds(300),});consttopic=define`HelloCdkTopic`(sns.Topic);topic.addSubscription(newsubs.SqsSubscription(queue));return{queue, topic};});constApp=C(cdk.App,(define)=>{conststack=define`my-stack`(Stack);stack.queue;// sqs.Queuestack.topic;// sns.Topic});... is equivalent to the following.
import*ascdkfrom"@aws-cdk/core";import*assqsfrom"@aws-cdk/aws-sqs";import*assnsfrom"@aws-cdk/aws-sns";classHelloCdkStackextendscdk.Stack{queue;topic;constructor(scope: cdk.App,id: string){super(scope,id,props);this.queue=newsqs.Queue(this,"HelloCdkQueue",{visibilityTimeout: cdk.Duration.seconds(300),});this.topic=newsns.Topic(this,"HelloCdkTopic");topic.addSubscription(newsubs.SqsSubscription(this.queue));}}classAppextendscdk.App{constructor(){super();conststack=newStack(this,"my-stack");stack.queue;// sqs.Queuestack.topic;// sns.Topic}}newApp().synth();import{C}from"concise-constructs";import*ascdkfrom"@aws-cdk/core";import*aseventsfrom"@aws-cdk/aws-events";import*aslambdafrom"@aws-cdk/aws-lambda";import*astargetsfrom"@aws-cdk/aws-event-targets";constcode=newlambda.AssetCode(path.resolve(__dirname,"lambda"));constStack=C(cdk.Stack,(define)=>{constlambdaFn=define`singleton`(lambda.Function,{
code,handler: "index.handler",timeout: cdk.Duration.seconds(300),runtime: lambda.Runtime.PYTHON_3_6,});construle=define`rule`(events.Rule,{schedule: events.Schedule.expression("cron(0 18 ? * MON-FRI *)"),});rule.addTarget(newtargets.LambdaFunction(lambdaFn));});constApp=C(cdk.App,(define)=>{conststack=define`my-stack`(Stack);});newApp().synth();... is equivalent to the following.
import*ascdkfrom"@aws-cdk/core";import*aseventsfrom"@aws-cdk/aws-events";import*aslambdafrom"@aws-cdk/aws-lambda";import*astargetsfrom"@aws-cdk/aws-event-targets";constcode=newlambda.AssetCode(path.resolve(__dirname,"lambda"));classStackextendscdk.Stack{constructor(scope: cdk.App,id: string){super(scope,id);constlambdaFn=newlambda.Function(this,"singleton",{
code,handler: "index.handler",timeout: cdk.Duration.seconds(300),runtime: lambda.Runtime.PYTHON_3_6,});construle=newevents.Rule(this,"rule",{schedule: events.Schedule.expression("cron(0 18 ? * MON-FRI *)"),});rule.addTarget(newtargets.LambdaFunction(lambdaFn));}}classAppextendscdk.App{constructor(){newStack(this,"my-stack");}}newApp().synth();See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.