Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 12x 12x 12x 12x 12x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 1x 124x 124x 124x 124x 124x 124x 124x 124x 124x 1x 1x 12x 12x 12x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 1x 1x 1x 1x 1x 1x | /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ import { IResolvable, IResource, Lazy, Names, Resource } from 'aws-cdk-lib'; import { CfnBroker, CfnConfiguration } from 'aws-cdk-lib/aws-amazonmq'; import { Metric, MetricOptions } from 'aws-cdk-lib/aws-cloudwatch'; import { ISecurityGroup, InstanceType, IVpc, SubnetSelection, Connections, Port, SecurityGroup } from 'aws-cdk-lib/aws-ec2'; import { IRole } from 'aws-cdk-lib/aws-iam'; import { IKey } from 'aws-cdk-lib/aws-kms'; import { LogRetention, RetentionDays } from 'aws-cdk-lib/aws-logs'; import { Construct } from 'constructs'; import { BrokerCloudwatchLogsExports } from './broker-cloudwatch-logs-exports'; import { BrokerDeploymentMode } from './broker-deployment-mode'; import { IBrokerConfiguration } from './configuration'; import { MaintenanceWindowStartTime } from './maintenance-window-start-time'; import { StorageType } from './storage-type'; export interface IBrokerDeployment extends IResource { readonly arn: string; readonly id: string; readonly name: string; readonly connections: Connections | undefined; /*** * @internal */ readonly _authenticationStrategy?: string; /*** * @internal */ readonly _engineVersion: string; metric(metricName: string, options?: MetricOptions): Metric; } export interface BrokerDeploymentProps { readonly key?: IKey; readonly brokerName?: string; /** * Specifies whether the broker is open to public Internet or deployed with * endpoints in own VPC. */ readonly publiclyAccessible: boolean; /** * vpcSubnets and vpc are optional. But when present - publiclyAccessible attribute must equal false. * * @default - undefined. If vpc is present - this attribute must be present. */ readonly vpcSubnets?: SubnetSelection; /** * The VPC in which create the communication endpoints for a private broker. * * @default - undefined. A default VPC will be used */ readonly vpc?: IVpc; /** * The Security Groups to apply for a non publicly accessible broker. * * NOTE: This needs to be set only if `publiclyAccessible` is true. * * @default - undefined. If no VPC is selected then a default VPC's default SG will be used. * Otherwise - a security group will be created. */ readonly securityGroups?: ISecurityGroup[]; /** * An instance type to use for the broker. Only a subset of available instance types is allowed. * * @see https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/broker-instance-types.html */ readonly instanceType: InstanceType; /** * Determines whether the broker will undergo a minor version upgrade during the maintenance window. * * @default - false. No minor version upgrade happens. */ readonly autoMinorVersionUpgrade: boolean; readonly maintenanceWindowStartTime?: MaintenanceWindowStartTime; /** * Sets the retention days for the broker's CloudWatch LogGroups * * @default - undefined; CloudWatch Log Groups retention is set to never expire */ readonly cloudwatchLogsRetention?: RetentionDays; readonly cloudwatchLogsRetentionRole?: IRole; } export enum BrokerEngine { RABBITMQ = 'RABBITMQ', ACTIVEMQ = 'ACTIVEMQ' } export interface BrokerDeploymentBaseProps extends BrokerDeploymentProps { readonly authenticationStrategy?: string; readonly version: string; readonly deploymentMode: BrokerDeploymentMode; readonly defaultPort?: Port; readonly engine: BrokerEngine; readonly storageType?: StorageType; readonly configuration?: IBrokerConfiguration; readonly cloudwatchLogsExports?: BrokerCloudwatchLogsExports; readonly users: CfnBroker.UserProperty[]; readonly ldapServerMetadata?: IResolvable | CfnBroker.LdapServerMetadataProperty; } export abstract class BrokerDeploymentBase extends Resource implements IBrokerDeployment { public readonly arn: string; public readonly id: string; public readonly name: string; /** @internal */ public readonly _authenticationStrategy?: string; /** @internal */ public readonly _engineVersion: string; /** @internal */ protected readonly _conns: Connections | undefined; /** @internal */ protected readonly _resource: CfnBroker; /** @internal */ protected _configuration: CfnConfiguration | undefined; private readonly cloudwatchLogsExports?: BrokerCloudwatchLogsExports; private readonly cloudwatchLogsRetention?: RetentionDays; private readonly cloudwatchLogsRetentionRole?: IRole; /** Manages connections for the cluster */ public get connections(): Connections | undefined { return this._conns; } constructor(scope: Construct, id: string, props: BrokerDeploymentBaseProps) { super(scope, id); this._authenticationStrategy = props.authenticationStrategy; this._engineVersion = props.version; this._conns = props.vpcSubnets && props.vpc ? new Connections({ defaultPort: props.defaultPort, securityGroups: props.securityGroups ?? [ new SecurityGroup(this, 'AMQ_SG', { description: `Automatic security group for broker ${Names.uniqueId(this)}`, vpc: props.vpc, allowAllOutbound: false, }), ], }) : undefined; this.name = props.brokerName ?? id; this._resource = new CfnBroker(this, 'Resource', { brokerName: this.name, configuration: Lazy.any({ produce: () => this._configuration && { id: this._configuration.ref, revision: this._configuration.attrRevision, }, }), engineType: props.engine, engineVersion: props.version, autoMinorVersionUpgrade: props.autoMinorVersionUpgrade, deploymentMode: props.deploymentMode, encryptionOptions: { kmsKeyId: props.key?.keyId, useAwsOwnedKey: props.key === undefined, }, maintenanceWindowStartTime: props.maintenanceWindowStartTime && { dayOfWeek: props.maintenanceWindowStartTime.dayOfWeek, timeOfDay: props.maintenanceWindowStartTime.timeOfDay, timeZone: props.maintenanceWindowStartTime.timeZone?.timezoneName, }, storageType: props.storageType, logs: props.cloudwatchLogsExports, hostInstanceType: `mq.${props.instanceType.toString()}`, publiclyAccessible: props.publiclyAccessible, securityGroups: this._conns?.securityGroups.map((sg) => sg.securityGroupId), subnetIds: props.vpc?.selectSubnets(props.vpcSubnets).subnetIds, users: props.users, authenticationStrategy: props.authenticationStrategy, ldapServerMetadata: props.ldapServerMetadata, }); this.arn = this._resource.attrArn; this.id = this._resource.ref; // TODO: this is ugly. Make it more self-explanatory this.cloudwatchLogsExports = props.engine === BrokerEngine.RABBITMQ && props.cloudwatchLogsExports && 'general' in props.cloudwatchLogsExports ? { general: true, channel: true, connection: true, mirroring: props.deploymentMode === BrokerDeploymentMode.CLUSTER_MULTI_AZ, } : props.cloudwatchLogsExports; this.cloudwatchLogsRetention = props.cloudwatchLogsRetention; this.cloudwatchLogsRetentionRole = props.cloudwatchLogsRetentionRole; if (props.configuration) { this._attachConfiguration(props.configuration); } this.configureLogRetention(); } public metric(metricName: string, options?: MetricOptions): Metric { return new Metric({ namespace: 'AWS/AmazonMQ', metricName, dimensionsMap: { Broker: this.id, }, ...options, }); } protected configureLogRetention() { const [logExports, retention, retentionRole] = [ this.cloudwatchLogsExports, this.cloudwatchLogsRetention, this.cloudwatchLogsRetentionRole, ]; if (logExports !== undefined && retention !== undefined) { const availableValues = ['general', 'audit', 'channel', 'connection', 'mirroring']; Object.entries(logExports) .filter(([log, enabled]: [string, boolean]) => availableValues.includes(log) && enabled) .map(([log, _]) => log) .forEach((log) => { new LogRetention(this, `LogRetention${log}`, { logGroupName: `/aws/amazonmq/broker/${this.id}/${log}`, retention, role: retentionRole, }); }); } } /*** * @internal */ protected _attachConfiguration(configuration: IBrokerConfiguration) { this._configuration = configuration.node.defaultChild as CfnConfiguration; this.node.addDependency(configuration); } } |