Package: alma-cdk.project
🚧Work-in-Progress: Breaking changes may occur at any given point duringv0.x.npmi-D@alma-cdk/projectOpinionated CDK “framework” with constructs & utilities for:deploying multiple environments to multiple accounts (with many-to-many relationship)managing account configuration through standardized props (no more random config files)querying account and/or environment specific information within your CDK codeenabling dynamic & short-lived “feature-environments”enabling well-defined taggingproviding structure & common conventions to CDK projectschoosing the target account & environment by passing in runtime context:npxcdkdeploy-caccount=dev-cenvironment=feature/abc-123... which means you don't need to define all the possibile environments ahead of time!Account StrategiesDepending on the use case, you may choose a configuration between 1-3 AWS accounts with the following environments:Shared account (shared):Multi-account (dev+prod)– RECOMMENDED:Multi-account (dev+preprod+prod):Getting StartedSteps required to define aenvironmentalproject resources; At first, it might seem complex but once you get into the habbit of defining your projects this way it starts to make sense:Choose yourAccount StrategyInitialize a newProjectinstead ofcdk.App://bin/app.tsimport{Project,AccountStrategy}from'@alma-cdk/project';constproject=newProject({//Basicinfo,youcouldalsoreadthesefrompackage.jsonifyouwantname:'my-cool-project',author:{organization:'Acme Corp',name:'Mad Scientists',email:'mad.scientists@acme.example.com',},//Ifnotset,defaultstooneof:$CDK_DEFAULT_REGION,$AWS_REGIONorus-east-1defaultRegion:'eu-west-1',//Configurestheprojecttouse2AWSaccounts(recommended)accounts:AccountStrategy.two({dev:{id:'111111111111',config:{//whateveryouwanthereas[string]:anybaseDomain:'example.net',},},prod:{id:'222222222222',config:{//whateveryouwanthereas[string]:anybaseDomain:'example.com',},},}),})Define a stack whichextends SmartStackwith resources://lib/my-stack.tsimport{Construct}from'constructs';import{StackProps,RemovalPolicy}from'aws-cdk-lib';import{SmartStack,Name,UrlName,PathName,EC}from'@alma-cdk/project';exportclassMyStackextendsSmartStack{constructor(scope:Construct,id:string,props?:StackProps){super(scope,id,props);newdynamodb.Table(this,'Table',{removalPolicy:EC.isStable(this)?RemovalPolicy.RETAIN:RemovalPolicy.DESTROY,tableName:Name.it(this,'MyTable'),partitionKey:{type:dynamodb.AttributeType.STRING,name:'pk',},//StagingMyTable});newevents.EventBus(this,'EventBus',{eventBusName:Name.withProject(this,'MyEventBus'),//MyCoolProjectStagingMyEventBus});news3.Bucket(this,'Bucket',{removalPolicy:EC.isStable(this)?RemovalPolicy.RETAIN:RemovalPolicy.DESTROY,autoDeleteObjects:EC.isStable(this)?false:true,bucketName:UrlName.globally(this,'MyBucket'),//acme-corp-my-cool-project-feature-foo-bar-my-bucket});newssm.StringParameter(this,'Parameter',{stringValue:'Foo',tier:ssm.ParameterTier.ADVANCED,parameterName:PathName.withProject(this,'MyNamespace/MyParameter'),///MyCoolProject/Staging/MyNamespace/MyParameter});}}Define a newenvironmentalwhichextends EnvironmentWrapperand initialize all your environmentalSmartStackstacks within://lib/environment.tsimport{Construct}from'constructs';import{EnvironmentWrapper}from'@alma-cdk/project';import{MyStack}from'./my-stack';exportclassEnvironmentextendsEnvironmentWrapper{constructor(scope:Construct){super(scope);newMyStack(this,'MyStack',{description:'This is required'});}}Resulting Stack properties (givenenvironment=staging):PropertyExample valuestackName"MyCoolProject-Environment-Staging-MyExampleStack"terminationProtectiontrueenv.account"111111111111"env.region"eu-west-1"Resulting Tags for the Stack and its resources (givenenvironment=staging):PropertyExample valueAccountdevEnvironmentstagingProjectmy-cool-projectAuthorMad ScientistsOrganizationAcme CorpContactmad.scientists@acme.example.comFinally initialize the environment with theProjectscope://bin/app.tsimport{Project,Accounts}from'@alma-cdk/project';import{Environment}from'../lib/environment';constproject=newProject({/*removedforbrevity,seestep1*/})newEnvironment(project);DocumentationSee detailed documentation for specific classes & methods atconstructs.dev.Generally speaking you would be most interested in the following:ProjectAccountStrategySmartStackAccountWrapper & EnvironmentWrapperAccountContext (AC)EnvironmentContext (EC)Name / UrlName / PathName