AWS ServiceCatalogApp Registry 构造库
本单元中更高层次的构件的API是实验性的并正在积极开发中. 在今后任何版本中,它们都须作非背向相容的修改或去除。 这些是 不适用 语义版本 模型和断开的更改 在发行笔记中宣布. 这意味着虽然你可能使用它们,但可能需要更新 当更新到此软件包的更新版本时,您的源代码.
AWS 服务目录应用程序注册 使各组织能够创建和管理应用程序和相关资源的储存库.
目录
这个 @aws-cdk/aws-servicecatalogappregistry-alpha 软件包包含使用户能够对其AWS资源进行大规模自动化治理和管理的资源.
import * as appreg from '@aws-cdk/aws-servicecatalogappregistry-alpha';
应用
一个 AppRegistry 应用程序允许您定义您的应用程序和相关资源. 申请名称必须在账户级别上独有,且不可改变.
const application = new appreg.Application(this, 'MyFirstApplication', {
applicationName: 'MyFirstApplicationName',
description: 'description for my application', // the description is optional
});
堆栈外已创建的应用程序可以导入到您的 CDK 应用程序中 .
应用程序可通过 ARN 导入 Application.fromApplicationArn() API : (英语)
const importedApplication = appreg.Application.fromApplicationArn(
this,
'MyImportedApplication',
'arn:aws:servicecatalog:us-east-1:012345678910:/applications/0aqmvxvgmry0ecc4mjhwypun6i',
);
应用程序协理员
ApplicationAssociator 定义 AppRegistry 应用程序,以包含通过您的 cdk 软件包部署的所有堆栈。 这有助于管理所有
cdk 部署的资源.
创建一个新应用程序来连接 cdk 中的所有堆栈 。 App 范围
如果您想要创建名为应用程序 MyAssociatedApplication 账户 123456789012 区域 us-east-1
并想要将所有堆栈连接到 App 范围至 MyAssociatedApplication,然后使用如下示例所示:
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'MyAssociatedApplication',
// 'Application containing stacks deployed via CDK.' is the default
applicationDescription: 'Associated Application description',
stackName: 'MyAssociatedApplicationStack',
// AWS Account and Region that are implied by the current CLI configuration is the default
env: { account: '123456789012', region: 'us-east-1' },
})],
});
这将创建一个堆栈 MyAssociatedApplicationStack 包含应用程序 MyAssociatedApplication
与 TagKey 作为 managedBy 财务报告和审定财务报表 TagValue 作为 CDK_Application_Associator。 。 。 .
默认情况下,堆栈将拥有系统管理应用程序管理器Control URL作为其创建应用程序的输出. 如果您想要删除输出, 请使用以下示例 :
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'MyAssociatedApplication',
// 'Application containing stacks deployed via CDK.' is the default
applicationDescription: 'Associated Application description',
stackName: 'MyAssociatedApplicationStack',
// Disables emitting Application Manager url as output
emitApplicationManagerUrlAsOutput: false,
// AWS Account and Region that are implied by the current CLI configuration is the default
env: { account: '123456789012', region: 'us-east-1' },
})],
});
导入已有的应用程序来连接 cdk 中的全部堆栈 。 App 范围
如果您想要用 ARN 重用已有的应用程序 : arn:aws:servicecatalog:us-east-1:123456789012:/applications/applicationId
并想要将所有堆栈连接到 App 范围,然后使用如下示例所示:
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.existingApplicationFromArn({
applicationArnValue: 'arn:aws:servicecatalog:us-east-1:123456789012:/applications/applicationId',
stackName: 'MyAssociatedApplicationStack',
})],
});
关联属性组 : ApplicationAssociator
如果您想要将属性组与创建于 ApplicationAssociator,然后使用如下示例所示:
import * as cdk from "aws-cdk-lib";
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'MyAssociatedApplication',
// 'Application containing stacks deployed via CDK.' is the default
applicationDescription: 'Associated Application description',
stackName: 'MyAssociatedApplicationStack',
// AWS Account and Region that are implied by the current CLI configuration is the default
env: { account: '123456789012', region: 'us-east-1' },
})],
});
// Associate application to the attribute group.
associatedApp.appRegistryApplication.addAttributeGroup('MyAttributeGroup' , {
attributeGroupName: 'MyAttributeGroupName',
description: 'Test attribute group',
attributes: {},
});
CDK管道部署的相干堆栈
如果您正在使用 CDK 管道来部署您的应用程序, 应用程序堆栈将位于阶段内,以及
应用 联系人无法找到他们。 打电话 associateStage 在添加到
管道,如下例所示:
import * as cdk from "aws-cdk-lib";
import * as codepipeline from "aws-cdk-lib/pipelines";
import * as codecommit from "aws-cdk-lib/aws-codecommit";
declare const repo: codecommit.Repository;
declare const pipeline: codepipeline.CodePipeline;
declare const beta: cdk.Stage;
class ApplicationPipelineStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) {
super(scope, id, props);
//associate the stage to application associator.
props.application.associateStage(beta);
pipeline.addStage(beta);
}
};
interface ApplicationPipelineStackProps extends cdk.StackProps {
application: appreg.ApplicationAssociator;
};
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'MyPipelineAssociatedApplication',
stackName: 'MyPipelineAssociatedApplicationStack',
env: { account: '123456789012', region: 'us-east-1' },
})],
});
const cdkPipeline = new ApplicationPipelineStack(app, 'CDKApplicationPipelineStack', {
application: associatedApp,
env: {account: '123456789012', region: 'us-east-1'},
});
关联交叉账户堆栈
默认情况下,应用程序协会不会执行与目标应用程序的交叉账户堆栈关联,
避免未为交叉账户协会设立的账户出现部署失败.
为建立跨账户的堆栈协会,确保所有账户都与账户在同一个组织内
目标应用程序的账户以及资源分享在组织内得以实现.
如果您希望启动交叉账户共享和协会,请设定 associateCrossAccountStacks 字段改为 true, (中文(简体) ),
如下例所示:
const app = new App();
const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
associateCrossAccountStacks: true,
applicationName: 'MyAssociatedApplication',
env: { account: '123456789012', region: 'us-east-1' },
})],
});
关联跨区域堆栈
目前,跨区域堆栈协会不支持.
属性组
AppRegistry属性组作为应用程序用户定义属性的容器. 元数据以机器可读格式附后,与自动化工作流程和工具相融合. 属性组名必须是账户级别上独有的,且不可改变.
const attributeGroup = new appreg.AttributeGroup(this, 'MyFirstAttributeGroup', {
attributeGroupName: 'MyFirstAttributeGroupName',
description: 'description for my attribute group', // the description is optional,
attributes: {
project: 'foo',
team: ['member1', 'member2', 'member3'],
public: false,
stages: {
alpha: 'complete',
beta: 'incomplete',
release: 'not started'
}
}
});
在堆栈外已创建的属性组可导入您的 CDK 应用程序 .
属性组可以通过 ARN 通过 AttributeGroup.fromAttributeGroupArn() API : (英语)
const importedAttributeGroup = appreg.AttributeGroup.fromAttributeGroupArn(
this,
'MyImportedAttrGroup',
'arn:aws:servicecatalog:us-east-1:012345678910:/attribute-groups/0aqmvxvgmry0ecc4mjhwypun6i',
);
协会
您可以将您的应用程序与属性组和资源关联 . 资源是 CloudFormation 堆栈, 您可以与应用程序关联到组相关 堆叠起来,使元数据能够对您的应用程序和资源有丰富的见解. 一个 Cloudform 堆栈只能与一个应用程序相联. 如果一个堆栈与您的应用程序中的多个应用程序相关联或已经与一个应用程序相关联, CDK在部署时会失败 .
将应用程序与新属性组连接
您可以创建属性组并将其关联到应用程序 addAttributeGroup() API : (英语)
declare const application: appreg.Application;
declare const attributeGroup: appreg.AttributeGroup;
application.addAttributeGroup('MyAttributeGroupId' , {
attributeGroupName: 'MyAttributeGroupName',
description: 'Test attribute group',
attributes: {},
});
将属性组与应用程序结合
您可以将应用程序与属性组关联到 associateWith数字 :
declare const application: appreg.Application;
declare const attributeGroup: appreg.AttributeGroup;
attributeGroup.associateWith(application);
将应用程序与堆栈连接
您可以将一个堆栈与应用程序连接到 associateApplicationWithStack() API : (英语)
const app = new App();
const myStack = new Stack(app, 'MyStack');
declare const application: appreg.Application;
application.associateApplicationWithStack(myStack);
共享
您可以与 AWS 组织,组织单位(OUs), AWS 组织内部的账户, 以及 IAM 角色和用户共享您的 AppRegistry 应用程序和属性组 。 AppRegistry 要求 AWS 组织在部署应用程序或属性组的共享之前在账户中启用.
共享应用程序
import * as iam from 'aws-cdk-lib/aws-iam';
declare const application: appreg.Application;
declare const myRole: iam.IRole;
declare const myUser: iam.IUser;
application.shareApplication('MyShareId', {
name:'MyShare',
accounts: ['123456789012'],
organizationArns: ['arn:aws:organizations::123456789012:organization/o-my-org-id'],
roles: [myRole],
users: [myUser],
});
例如,与多个账户共享应用程序,并允许账户与应用程序关联资源.
import * as iam from 'aws-cdk-lib/aws-iam';
declare const application: appreg.Application;
application.shareApplication('MyShareId', {
name: 'MyShare',
accounts: ['123456789012', '234567890123'],
sharePermission: appreg.SharePermission.ALLOW_ACCESS,
});
共享属性组
import * as iam from 'aws-cdk-lib/aws-iam';
declare const attributeGroup: appreg.AttributeGroup;
declare const myRole: iam.IRole;
declare const myUser: iam.IUser;
attributeGroup.shareAttributeGroup('MyShareId', {
name: 'MyShare',
accounts: ['123456789012'],
organizationArns: ['arn:aws:organizations::123456789012:organization/o-my-org-id'],
roles: [myRole],
users: [myUser],
});
例如,与多个账户共享一个应用程序,并允许账户将应用程序关联到属性组.
import * as iam from 'aws-cdk-lib/aws-iam';
declare const attributeGroup: appreg.AttributeGroup;
attributeGroup.shareAttributeGroup('MyShareId', {
name: 'MyShare',
accounts: ['123456789012', '234567890123'],
sharePermission: appreg.SharePermission.ALLOW_ACCESS,
});