Skip to content

Commit 1bd1cec

Browse files
authored
Merge branch 'master' into master
2 parents 2cadfec + cac5726 commit 1bd1cec

11 files changed

Lines changed: 244 additions & 68 deletions

File tree

packages/@aws-cdk/aws-codecommit/lib/repository.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,23 @@ export interface IRepository extends IResource, notifications.INotificationRuleS
177177

178178
/**
179179
* Defines a CodeStar Notification rule which triggers when a pull request is merged.
180+
* @deprecated this method has a typo in its name, use notifyOnPullRequestMerged instead
180181
*/
181182
notifiyOnPullRequestMerged(
182183
id: string,
183184
target: notifications.INotificationRuleTarget,
184185
options?: notifications.NotificationRuleOptions,
185186
): notifications.INotificationRule;
186187

188+
/**
189+
* Defines a CodeStar Notification rule which triggers when a pull request is merged.
190+
*/
191+
notifyOnPullRequestMerged(
192+
id: string,
193+
target: notifications.INotificationRuleTarget,
194+
options?: notifications.NotificationRuleOptions,
195+
): notifications.INotificationRule;
196+
187197
/**
188198
* Defines a CodeStar Notification rule which triggers when a new branch or tag is created.
189199
*/
@@ -419,6 +429,14 @@ abstract class RepositoryBase extends Resource implements IRepository {
419429
id: string,
420430
target: notifications.INotificationRuleTarget,
421431
options?: notifications.NotificationRuleOptions,
432+
): notifications.INotificationRule {
433+
return this.notifyOnPullRequestMerged(id, target, options);
434+
}
435+
436+
public notifyOnPullRequestMerged(
437+
id: string,
438+
target: notifications.INotificationRuleTarget,
439+
options?: notifications.NotificationRuleOptions,
422440
): notifications.INotificationRule {
423441
return this.notifyOn(id, target, {
424442
...options,

packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ const repository = new codecommit.Repository(stack, 'MyCodecommitRepository', {
1414
const target = new sns.Topic(stack, 'MyTopic');
1515

1616
repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target);
17-
repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
17+
repository.notifyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
1818

1919
app.synth();

packages/@aws-cdk/aws-codecommit/test/notification-rule.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('notification rule', () => {
1414

1515
repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target);
1616

17-
repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
17+
repository.notifyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
1818

1919
expect(stack).toHaveResource('AWS::CodeStarNotifications::NotificationRule', {
2020
Name: 'MyCodecommitRepositoryNotifyOnPullRequestCreatedBB14EA32',

packages/@aws-cdk/aws-elasticsearch/lib/domain.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,22 +1273,16 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
12731273
const defaultInstanceType = 'r5.large.elasticsearch';
12741274
const warmDefaultInstanceType = 'ultrawarm1.medium.elasticsearch';
12751275

1276-
const dedicatedMasterType =
1277-
props.capacity?.masterNodeInstanceType?.toLowerCase() ??
1278-
defaultInstanceType;
1276+
const dedicatedMasterType = initializeInstanceType(defaultInstanceType, props.capacity?.masterNodeInstanceType);
12791277
const dedicatedMasterCount = props.capacity?.masterNodes ?? 0;
1280-
const dedicatedMasterEnabled = dedicatedMasterCount > 0;
1278+
const dedicatedMasterEnabled = cdk.Token.isUnresolved(dedicatedMasterCount) ? true : dedicatedMasterCount > 0;
12811279

1282-
const instanceType =
1283-
props.capacity?.dataNodeInstanceType?.toLowerCase() ??
1284-
defaultInstanceType;
1280+
const instanceType = initializeInstanceType(defaultInstanceType, props.capacity?.dataNodeInstanceType);
12851281
const instanceCount = props.capacity?.dataNodes ?? 1;
12861282

1287-
const warmType =
1288-
props.capacity?.warmInstanceType?.toLowerCase() ??
1289-
warmDefaultInstanceType;
1283+
const warmType = initializeInstanceType(warmDefaultInstanceType, props.capacity?.warmInstanceType);
12901284
const warmCount = props.capacity?.warmNodes ?? 0;
1291-
const warmEnabled = warmCount > 0;
1285+
const warmEnabled = cdk.Token.isUnresolved(warmCount) ? true : warmCount > 0;
12921286

12931287
const availabilityZoneCount =
12941288
props.zoneAwareness?.availabilityZoneCount ?? 2;
@@ -1319,11 +1313,11 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
13191313
throw new Error('When providing vpc options you need to provide a subnet for each AZ you are using');
13201314
}
13211315

1322-
if ([dedicatedMasterType, instanceType, warmType].some(t => !t.endsWith('.elasticsearch'))) {
1316+
if ([dedicatedMasterType, instanceType, warmType].some(t => (!cdk.Token.isUnresolved(t) && !t.endsWith('.elasticsearch')))) {
13231317
throw new Error('Master, data and UltraWarm node instance types must end with ".elasticsearch".');
13241318
}
13251319

1326-
if (!warmType.startsWith('ultrawarm')) {
1320+
if (!cdk.Token.isUnresolved(warmType) && !warmType.startsWith('ultrawarm')) {
13271321
throw new Error('UltraWarm node instance type must start with "ultrawarm".');
13281322
}
13291323

@@ -1822,3 +1816,18 @@ function selectSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection[]): ec2.IS
18221816
}
18231817
return selected;
18241818
}
1819+
1820+
/**
1821+
* Initializes an instance type.
1822+
*
1823+
* @param defaultInstanceType Default instance type which is used if no instance type is provided
1824+
* @param instanceType Instance type
1825+
* @returns Instance type in lowercase (if provided) or default instance type
1826+
*/
1827+
function initializeInstanceType(defaultInstanceType: string, instanceType?: string): string {
1828+
if (instanceType) {
1829+
return cdk.Token.isUnresolved(instanceType) ? instanceType : instanceType.toLowerCase();
1830+
} else {
1831+
return defaultInstanceType;
1832+
}
1833+
}

packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as iam from '@aws-cdk/aws-iam';
88
import * as kms from '@aws-cdk/aws-kms';
99
import * as logs from '@aws-cdk/aws-logs';
1010
import * as route53 from '@aws-cdk/aws-route53';
11-
import { App, Stack, Duration, SecretValue, CfnParameter } from '@aws-cdk/core';
11+
import { App, Stack, Duration, SecretValue, CfnParameter, Token } from '@aws-cdk/core';
1212
import { Domain, ElasticsearchVersion } from '../lib';
1313

1414
let app: App;
@@ -246,6 +246,45 @@ describe('UltraWarm instances', () => {
246246

247247
});
248248

249+
test('can use tokens in capacity configuration', () => {
250+
new Domain(stack, 'Domain', {
251+
version: ElasticsearchVersion.V7_10,
252+
capacity: {
253+
dataNodeInstanceType: Token.asString({ Ref: 'dataNodeInstanceType' }),
254+
dataNodes: Token.asNumber({ Ref: 'dataNodes' }),
255+
masterNodeInstanceType: Token.asString({ Ref: 'masterNodeInstanceType' }),
256+
masterNodes: Token.asNumber({ Ref: 'masterNodes' }),
257+
warmInstanceType: Token.asString({ Ref: 'warmInstanceType' }),
258+
warmNodes: Token.asNumber({ Ref: 'warmNodes' }),
259+
},
260+
});
261+
262+
expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', {
263+
ElasticsearchClusterConfig: {
264+
InstanceCount: {
265+
Ref: 'dataNodes',
266+
},
267+
InstanceType: {
268+
Ref: 'dataNodeInstanceType',
269+
},
270+
DedicatedMasterEnabled: true,
271+
DedicatedMasterCount: {
272+
Ref: 'masterNodes',
273+
},
274+
DedicatedMasterType: {
275+
Ref: 'masterNodeInstanceType',
276+
},
277+
WarmEnabled: true,
278+
WarmCount: {
279+
Ref: 'warmNodes',
280+
},
281+
WarmType: {
282+
Ref: 'warmInstanceType',
283+
},
284+
},
285+
});
286+
});
287+
249288
describe('log groups', () => {
250289

251290
test('slowSearchLogEnabled should create a custom log group', () => {

packages/@aws-cdk/aws-opensearchservice/lib/domain.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,22 +1204,16 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
12041204
const defaultInstanceType = 'r5.large.search';
12051205
const warmDefaultInstanceType = 'ultrawarm1.medium.search';
12061206

1207-
const dedicatedMasterType =
1208-
props.capacity?.masterNodeInstanceType?.toLowerCase() ??
1209-
defaultInstanceType;
1207+
const dedicatedMasterType = initializeInstanceType(defaultInstanceType, props.capacity?.masterNodeInstanceType);
12101208
const dedicatedMasterCount = props.capacity?.masterNodes ?? 0;
1211-
const dedicatedMasterEnabled = dedicatedMasterCount > 0;
1209+
const dedicatedMasterEnabled = cdk.Token.isUnresolved(dedicatedMasterCount) ? true : dedicatedMasterCount > 0;
12121210

1213-
const instanceType =
1214-
props.capacity?.dataNodeInstanceType?.toLowerCase() ??
1215-
defaultInstanceType;
1211+
const instanceType = initializeInstanceType(defaultInstanceType, props.capacity?.dataNodeInstanceType);
12161212
const instanceCount = props.capacity?.dataNodes ?? 1;
12171213

1218-
const warmType =
1219-
props.capacity?.warmInstanceType?.toLowerCase() ??
1220-
warmDefaultInstanceType;
1214+
const warmType = initializeInstanceType(warmDefaultInstanceType, props.capacity?.warmInstanceType);
12211215
const warmCount = props.capacity?.warmNodes ?? 0;
1222-
const warmEnabled = warmCount > 0;
1216+
const warmEnabled = cdk.Token.isUnresolved(warmCount) ? true : warmCount > 0;
12231217

12241218
const availabilityZoneCount =
12251219
props.zoneAwareness?.availabilityZoneCount ?? 2;
@@ -1250,11 +1244,11 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
12501244
throw new Error('When providing vpc options you need to provide a subnet for each AZ you are using');
12511245
}
12521246

1253-
if ([dedicatedMasterType, instanceType, warmType].some(t => !t.endsWith('.search'))) {
1247+
if ([dedicatedMasterType, instanceType, warmType].some(t => (!cdk.Token.isUnresolved(t) && !t.endsWith('.search')))) {
12541248
throw new Error('Master, data and UltraWarm node instance types must end with ".search".');
12551249
}
12561250

1257-
if (!warmType.startsWith('ultrawarm')) {
1251+
if (!cdk.Token.isUnresolved(warmType) && !warmType.startsWith('ultrawarm')) {
12581252
throw new Error('UltraWarm node instance type must start with "ultrawarm".');
12591253
}
12601254

@@ -1761,3 +1755,18 @@ function selectSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection[]): ec2.IS
17611755
}
17621756
return selected;
17631757
}
1758+
1759+
/**
1760+
* Initializes an instance type.
1761+
*
1762+
* @param defaultInstanceType Default instance type which is used if no instance type is provided
1763+
* @param instanceType Instance type
1764+
* @returns Instance type in lowercase (if provided) or default instance type
1765+
*/
1766+
function initializeInstanceType(defaultInstanceType: string, instanceType?: string): string {
1767+
if (instanceType) {
1768+
return cdk.Token.isUnresolved(instanceType) ? instanceType : instanceType.toLowerCase();
1769+
} else {
1770+
return defaultInstanceType;
1771+
}
1772+
}

packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as iam from '@aws-cdk/aws-iam';
88
import * as kms from '@aws-cdk/aws-kms';
99
import * as logs from '@aws-cdk/aws-logs';
1010
import * as route53 from '@aws-cdk/aws-route53';
11-
import { App, Stack, Duration, SecretValue, CfnParameter } from '@aws-cdk/core';
11+
import { App, Stack, Duration, SecretValue, CfnParameter, Token } from '@aws-cdk/core';
1212
import { Domain, EngineVersion } from '../lib';
1313

1414
let app: App;
@@ -248,6 +248,45 @@ describe('UltraWarm instances', () => {
248248

249249
});
250250

251+
test('can use tokens in capacity configuration', () => {
252+
new Domain(stack, 'Domain', {
253+
version: defaultVersion,
254+
capacity: {
255+
dataNodeInstanceType: Token.asString({ Ref: 'dataNodeInstanceType' }),
256+
dataNodes: Token.asNumber({ Ref: 'dataNodes' }),
257+
masterNodeInstanceType: Token.asString({ Ref: 'masterNodeInstanceType' }),
258+
masterNodes: Token.asNumber({ Ref: 'masterNodes' }),
259+
warmInstanceType: Token.asString({ Ref: 'warmInstanceType' }),
260+
warmNodes: Token.asNumber({ Ref: 'warmNodes' }),
261+
},
262+
});
263+
264+
expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', {
265+
ClusterConfig: {
266+
InstanceCount: {
267+
Ref: 'dataNodes',
268+
},
269+
InstanceType: {
270+
Ref: 'dataNodeInstanceType',
271+
},
272+
DedicatedMasterEnabled: true,
273+
DedicatedMasterCount: {
274+
Ref: 'masterNodes',
275+
},
276+
DedicatedMasterType: {
277+
Ref: 'masterNodeInstanceType',
278+
},
279+
WarmEnabled: true,
280+
WarmCount: {
281+
Ref: 'warmNodes',
282+
},
283+
WarmType: {
284+
Ref: 'warmInstanceType',
285+
},
286+
},
287+
});
288+
});
289+
251290
describe('log groups', () => {
252291

253292
test('slowSearchLogEnabled should create a custom log group', () => {

packages/@aws-cdk/aws-stepfunctions-tasks/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,20 @@ new tasks.EmrCreateCluster(this, 'Create Cluster', {
700700
});
701701
```
702702

703+
If you want to use an [auto-termination policy](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-auto-termination-policy.html),
704+
you can specify the `autoTerminationPolicy` property. Set the `idleTimeout` as a `Duration` between 60 seconds and 7 days.
705+
`autoTerminationPolicy` requires the EMR release label to be 5.30.0 or above.
706+
707+
```ts
708+
new tasks.EmrCreateCluster(this, 'Create Cluster', {
709+
instances: {},
710+
name: 'ClusterName',
711+
autoTerminationPolicy: {
712+
idleTimeout: Duration.seconds(120),
713+
},
714+
});
715+
```
716+
703717
### Termination Protection
704718

705719
Locks a cluster (job flow) so the EC2 instances in the cluster cannot be

packages/@aws-cdk/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Construct } from 'constructs';
55
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
66
import {
77
ApplicationConfigPropertyToJson,
8+
AutoTerminationPolicyPropertyToJson,
89
BootstrapActionConfigToJson,
910
ConfigurationPropertyToJson,
1011
InstancesConfigPropertyToJson,
@@ -67,6 +68,15 @@ export interface EmrCreateClusterProps extends sfn.TaskStateBaseProps {
6768
*/
6869
readonly autoScalingRole?: iam.IRole;
6970

71+
/**
72+
* An auto-termination policy for an Amazon EMR cluster. An auto-termination policy defines the amount of
73+
* idle time in seconds after which a cluster automatically terminates. The value must be between
74+
* 60 seconds and 7 days.
75+
*
76+
* @default - None
77+
*/
78+
readonly autoTerminationPolicy?: EmrCreateCluster.AutoTerminationPolicyProperty;
79+
7080
/**
7181
* A list of bootstrap actions to run before Hadoop starts on the cluster nodes.
7282
*
@@ -269,6 +279,7 @@ export class EmrCreateCluster extends sfn.TaskStateBase {
269279
AdditionalInfo: cdk.stringToCloudFormation(this.props.additionalInfo),
270280
Applications: cdk.listMapper(ApplicationConfigPropertyToJson)(this.props.applications),
271281
AutoScalingRole: cdk.stringToCloudFormation(this._autoScalingRole?.roleName),
282+
AutoTerminationPolicy: this.props.autoTerminationPolicy ? AutoTerminationPolicyPropertyToJson(this.props.autoTerminationPolicy) : undefined,
272283
BootstrapActions: cdk.listMapper(BootstrapActionConfigToJson)(this.props.bootstrapActions),
273284
Configurations: cdk.listMapper(ConfigurationPropertyToJson)(this.props.configurations),
274285
CustomAmiId: cdk.stringToCloudFormation(this.props.customAmiId),
@@ -1389,6 +1400,20 @@ export namespace EmrCreateCluster {
13891400
readonly version?: string;
13901401
}
13911402

1403+
/**
1404+
* Auto-termination policy for the EMR cluster.
1405+
*
1406+
* @see https://docs.aws.amazon.com/emr/latest/APIReference/API_AutoTerminationPolicy.html
1407+
*
1408+
*/
1409+
export interface AutoTerminationPolicyProperty {
1410+
1411+
/**
1412+
* Specifies the amount of idle time after which the cluster automatically terminates.
1413+
*/
1414+
readonly idleTimeout: cdk.Duration;
1415+
}
1416+
13921417
/**
13931418
* Configuration of the script to run during a bootstrap action.
13941419
*

0 commit comments

Comments
 (0)