Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 9, 2021
2 parents 2cadfec + cac5726 commit 1bd1cec
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 68 deletions.
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-codecommit/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,23 @@ export interface IRepository extends IResource, notifications.INotificationRuleS

/**
* Defines a CodeStar Notification rule which triggers when a pull request is merged.
* @deprecated this method has a typo in its name, use notifyOnPullRequestMerged instead
*/
notifiyOnPullRequestMerged(
id: string,
target: notifications.INotificationRuleTarget,
options?: notifications.NotificationRuleOptions,
): notifications.INotificationRule;

/**
* Defines a CodeStar Notification rule which triggers when a pull request is merged.
*/
notifyOnPullRequestMerged(
id: string,
target: notifications.INotificationRuleTarget,
options?: notifications.NotificationRuleOptions,
): notifications.INotificationRule;

/**
* Defines a CodeStar Notification rule which triggers when a new branch or tag is created.
*/
Expand Down Expand Up @@ -419,6 +429,14 @@ abstract class RepositoryBase extends Resource implements IRepository {
id: string,
target: notifications.INotificationRuleTarget,
options?: notifications.NotificationRuleOptions,
): notifications.INotificationRule {
return this.notifyOnPullRequestMerged(id, target, options);
}

public notifyOnPullRequestMerged(
id: string,
target: notifications.INotificationRuleTarget,
options?: notifications.NotificationRuleOptions,
): notifications.INotificationRule {
return this.notifyOn(id, target, {
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ const repository = new codecommit.Repository(stack, 'MyCodecommitRepository', {
const target = new sns.Topic(stack, 'MyTopic');

repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target);
repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
repository.notifyOnPullRequestMerged('NotifyOnPullRequestMerged', target);

app.synth();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('notification rule', () => {

repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target);

repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target);
repository.notifyOnPullRequestMerged('NotifyOnPullRequestMerged', target);

expect(stack).toHaveResource('AWS::CodeStarNotifications::NotificationRule', {
Name: 'MyCodecommitRepositoryNotifyOnPullRequestCreatedBB14EA32',
Expand Down
35 changes: 22 additions & 13 deletions packages/@aws-cdk/aws-elasticsearch/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,22 +1273,16 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
const defaultInstanceType = 'r5.large.elasticsearch';
const warmDefaultInstanceType = 'ultrawarm1.medium.elasticsearch';

const dedicatedMasterType =
props.capacity?.masterNodeInstanceType?.toLowerCase() ??
defaultInstanceType;
const dedicatedMasterType = initializeInstanceType(defaultInstanceType, props.capacity?.masterNodeInstanceType);
const dedicatedMasterCount = props.capacity?.masterNodes ?? 0;
const dedicatedMasterEnabled = dedicatedMasterCount > 0;
const dedicatedMasterEnabled = cdk.Token.isUnresolved(dedicatedMasterCount) ? true : dedicatedMasterCount > 0;

const instanceType =
props.capacity?.dataNodeInstanceType?.toLowerCase() ??
defaultInstanceType;
const instanceType = initializeInstanceType(defaultInstanceType, props.capacity?.dataNodeInstanceType);
const instanceCount = props.capacity?.dataNodes ?? 1;

const warmType =
props.capacity?.warmInstanceType?.toLowerCase() ??
warmDefaultInstanceType;
const warmType = initializeInstanceType(warmDefaultInstanceType, props.capacity?.warmInstanceType);
const warmCount = props.capacity?.warmNodes ?? 0;
const warmEnabled = warmCount > 0;
const warmEnabled = cdk.Token.isUnresolved(warmCount) ? true : warmCount > 0;

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

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

if (!warmType.startsWith('ultrawarm')) {
if (!cdk.Token.isUnresolved(warmType) && !warmType.startsWith('ultrawarm')) {
throw new Error('UltraWarm node instance type must start with "ultrawarm".');
}

Expand Down Expand Up @@ -1822,3 +1816,18 @@ function selectSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection[]): ec2.IS
}
return selected;
}

/**
* Initializes an instance type.
*
* @param defaultInstanceType Default instance type which is used if no instance type is provided
* @param instanceType Instance type
* @returns Instance type in lowercase (if provided) or default instance type
*/
function initializeInstanceType(defaultInstanceType: string, instanceType?: string): string {
if (instanceType) {
return cdk.Token.isUnresolved(instanceType) ? instanceType : instanceType.toLowerCase();
} else {
return defaultInstanceType;
}
}
41 changes: 40 additions & 1 deletion packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as logs from '@aws-cdk/aws-logs';
import * as route53 from '@aws-cdk/aws-route53';
import { App, Stack, Duration, SecretValue, CfnParameter } from '@aws-cdk/core';
import { App, Stack, Duration, SecretValue, CfnParameter, Token } from '@aws-cdk/core';
import { Domain, ElasticsearchVersion } from '../lib';

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

});

test('can use tokens in capacity configuration', () => {
new Domain(stack, 'Domain', {
version: ElasticsearchVersion.V7_10,
capacity: {
dataNodeInstanceType: Token.asString({ Ref: 'dataNodeInstanceType' }),
dataNodes: Token.asNumber({ Ref: 'dataNodes' }),
masterNodeInstanceType: Token.asString({ Ref: 'masterNodeInstanceType' }),
masterNodes: Token.asNumber({ Ref: 'masterNodes' }),
warmInstanceType: Token.asString({ Ref: 'warmInstanceType' }),
warmNodes: Token.asNumber({ Ref: 'warmNodes' }),
},
});

expect(stack).toHaveResourceLike('AWS::Elasticsearch::Domain', {
ElasticsearchClusterConfig: {
InstanceCount: {
Ref: 'dataNodes',
},
InstanceType: {
Ref: 'dataNodeInstanceType',
},
DedicatedMasterEnabled: true,
DedicatedMasterCount: {
Ref: 'masterNodes',
},
DedicatedMasterType: {
Ref: 'masterNodeInstanceType',
},
WarmEnabled: true,
WarmCount: {
Ref: 'warmNodes',
},
WarmType: {
Ref: 'warmInstanceType',
},
},
});
});

describe('log groups', () => {

test('slowSearchLogEnabled should create a custom log group', () => {
Expand Down
35 changes: 22 additions & 13 deletions packages/@aws-cdk/aws-opensearchservice/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,22 +1204,16 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
const defaultInstanceType = 'r5.large.search';
const warmDefaultInstanceType = 'ultrawarm1.medium.search';

const dedicatedMasterType =
props.capacity?.masterNodeInstanceType?.toLowerCase() ??
defaultInstanceType;
const dedicatedMasterType = initializeInstanceType(defaultInstanceType, props.capacity?.masterNodeInstanceType);
const dedicatedMasterCount = props.capacity?.masterNodes ?? 0;
const dedicatedMasterEnabled = dedicatedMasterCount > 0;
const dedicatedMasterEnabled = cdk.Token.isUnresolved(dedicatedMasterCount) ? true : dedicatedMasterCount > 0;

const instanceType =
props.capacity?.dataNodeInstanceType?.toLowerCase() ??
defaultInstanceType;
const instanceType = initializeInstanceType(defaultInstanceType, props.capacity?.dataNodeInstanceType);
const instanceCount = props.capacity?.dataNodes ?? 1;

const warmType =
props.capacity?.warmInstanceType?.toLowerCase() ??
warmDefaultInstanceType;
const warmType = initializeInstanceType(warmDefaultInstanceType, props.capacity?.warmInstanceType);
const warmCount = props.capacity?.warmNodes ?? 0;
const warmEnabled = warmCount > 0;
const warmEnabled = cdk.Token.isUnresolved(warmCount) ? true : warmCount > 0;

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

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

if (!warmType.startsWith('ultrawarm')) {
if (!cdk.Token.isUnresolved(warmType) && !warmType.startsWith('ultrawarm')) {
throw new Error('UltraWarm node instance type must start with "ultrawarm".');
}

Expand Down Expand Up @@ -1761,3 +1755,18 @@ function selectSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection[]): ec2.IS
}
return selected;
}

/**
* Initializes an instance type.
*
* @param defaultInstanceType Default instance type which is used if no instance type is provided
* @param instanceType Instance type
* @returns Instance type in lowercase (if provided) or default instance type
*/
function initializeInstanceType(defaultInstanceType: string, instanceType?: string): string {
if (instanceType) {
return cdk.Token.isUnresolved(instanceType) ? instanceType : instanceType.toLowerCase();
} else {
return defaultInstanceType;
}
}
41 changes: 40 additions & 1 deletion packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as logs from '@aws-cdk/aws-logs';
import * as route53 from '@aws-cdk/aws-route53';
import { App, Stack, Duration, SecretValue, CfnParameter } from '@aws-cdk/core';
import { App, Stack, Duration, SecretValue, CfnParameter, Token } from '@aws-cdk/core';
import { Domain, EngineVersion } from '../lib';

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

});

test('can use tokens in capacity configuration', () => {
new Domain(stack, 'Domain', {
version: defaultVersion,
capacity: {
dataNodeInstanceType: Token.asString({ Ref: 'dataNodeInstanceType' }),
dataNodes: Token.asNumber({ Ref: 'dataNodes' }),
masterNodeInstanceType: Token.asString({ Ref: 'masterNodeInstanceType' }),
masterNodes: Token.asNumber({ Ref: 'masterNodes' }),
warmInstanceType: Token.asString({ Ref: 'warmInstanceType' }),
warmNodes: Token.asNumber({ Ref: 'warmNodes' }),
},
});

expect(stack).toHaveResourceLike('AWS::OpenSearchService::Domain', {
ClusterConfig: {
InstanceCount: {
Ref: 'dataNodes',
},
InstanceType: {
Ref: 'dataNodeInstanceType',
},
DedicatedMasterEnabled: true,
DedicatedMasterCount: {
Ref: 'masterNodes',
},
DedicatedMasterType: {
Ref: 'masterNodeInstanceType',
},
WarmEnabled: true,
WarmCount: {
Ref: 'warmNodes',
},
WarmType: {
Ref: 'warmInstanceType',
},
},
});
});

describe('log groups', () => {

test('slowSearchLogEnabled should create a custom log group', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions-tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,20 @@ new tasks.EmrCreateCluster(this, 'Create Cluster', {
});
```

If you want to use an [auto-termination policy](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-auto-termination-policy.html),
you can specify the `autoTerminationPolicy` property. Set the `idleTimeout` as a `Duration` between 60 seconds and 7 days.
`autoTerminationPolicy` requires the EMR release label to be 5.30.0 or above.

```ts
new tasks.EmrCreateCluster(this, 'Create Cluster', {
instances: {},
name: 'ClusterName',
autoTerminationPolicy: {
idleTimeout: Duration.seconds(120),
},
});
```

### Termination Protection

Locks a cluster (job flow) so the EC2 instances in the cluster cannot be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Construct } from 'constructs';
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
import {
ApplicationConfigPropertyToJson,
AutoTerminationPolicyPropertyToJson,
BootstrapActionConfigToJson,
ConfigurationPropertyToJson,
InstancesConfigPropertyToJson,
Expand Down Expand Up @@ -67,6 +68,15 @@ export interface EmrCreateClusterProps extends sfn.TaskStateBaseProps {
*/
readonly autoScalingRole?: iam.IRole;

/**
* An auto-termination policy for an Amazon EMR cluster. An auto-termination policy defines the amount of
* idle time in seconds after which a cluster automatically terminates. The value must be between
* 60 seconds and 7 days.
*
* @default - None
*/
readonly autoTerminationPolicy?: EmrCreateCluster.AutoTerminationPolicyProperty;

/**
* A list of bootstrap actions to run before Hadoop starts on the cluster nodes.
*
Expand Down Expand Up @@ -269,6 +279,7 @@ export class EmrCreateCluster extends sfn.TaskStateBase {
AdditionalInfo: cdk.stringToCloudFormation(this.props.additionalInfo),
Applications: cdk.listMapper(ApplicationConfigPropertyToJson)(this.props.applications),
AutoScalingRole: cdk.stringToCloudFormation(this._autoScalingRole?.roleName),
AutoTerminationPolicy: this.props.autoTerminationPolicy ? AutoTerminationPolicyPropertyToJson(this.props.autoTerminationPolicy) : undefined,
BootstrapActions: cdk.listMapper(BootstrapActionConfigToJson)(this.props.bootstrapActions),
Configurations: cdk.listMapper(ConfigurationPropertyToJson)(this.props.configurations),
CustomAmiId: cdk.stringToCloudFormation(this.props.customAmiId),
Expand Down Expand Up @@ -1389,6 +1400,20 @@ export namespace EmrCreateCluster {
readonly version?: string;
}

/**
* Auto-termination policy for the EMR cluster.
*
* @see https://docs.aws.amazon.com/emr/latest/APIReference/API_AutoTerminationPolicy.html
*
*/
export interface AutoTerminationPolicyProperty {

/**
* Specifies the amount of idle time after which the cluster automatically terminates.
*/
readonly idleTimeout: cdk.Duration;
}

/**
* Configuration of the script to run during a bootstrap action.
*
Expand Down
Loading

0 comments on commit 1bd1cec

Please sign in to comment.