Skip to content

ClusterlessHQ/clusterless-commons

Repository files navigation

Clusterless Commons

Maven Central javadoc javadoc

A set of Java APIs for building cloud based applications.

  • clusterless-commons-core - Utilities and helpers for consistent naming and temporal operations.
  • clusterless-commons-aws - Utilities and base Constructs for AWS CDK applications.

For use with JDK 11+.

Core

Naming

Consistent, human-readable, names are important for usability and maintainability of cloud applications. In many cases names must be unique to a region, account, or globally.

Label

The Label class is for making labels, String for use in different contexts.

Label id = Label.of("project").with("version");

id.camelCase(); // projectVersion
id.lowerHyphen(); // project-version
id.lowerColonPath(); // project:version

There are a few flavors of Label:

  • Fixed - retains the original value
  • Partition - allows for key=value pairs within each path element
  • Region - for declaring AWS regions
  • Stage - for declaring deployment stages
  • Version - for declaring versions

Label is an interface that can be implemented by specialized classes. Use Label.EnumLabel to create label enums.

Ref

Ref is used to create a unique export name for a resource.

A Ref can represent

  • id - the id of the exported resource (like a vpc id)
  • name - the physical name of the exported resource (like S3 bucket name)
  • arn - the AWS Arn of the exported resource

A Ref takes the form of:

aws:qualifier:[stage:]scopeName:scopeVersion:resourceNS:resourceType:resourceName

The ScopedConstruct class provides a way to create Refs for child resources of the construct.

Temporal

Provides IntervalUnit implementations of:

  • Fourths - 15 minute intervals
  • Sixths - 10 minute intervals
  • Twelfths - 5 minute intervals

These intervals are used by Clusterless to label lots.

There is also a IntervalDateTimeFormatter for formatting dates and times of these intervals.

Collection

Provides a few Collection helpers:

  • OrderedMaps - The same as Maps.of() but retains the order of the keys
  • OrderedSafeMaps - The same as OrderedMaps.of() but retains the order of the keys and ignores null values
  • SafeList - The same as List.of() but ignores null values

OrderedMaps is especially useful when the hashing order could change even if the key values don't. When creating many CDK Constructs, Map instances are required. Using OrderedMaps.of() will ensure the order of the keys is retained to prevent a deployment from being unnecessarily triggered.

AWS

This module provides AWS specific related classes centered around simplifying the naming, exporting, and tagging of resources.

Naming

  • ArnsRefs - ArnRefs provides a utility for resolving ARN references from a Ref or ARN string.
  • ResourceNames - Provides methods for creating unique resource names.

Scoped

A set of classes for creating Stacks and Constructs scoped to:

  • stage - the current deployment stage
  • name - the name of the application
  • version - the version of the application

There are also methods to create Refs for exported resources, or to import resources via a stringified Ref or Arn.

Names are generated from these values to prevent collisions across deployments within an account, or across accounts.

  • ScopedApp - A CDK App scoped to stage, name, and version.
  • ScopedStack - A CDK Stack scoped to stage, name, and version by virtue of being a child of a ScopedApp.
  • ScopedConstruct - A CDK Construct scoped to stage, name, and version by virtue of being a child of a ScopedStack.

Construct

Util

  • TagsUtil - A utility for applying tags to AWS resources.

The TagsUtil can be disabled to speed up deployments for stacks that have a large number of resources, in order to speed the deployment during development.

About

APIs for building things in the cloud.

Resources

License

Stars

Watchers

Forks

Languages