Scaffolding

Now We are going to be scaffolding a new subproject within the monorepo by configuring the .projenrc.ts

You can find an example of how your construct should look in the .projenrc.ts file as a functioning, dynamodb-table construct has been filled in already.

Here is a boilerplate declaration of a s3 bucket construct to help you get started.

You’ll need to fill in the gaps, anything with ‘[CUSTOMISE]’ is free for you to alter. For a guide, please see the below the code snippet to assess what values you’ll need to be aware of.

new awscdk.AwsCdkConstructLibrary({
  author: 'DTS Digital Platform Factory Team',
  authorAddress: 'DTS-Digital-Platform-Factory@curtin.edu.au',
  cdkVersion: '2.50.0',
  typescriptVersion: '4.8.4',
  defaultReleaseBranch: 'main',
  name: '[CUSTOMISE]',
  parent: parentProject,
  outdir: '[CUSTOMISE]',
  description: '[CUSTOMISE]',
  keywords: [[CUSTOMISE], [CUSTOMISE], [CUSTOMISE], [CUSTOMISE],],
  repositoryUrl: 'https://bitbucket.org/lifecycle-sandpit/cdk-pattern-template/src/main/',
  packageManager: NodePackageManager.NPM,
  tsconfig: {
    compilerOptions: {
      noUnusedLocals: false,
    },
  },
  tsconfigDev: {
    ...commonTsConfigDev,
  },
  devDeps: [
    ...commonDevDeps, //If an additional dependency is required, add before '...commonDevDeps'
  ],
  peerDeps: [
    ...commonPeerDeps, //If an additional dependency is required, add before '...commonPeerDeps'
  ],
  eslintOptions: {
    ...commonEslintOptions, //Shouldn't be modified
  },
});

Add your new construct definition to the .projenrc.ts file at the root of the project folder structure e.g. assembly-line-cdk-base-lib


The following properties must be set:

name

The name of the construct. • Remove any previous library prefix e.g. base- • Use the appropriate scope e.g. @assembly-line-base, see Lesson 5: Project Structure for more info. Example:

name: '@assembly-line-base/apigateway-restapi'

parent

parentProject - this links it to the parent. Projen.rc needs to contain a reference to its parent but in this project it is already defined. Example:

parent: parentProject,

outdir

The directory where the code for the construct should be created. All constructs live in their own folder within the constructs folder Example:

'constructs/dynamodb-table'

description

A useful description of what the construct does - this appears in the ConstructHub entry for the particular construct. Example:

description: 'This Base Construct produces an AWS DynamoDb Table',

keywords

This is a string array of searchable terms for users to be able to find your construct. It should include the name of the library to which it belongs [‘base’, ‘integration’, ‘experiences] along with each type of AWS resource that it creates, e.g. ‘S3’ Example:

keywords: ['CDKv2', 'DynamoDb', 'base construct', 'amazon DynamoDb', 'DynamoDb Table'],

devDeps & peerDeps

These arrays are used to specify specific dependencies for your construct. They contain the common default ones required to compile and use your construct but you add any construct specific ones here. Example:

  devDeps: [
    ...commonDevDeps,
  ],
  peerDeps: [
    ...commonPeerDeps,
  ],
You must be logged into CodeArtifact, so that projen can resolve the dependencies. Each construct library has a script that will do this for you!

Run the following command to create your empty construct in the output folder specified in the previous step:

npx projen

Assuming you have not removed the Dynamo-db table from the repo, you should see the following output: Text confirming a Projen activation