Skip to content

Commit

Permalink
Merge branch 'master' into ecs-port-mappings-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
misterjoshua authored Feb 26, 2021
2 parents cfa1bbd + ea91aa3 commit 9247299
Show file tree
Hide file tree
Showing 114 changed files with 2,324 additions and 167 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ All notable changes to this project will be documented in this file. See [standa

### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **appmesh:** the properties virtualRouter and virtualNode of VirtualServiceProps have been replaced with the union-like class VirtualServiceProvider
* **appmesh:** the properties virtualRouter and virtualNode of VirtualServiceProps have been replaced with the union-like class VirtualServiceProvider
* **appmesh**: the method `addVirtualService` has been removed from `IMesh`
* **cloudfront:** experimental EdgeFunction stack names have changed from 'edge-lambda-stack-${region}' to 'edge-lambda-stack-${stackid}' to support multiple independent CloudFront distributions with EdgeFunctions.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"Arn"
]
},
"Runtime": "nodejs12.x"
"Runtime": "nodejs12.x",
"Description": "veni vidi vici"
},
"DependsOn": [
"CustomReflectCustomResourceProviderRoleB4B29AEC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TestStack extends Stack {
const serviceToken = CustomResourceProvider.getOrCreate(this, resourceType, {
codeDirectory: `${__dirname}/core-custom-resource-provider-fixture`,
runtime: CustomResourceProviderRuntime.NODEJS_12,
description: 'veni vidi vici',
});

const cr = new CustomResource(this, 'MyResource', {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch/lib/private/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function metricGraphJson(metric: IMetric, yAxis?: string, id?: string) {

withExpression(expr) {
options.expression = expr.expression;
if (expr.period && expr.period !== 300) { options.period = expr.period; }
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\"}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\",\"period\":60}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
Expand Down Expand Up @@ -120,7 +120,7 @@
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\"}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\",\"period\":60}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/test.metric-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ export = {
test.done();
},

'top level period in a MathExpression is respected in its metrics'(test: Test) {
const graph = new GraphWidget({
left: [
a,
new MathExpression({
expression: 'a + b',
usingMetrics: { a, b },
period: Duration.minutes(1),
}),
],
});

// THEN
graphMetricsAre(test, graph, [
['Test', 'ACount'],
[{ label: 'a + b', expression: 'a + b', period: 60 }],
['Test', 'ACount', { visible: false, id: 'a', period: 60 }],
['Test', 'BCount', { visible: false, id: 'b', period: 60 }],
]);
test.done();
},

'MathExpression controls period of metrics transitively used in it'(test: Test) {
// Same as the previous test, but recursively

Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/cfn-init-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ export abstract class InitFile extends InitElement {
* Use a literal string as the file content
*/
public static fromString(fileName: string, content: string, options: InitFileOptions = {}): InitFile {
if (!content) {
throw new Error(`InitFile ${fileName}: cannot create empty file. Please supply at least one character of content.`);
}
return new class extends InitFile {
protected _doBind(bindOptions: InitBindOptions) {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
public static readonly KMS = new InterfaceVpcEndpointAwsService('kms');
public static readonly CLOUDWATCH_LOGS = new InterfaceVpcEndpointAwsService('logs');
public static readonly CLOUDWATCH = new InterfaceVpcEndpointAwsService('monitoring');
public static readonly RDS = new InterfaceVpcEndpointAwsService('rds');
public static readonly SAGEMAKER_API = new InterfaceVpcEndpointAwsService('sagemaker.api');
public static readonly SAGEMAKER_RUNTIME = new InterfaceVpcEndpointAwsService('sagemaker.runtime');
public static readonly SAGEMAKER_RUNTIME_FIPS = new InterfaceVpcEndpointAwsService('sagemaker.runtime-fips');
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KINESIS_STREAMS",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KINESIS_FIREHOSE",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KMS",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.RDS",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_API",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_NOTEBOOK",
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_RUNTIME",
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/cfn-init-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ describe('InitFile', () => {
});
});

test('empty content string throws error', () => {
expect(() => {
ec2.InitFile.fromString('/tmp/foo', '');
}).toThrow('InitFile /tmp/foo: cannot create empty file. Please supply at least one character of content.');
});

test('symlink throws an error if mode is set incorrectly', () => {
expect(() => {
ec2.InitFile.symlink('/tmp/foo', '/tmp/bar', {
Expand Down
38 changes: 38 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,41 @@ const scheduledFargateTask = new ScheduledFargateTask(stack, 'ScheduledFargateTa
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
});
```

### Use the REMOVE_DEFAULT_DESIRED_COUNT feature flag

The REMOVE_DEFAULT_DESIRED_COUNT feature flag is used to override the default desiredCount that is autogenerated by the CDK. This will set the desiredCount of any service created by any of the following constructs to be undefined.

* ApplicationLoadBalancedEc2Service
* ApplicationLoadBalancedFargateService
* NetworkLoadBalancedEc2Service
* NetworkLoadBalancedFargateService
* QueueProcessingEc2Service
* QueueProcessingFargateService

If a desiredCount is not passed in as input to the above constructs, CloudFormation will either create a new service to start up with a desiredCount of 1, or update an existing service to start up with the same desiredCount as prior to the update.

To enable the feature flag, ensure that the REMOVE_DEFAULT_DESIRED_COUNT flag within an application stack context is set to true, like so:

```ts
stack.node.setContext(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT, true);
```

The following is an example of an application with the REMOVE_DEFAULT_DESIRED_COUNT feature flag enabled:

```ts
const app = new App();

const stack = new Stack(app, 'aws-ecs-patterns-queue');
stack.node.setContext(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT, true);

const vpc = new ec2.Vpc(stack, 'VPC', {
maxAzs: 2,
});

new QueueProcessingFargateService(stack, 'QueueProcessingService', {
vpc,
memoryLimitMiB: 512,
image: new ecs.AssetImage(path.join(__dirname, '..', 'sqs-reader')),
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export interface ApplicationLoadBalancedServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default 1
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* when updating an existing service.
*/
readonly desiredCount?: number;

Expand Down Expand Up @@ -311,12 +313,19 @@ export interface ApplicationLoadBalancedTaskImageOptions {
* The base class for ApplicationLoadBalancedEc2Service and ApplicationLoadBalancedFargateService services.
*/
export abstract class ApplicationLoadBalancedServiceBase extends CoreConstruct {

/**
* The desired number of instantiations of the task definition to keep running on the service.
* @deprecated - Use `internalDesiredCount` instead.
*/
public readonly desiredCount: number;

/**
* The desired number of instantiations of the task definition to keep running on the service.
* The default is 1 for all new services and uses the existing services desired count
* when updating an existing service if one is not provided.
*/
public readonly internalDesiredCount?: number;

/**
* The Application Load Balancer for the service.
*/
Expand Down Expand Up @@ -368,7 +377,9 @@ export abstract class ApplicationLoadBalancedServiceBase extends CoreConstruct {
if (props.desiredCount !== undefined && props.desiredCount < 1) {
throw new Error('You must specify a desiredCount greater than 0');
}

this.desiredCount = props.desiredCount || 1;
this.internalDesiredCount = props.desiredCount;

const internetFacing = props.publicLoadBalancer ?? true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export interface ApplicationMultipleTargetGroupsServiceBaseProps {
/**
* The desired number of instantiations of the task definition to keep running on the service.
*
* @default 1
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* when updating an existing service.
*/
readonly desiredCount?: number;

Expand Down Expand Up @@ -329,12 +331,19 @@ export interface ApplicationListenerProps {
* The base class for ApplicationMultipleTargetGroupsEc2Service and ApplicationMultipleTargetGroupsFargateService classes.
*/
export abstract class ApplicationMultipleTargetGroupsServiceBase extends CoreConstruct {

/**
* The desired number of instantiations of the task definition to keep running on the service.
* @deprecated - Use `internalDesiredCount` instead.
*/
public readonly desiredCount: number;

/**
* The desired number of instantiations of the task definition to keep running on the service.
* The default is 1 for all new services and uses the existing services desired count
* when updating an existing service, if one is not provided.
*/
public readonly internalDesiredCount?: number;

/**
* The default Application Load Balancer for the service (first added load balancer).
*/
Expand Down Expand Up @@ -365,7 +374,10 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends CoreCon
this.validateInput(props);

this.cluster = props.cluster || this.getDefaultCluster(this, props.vpc);

this.desiredCount = props.desiredCount || 1;
this.internalDesiredCount = props.desiredCount;

if (props.taskImageOptions) {
this.logDriver = this.createLogDriver(props.taskImageOptions.enableLogging, props.taskImageOptions.logDriver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export interface NetworkLoadBalancedServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default 1
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* when updating an existing service.
*/
readonly desiredCount?: number;

Expand Down Expand Up @@ -263,9 +265,17 @@ export interface NetworkLoadBalancedTaskImageOptions {
export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
/**
* The desired number of instantiations of the task definition to keep running on the service.
* @deprecated - Use `internalDesiredCount` instead.
*/
public readonly desiredCount: number;

/**
* The desired number of instantiations of the task definition to keep running on the service.
* The default is 1 for all new services and uses the existing services desired count
* when updating an existing service, if one is not provided.
*/
public readonly internalDesiredCount?: number;

/**
* The Network Load Balancer for the service.
*/
Expand Down Expand Up @@ -306,7 +316,9 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
if (props.desiredCount !== undefined && props.desiredCount < 1) {
throw new Error('You must specify a desiredCount greater than 0');
}

this.desiredCount = props.desiredCount || 1;
this.internalDesiredCount = props.desiredCount;

const internetFacing = props.publicLoadBalancer ?? true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export interface NetworkMultipleTargetGroupsServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default 1
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* when updating an existing service.
*/
readonly desiredCount?: number;

Expand Down Expand Up @@ -264,9 +266,17 @@ export interface NetworkTargetProps {
export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstruct {
/**
* The desired number of instantiations of the task definition to keep running on the service.
* @deprecated - Use `internalDesiredCount` instead.
*/
public readonly desiredCount: number;

/**
* The desired number of instantiations of the task definition to keep running on the service.
* The default is 1 for all new services and uses the existing services desired count
* when updating an existing service, if one is not provided.
*/
public readonly internalDesiredCount?: number;

/**
* The Network Load Balancer for the service.
*/
Expand Down Expand Up @@ -297,7 +307,10 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru
this.validateInput(props);

this.cluster = props.cluster || this.getDefaultCluster(this, props.vpc);

this.desiredCount = props.desiredCount || 1;
this.internalDesiredCount = props.desiredCount;

if (props.taskImageOptions) {
this.logDriver = this.createLogDriver(props.taskImageOptions.enableLogging, props.taskImageOptions.logDriver);
}
Expand Down
Loading

0 comments on commit 9247299

Please sign in to comment.