Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Concise Constructs

npm versionlicensePRs welcome

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.


Resources

To execute an example, run npm run example [example-dir] [command] (for example, npm run example graphql-api deploy)

Installation

Node users can install with npm.

npm install concise-constructs

Packaged as CommonJS, alongside corresponding type definitions.

Snippets

Lambda Rest API

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();

SQS + SNS

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();

Lambda CRON

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();

Contributing

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

About

A functional-feeling DX for the AWS CDK and other construct libraries

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

38 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages