Component: Secrets - aws/codecatalyst-blueprints GitHub Wiki

Secrets are used in CodeCatalyst to store sensitive data that can be referenced in workflows. You can add a secret to your blueprint and reference it in your workflow.

In your blueprint.ts file, add the following:

import { Secret, SecretDefinition } from '@amazon-codecatalyst/blueprint-component.secrets'

Secrets component examples

Creating a secret

The following example creates a UI component that prompts the user to enter a secret value and optional description:

export interface Options extends ParentOptions {
    ...
    mySecret: SecretDefinition;
}


export class Blueprint extends ParentBlueprint {
  constructor(options_: Options) {
    new Secret(this, options.secret);
}

The secret component requires a name. The following code is the minimum required default shape:

{
    ...
    "secret": {
        "name": "secretName"
    },

}

Referencing a secret in a workflow

The following example creates a secret and a workflow that references the secret value. For more information, see Referencing a secret in a workflow.

export interface Options extends ParentOptions {
     /**
     * @validationRegex /^[-\w^&'@{}[\],$=!#().%+~ ]+$/
     */
     fileName: string;


     /**
     * @validationRegex /^\w+$/
     */
     username: string;


     password: SecretDefinition;
}


export class Blueprint extends ParentBlueprint {
  constructor(options_: Options) {
    const password = new Secret(this, options_.password);

    const workflowBuilder = new WorkflowBuilder(this, {
      Name: 'my_workflow',
    });


    workflowBuilder.addBuildAction({
      actionName: 'download_files',
      input: {
        Sources: ['WorkflowSource'],
      },
      output: {
        Artifacts: [{ Name: 'download', Files: [options_.fileName] }],
      },
      steps: [
        `curl -u ${options_.username}:${password.reference} -o ${options_.fileName} https://example.com`,
      ],
    });

    new Workflow(
      this,
      repo,
      workflowBuilder.getDefinition(),
    );

}

To learn more about using secrets in CodeCatalyst, see Working with secrets.