亚马逊 CodeCatalyst 不再向新买家开放。现有客户可以继续正常使用该服务。有关更多信息,请参阅 如何从中迁移 CodeCatalyst。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
向蓝图添加密钥组件
可以在 CodeCatalyst 中使用密钥来存储可在工作流中引用的敏感数据。您可以向自定义蓝图添加密钥并在工作流中引用该密钥。有关更多信息,请参阅 使用密钥遮蔽数据。
导入 Amazon CodeCatalyst 蓝图区域类型
在您的 blueprint.ts 文件中,添加以下内容:
import { Secret, SecretDefinition } from '@amazon-codecatalyst/blueprint-component.secrets'
创建密钥
以下示例创建了一个 UI 组件,该组件提示用户输入密钥值和可选描述:
export interface Options extends ParentOptions { ... mySecret: SecretDefinition; } export class Blueprint extends ParentBlueprint { constructor(options_: Options) { new Secret(this, options.secret); }
密钥组件需要 name。以下代码是所需的最低默认设置:
{ ... "secret": { "name": "secretName" }, }
在工作流中引用密钥
以下示例蓝图创建了一个密钥和一个引用该密钥值的工作流。有关更多信息,请参阅 在工作流中引用密钥。
export interface Options extends ParentOptions { ... /** * * @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: ['file1'] }], }, steps: [ `curl -u ${options_.username}:${password.reference} https://example.com`, ], }); new Workflow( this, repo, workflowBuilder.getDefinition(), ); }
要了解有关在 CodeCatalyst 中使用密钥的更多信息,请参阅使用密钥遮蔽数据。