后台的 AWS 配置目录插件
这是后台的 AWS 配置目录插件 。 io 用于将 AWS 资源信息输入后台目录.
特征 :
- 从 AWS 配置自动添加 AWS 资源
- 使用增量摄取来有效摄取
说明: 可以轻易地将这个实体供应商配置成将大量实体摄入后台目录的方式。 请审查 考虑因素 下节.
说明: 如果您尚未使用 AWS 配置, 需要注意的是, 您启用此配置将产生成本 。 请审查定价信息, 然后再允许在您的 AWS 组织内使用 .
安装
本指南假设你熟悉将军 开始 并假设您已有后台应用程序.
在您的后台应用程序中安装后端软件包 :
yarn workspace backend add @backstage/plugin-catalog-backend-module-incremental-ingestion @aws/aws-config-catalog-module-for-backstage
将脚手架模块添加到 packages/backend/src/index.ts数字 :
const backend = createBackend();
// ...
backend.add(
import('@backstage/plugin-catalog-backend-module-incremental-ingestion'),
);
backend.add(import('@aws/aws-config-catalog-module-for-backstage'));
// ...
backend.start();
配置
将实体提供者添加到后台应用程序配置 :
providers:
awsConfig:
default: # Name of the provider
accountId: # [OPTIONAL] AWS account ID to use to access AWS Config API
region: # [OPTIONAL] AWS region to use to access AWS Config API
aggregator: # [OPTIONAL] The name of the AWS Config aggregator
hashEntityNames: # [OPTIONAL] Generated entity names will always be hashes of the ARN
filters: # Filter the resources queried from AWS Config API
tags: # [OPTIONAL] Match by tags on the AWS resources
- key: 'component' # Only retrieve resources that have a 'component' tag
- key: environment # Only retrieve resources that have a 'environment' tag with value 'prod'
value: prod
resourceTypes: # [REQUIRED] Filter by AWS resource type
- AWS::ECS::Cluster
- AWS::ECS::Service
- AWS::DynamoDB::Table
- AWS::RDS::DBCluster
- AWS::Lambda::Function
- AWS::ElasticLoadBalancingV2::LoadBalancer
- AWS::ApiGatewayV2::Api
- AWS::S3::Bucket
transform: # [OPTIONAL] Apply transformations to the emitted entity
fields: # Modify specific fields
name: # Customize the name field generated (see note below)
expression: $join([$resource.resourceName, $resource.accountId], '-')
annotations: # Add to metadata.annotations
accountId:
expression: $resource.accountId # Add an annotation with the AWS account ID using JSONata expression
spec:
owner:
tag: owner # Set 'spec.owner' to the value of the 'owner' tag on the AWS resource
component:
tag: component # Create a 'dependencyOf' relationshop based on the 'component' tag
system:
value: my-system # Set 'spec.system' to a hard-coded value of 'my-system'
options: # [OPTIONAL] Configure details of the provider behavior
incremental:
restLength: { hours: 6 } # Wait 6 hours between each ingestion cycle
由上述配置创建的实体将看起来像:
apiVersion: backstage.io/v1alpha1
kind: Resource
metadata:
annotations:
aws.amazon.com/arn: arn:aws:ecs:us-west-2:1234567890:service/my-cluster/my-app
aws.amazon.com/name: my-app
aws.amazon.com/region: us-west-2
aws.amazon.com/resource-id: arn:aws:ecs:us-west-2:1234567890:service/my-cluster/my-app
aws.amazon.com/resource-type: AWS::ECS::Service
name: my-app
description: AWS Config Resource AWS::ECS::Service my-app
spec:
owner: my-team
type: ecs-service
system: my-system
注:
metadata.name字段必须在您的后台实例中独有,否则实体会相互覆盖。 如果您的 AWS 资源命名已经是独一无二的, 那么您没有要采取的行动 。 如果您有AWS资源, 可能会有相冲突的名称, 那么您需要使用transform.fields.name转换配置值metadata.name字段为每个实体的独有之处.
考虑因素
它建议使用可用于摄取后台目录中必需的最低实体的配置. AWS Config,特别是在较大的组织中,可以追踪大量AWS资源,对摄入机制以及存储过的用户编目经验都有负面影响.
一般性建议如下:
- 使用
resourceTypes字段以限制想要的 AWS 服务。 如果需要,从1或2个资源类型开始,并逐渐增加更多,以评估对后台目录大小的影响. - 将摄入限制在单一的"环境"中,如中转或生产.
- 根据将摄入的资源数量适当配置摄入时间表.
JSONata 表达式
供应商改变实体的方法之一是使用 杰索纳塔 通过 expressions 字段。 这是根据AWS配置资源有效载荷中的任何字段对排放实体的字段进行转换的灵活方法.
AWS配置资源有效载荷可通过 $resource 变量.
以下是一个简单的示例, 用资源账户 ID 设置注释 :
transform:
fields:
annotations:
accountId:
expression: $resource.accountId
以下是一个更为复杂的例子,它只当资源是RDS DB集群时,才用 RDS 引擎版本设置注释:
transform:
fields:
annotations:
engineVersion:
expression: $resource.resourceType = "AWS::RDS::DBCluster" ? $resource.configuration.engineVersion
表达式必须返回 a string。 。 。 .
使用大小写
本节载有一些超出简单资源摄入范围的具体使用案例的例子.
EKS 分类群集定位器
后台 库伯涅特集群定位器 来自后台目录的Kubernetes集群信息,用于为Kubernetes插件提供动力. 这是一个比后台配置中配置集群更灵活的机制.
此实体提供者可用于生成 Resource 使用字段转换来兼容此插件的实体 :
providers:
awsConfig:
eksClusters:
filters:
tags: [...]
resourceTypes:
- AWS::EKS::Cluster
transform:
fields:
annotations:
'amazonaws.com/account-id':
expression: $resource.accountId
'amazonaws.com/arn':
expression: $resource.arn
'kubernetes.io/api-server':
expression: $resource.configuration.Endpoint
'kubernetes.io/api-server-certificate-authority':
expression: $resource.configuration.CertificateAuthorityData
'kubernetes.io/x-k8s-aws-id':
expression: $resource.resourceName
'kubernetes.io/auth-provider':
value: aws
spec:
owner:
tag: owner
component:
tag: component
type:
value: kubernetes-cluster
适当使用标记过滤集群 .