Skip to content

Commit 7177dc1

Browse files
authored
Merge branch 'main' into add-websocket-iam-authorizer
2 parents 0c6890a + 7ccc644 commit 7177dc1

186 files changed

Lines changed: 7916 additions & 1033 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.v2.alpha.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [2.35.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.34.2-alpha.0...v2.35.0-alpha.0) (2022-08-02)
6+
7+
8+
### Bug Fixes
9+
10+
* **cognito-identitypool:** providerUrl causes error when mappingKey is not provided and it is a token ([#21191](https://github.com/aws/aws-cdk/issues/21191)) ([d91c904](https://github.com/aws/aws-cdk/commit/d91c9045b2ca027947c94ff8b93adb80f8ca8434)), closes [#19222](https://github.com/aws/aws-cdk/issues/19222) [/github.com/aws/aws-cdk/pull/21056#issuecomment-1178879318](https://github.com/aws//github.com/aws/aws-cdk/pull/21056/issues/issuecomment-1178879318)
11+
512
## [2.34.2-alpha.0](https://github.com/aws/aws-cdk/compare/v2.34.1-alpha.0...v2.34.2-alpha.0) (2022-07-29)
613

714
## [2.34.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.34.0-alpha.0...v2.34.1-alpha.0) (2022-07-29)

CHANGELOG.v2.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [2.35.0](https://github.com/aws/aws-cdk/compare/v2.34.2...v2.35.0) (2022-08-02)
6+
7+
8+
### Features
9+
10+
* **config:** add support for eks-cluster-xxx-version managed rule ([#21344](https://github.com/aws/aws-cdk/issues/21344)) ([82e8100](https://github.com/aws/aws-cdk/commit/82e81008c08669429c19c5b864292b256aaf976e)), closes [#21254](https://github.com/aws/aws-cdk/issues/21254)
11+
* **core:** cache fingerprints of large assets ([#21321](https://github.com/aws/aws-cdk/issues/21321)) ([17f1ec8](https://github.com/aws/aws-cdk/commit/17f1ec881ba8fb300bd4cf8674a87640ab05c31a)), closes [#21297](https://github.com/aws/aws-cdk/issues/21297)
12+
* **ec2:** add missing endpoints to InterfaceVpcEndpointAwsService ([#21401](https://github.com/aws/aws-cdk/issues/21401)) ([c64cccb](https://github.com/aws/aws-cdk/commit/c64cccb0f17d014f978b8df38f47dcfa254c89e6)), closes [#21402](https://github.com/aws/aws-cdk/issues/21402) [#21220](https://github.com/aws/aws-cdk/issues/21220) [#21338](https://github.com/aws/aws-cdk/issues/21338) [#19420](https://github.com/aws/aws-cdk/issues/19420)
13+
* **events-targets:** add dlq support for ecs target ([#21396](https://github.com/aws/aws-cdk/issues/21396)) ([e82ba52](https://github.com/aws/aws-cdk/commit/e82ba52ac5c27863cc30309502ecd45810f96803)), closes [#21118](https://github.com/aws/aws-cdk/issues/21118)
14+
* **fsx:** support AutoImportPolicy in LustreFilesystem ([#21301](https://github.com/aws/aws-cdk/issues/21301)) ([b1ce472](https://github.com/aws/aws-cdk/commit/b1ce472ed2a15480980286f21a028fdc20cdb91d))
15+
* **fsx:** support DataCompressionType in LustreConfiguration ([#21392](https://github.com/aws/aws-cdk/issues/21392)) ([214a792](https://github.com/aws/aws-cdk/commit/214a7921616fa2cf3031e17cc26308772878fefd)), closes [#16431](https://github.com/aws/aws-cdk/issues/16431)
16+
* **opensearch:** add support for latest amazon opensearch service 1.3 ([#21413](https://github.com/aws/aws-cdk/issues/21413)) ([aa55715](https://github.com/aws/aws-cdk/commit/aa5571532f046158cde3da6080a8b19d9b1339e0)), closes [#21414](https://github.com/aws/aws-cdk/issues/21414)
17+
* **pipelines:** allow use of custom role for pipeline ([#21299](https://github.com/aws/aws-cdk/issues/21299)) ([ff3c01a](https://github.com/aws/aws-cdk/commit/ff3c01a85d1bd32c149e83fda5bf44ec3253e99d)), closes [#21412](https://github.com/aws/aws-cdk/issues/21412)
18+
* **rds:** add copyTagsToSnapshot to the construct props for ServerlessCluster and ServerlessClusterFromSnapshot ([#21056](https://github.com/aws/aws-cdk/issues/21056)) ([47333a1](https://github.com/aws/aws-cdk/commit/47333a12f83fbac6c8174bd7fe13f1e41159f8ae)), closes [#20968](https://github.com/aws/aws-cdk/issues/20968)
19+
20+
21+
### Bug Fixes
22+
23+
* **appmesh:** routes with weight 0 are assigned a weight of 1 ([#21400](https://github.com/aws/aws-cdk/issues/21400)) ([fa0341f](https://github.com/aws/aws-cdk/commit/fa0341f9caceff040a1af5b6ee7b4f8a736d02bf))
24+
* **cognito:** UserPoolClient doesn't correctly respect authFlows ([#21386](https://github.com/aws/aws-cdk/issues/21386)) ([daf178a](https://github.com/aws/aws-cdk/commit/daf178aa38632c9b830c20924a77b27b04698ce9)), closes [#16236](https://github.com/aws/aws-cdk/issues/16236)
25+
* **core:** asset fingerprint cache invalidation incorrectly uses mtime ([#21374](https://github.com/aws/aws-cdk/issues/21374)) ([65a210a](https://github.com/aws/aws-cdk/commit/65a210aaaf8f45095170bca7779fd274aab54a00)), closes [#21321](https://github.com/aws/aws-cdk/issues/21321)
26+
* **ecs:** ec2Service placement strategies use incorrect casing which causes drift ([#20946](https://github.com/aws/aws-cdk/issues/20946)) ([715158f](https://github.com/aws/aws-cdk/commit/715158f44ae1576361b93ec529f09d7dc0472c3b)), closes [#20812](https://github.com/aws/aws-cdk/issues/20812)
27+
* **ecs:** new arn format not supported (under feature flag) ([#18140](https://github.com/aws/aws-cdk/issues/18140)) ([9749a57](https://github.com/aws/aws-cdk/commit/9749a5725c4f5cb13313a3d28d6b52e85c59548b)), closes [#16634](https://github.com/aws/aws-cdk/issues/16634) [#18137](https://github.com/aws/aws-cdk/issues/18137)
28+
* **eks:** cannot disable cluster logging once it has been enabled ([#21185](https://github.com/aws/aws-cdk/issues/21185)) ([e41b073](https://github.com/aws/aws-cdk/commit/e41b073415bf68c8862219242d8f92c7fb6c16bb)), closes [#18112](https://github.com/aws/aws-cdk/issues/18112) [#20707](https://github.com/aws/aws-cdk/issues/20707) [#19898](https://github.com/aws/aws-cdk/issues/19898)
29+
* **events:** archive construct does not have defaultChild set ([#21345](https://github.com/aws/aws-cdk/issues/21345)) ([de7d825](https://github.com/aws/aws-cdk/commit/de7d825a32e7d4ab7fd168ee61eb4243d87f41ff)), closes [#21263](https://github.com/aws/aws-cdk/issues/21263)
30+
31+
32+
### Reverts
33+
34+
* **cli:** cannot pass objects and numbers as context arguments ([#21387](https://github.com/aws/aws-cdk/issues/21387)) ([2fa85b9](https://github.com/aws/aws-cdk/commit/2fa85b99d643cd35c9685a0bd7d857ffdf55c486)), closes [aws/aws-cdk#20068](https://github.com/aws/aws-cdk/issues/20068)
35+
536
## [2.34.2](https://github.com/aws/aws-cdk/compare/v2.34.1...v2.34.2) (2022-07-29)
637

738
### Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"devDependencies": {
1919
"@types/prettier": "2.6.0",
2020
"@yarnpkg/lockfile": "^1.1.0",
21-
"cdk-generate-synthetic-examples": "^0.1.12",
21+
"cdk-generate-synthetic-examples": "^0.1.14",
2222
"conventional-changelog-cli": "^2.2.2",
2323
"fs-extra": "^9.1.0",
2424
"graceful-fs": "^4.2.10",

packages/@aws-cdk/aws-apigateway/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,13 +1305,19 @@ in your openApi file.
13051305
## Metrics
13061306

13071307
The API Gateway service sends metrics around the performance of Rest APIs to Amazon CloudWatch.
1308-
These metrics can be referred to using the metric APIs available on the `RestApi` construct.
1309-
The APIs with the `metric` prefix can be used to get reference to specific metrics for this API. For example,
1310-
the method below refers to the client side errors metric for this API.
1308+
These metrics can be referred to using the metric APIs available on the `RestApi`, `Stage` and `Method` constructs.
1309+
Note that detailed metrics must be enabled for a stage to use the `Method` metrics.
1310+
Read more about [API Gateway metrics](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-metrics-and-dimensions.html), including enabling detailed metrics.
1311+
The APIs with the `metric` prefix can be used to get reference to specific metrics for this API. For example:
13111312

13121313
```ts
13131314
const api = new apigateway.RestApi(this, 'my-api');
1314-
const clientErrorMetric = api.metricClientError();
1315+
const stage = api.deploymentStage;
1316+
const method = api.root.addMethod('GET');
1317+
1318+
const clientErrorApiMetric = api.metricClientError();
1319+
const serverErrorStageMetric = stage.metricServerError();
1320+
const latencyMethodMetric = method.metricLatency(stage);
13151321
```
13161322

13171323
## APIGateway v2

packages/@aws-cdk/aws-apigateway/lib/method.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
12
import { ArnFormat, Lazy, Resource, Stack } from '@aws-cdk/core';
23
import { Construct } from 'constructs';
4+
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
35
import { CfnMethod, CfnMethodProps } from './apigateway.generated';
46
import { Authorizer, IAuthorizer } from './authorizer';
57
import { Integration, IntegrationConfig } from './integration';
@@ -9,6 +11,7 @@ import { IModel } from './model';
911
import { IRequestValidator, RequestValidatorOptions } from './requestvalidator';
1012
import { IResource } from './resource';
1113
import { IRestApi, RestApi, RestApiBase } from './restapi';
14+
import { IStage } from './stage';
1215
import { validateHttpMethod } from './util';
1316

1417
export interface MethodOptions {
@@ -364,6 +367,100 @@ export class Method extends Resource {
364367
// For backward compatibility
365368
return options.requestValidator?.requestValidatorId;
366369
}
370+
371+
/**
372+
* Returns the given named metric for this API method
373+
*/
374+
public metric(metricName: string, stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
375+
return new cloudwatch.Metric({
376+
namespace: 'AWS/ApiGateway',
377+
metricName,
378+
dimensionsMap: { ApiName: this.api.restApiName, Method: this.httpMethod, Resource: this.resource.path, Stage: stage.stageName },
379+
...props,
380+
}).attachTo(this);
381+
}
382+
383+
/**
384+
* Metric for the number of client-side errors captured in a given period.
385+
*
386+
* @default - sum over 5 minutes
387+
*/
388+
public metricClientError(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
389+
return this.cannedMetric(ApiGatewayMetrics._4XxErrorSum, stage, props);
390+
}
391+
392+
/**
393+
* Metric for the number of server-side errors captured in a given period.
394+
*
395+
* @default - sum over 5 minutes
396+
*/
397+
public metricServerError(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
398+
return this.cannedMetric(ApiGatewayMetrics._5XxErrorSum, stage, props);
399+
}
400+
401+
/**
402+
* Metric for the number of requests served from the API cache in a given period.
403+
*
404+
* @default - sum over 5 minutes
405+
*/
406+
public metricCacheHitCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
407+
return this.cannedMetric(ApiGatewayMetrics.cacheHitCountSum, stage, props);
408+
}
409+
410+
/**
411+
* Metric for the number of requests served from the backend in a given period,
412+
* when API caching is enabled.
413+
*
414+
* @default - sum over 5 minutes
415+
*/
416+
public metricCacheMissCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
417+
return this.cannedMetric(ApiGatewayMetrics.cacheMissCountSum, stage, props);
418+
}
419+
420+
/**
421+
* Metric for the total number API requests in a given period.
422+
*
423+
* @default - sample count over 5 minutes
424+
*/
425+
public metricCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
426+
return this.cannedMetric(ApiGatewayMetrics.countSum, stage, {
427+
statistic: 'SampleCount',
428+
...props,
429+
});
430+
}
431+
432+
/**
433+
* Metric for the time between when API Gateway relays a request to the backend
434+
* and when it receives a response from the backend.
435+
*
436+
* @default - average over 5 minutes.
437+
*/
438+
public metricIntegrationLatency(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
439+
return this.cannedMetric(ApiGatewayMetrics.integrationLatencyAverage, stage, props);
440+
}
441+
442+
/**
443+
* The time between when API Gateway receives a request from a client
444+
* and when it returns a response to the client.
445+
* The latency includes the integration latency and other API Gateway overhead.
446+
*
447+
* @default - average over 5 minutes.
448+
*/
449+
public metricLatency(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
450+
return this.cannedMetric(ApiGatewayMetrics.latencyAverage, stage, props);
451+
}
452+
453+
private cannedMetric(fn: (dims: {
454+
ApiName: string;
455+
Method: string;
456+
Resource: string;
457+
Stage: string;
458+
}) => cloudwatch.MetricProps, stage: IStage, props?: cloudwatch.MetricOptions) {
459+
return new cloudwatch.Metric({
460+
...fn({ ApiName: this.api.restApiName, Method: this.httpMethod, Resource: this.resource.path, Stage: stage.stageName }),
461+
...props,
462+
}).attachTo(this);
463+
}
367464
}
368465

369466
export enum AuthorizationType {

packages/@aws-cdk/aws-apigateway/lib/restapi.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export interface IRestApi extends IResourceBase {
2828
*/
2929
readonly restApiId: string;
3030

31+
/**
32+
* The name of this API Gateway RestApi.
33+
* @attribute
34+
*/
35+
readonly restApiName: string;
36+
3137
/**
3238
* The resource ID of the root resource.
3339
* @attribute
@@ -673,6 +679,13 @@ export interface RestApiAttributes {
673679
*/
674680
readonly restApiId: string;
675681

682+
/**
683+
* The name of the API Gateway RestApi.
684+
*
685+
* @default - ID of the RestApi construct.
686+
*/
687+
readonly restApiName?: string;
688+
676689
/**
677690
* The resource ID of the root resource.
678691
*/
@@ -713,6 +726,7 @@ export class RestApi extends RestApiBase {
713726
public static fromRestApiAttributes(scope: Construct, id: string, attrs: RestApiAttributes): IRestApi {
714727
class Import extends RestApiBase {
715728
public readonly restApiId = attrs.restApiId;
729+
public readonly restApiName = attrs.restApiName ?? id;
716730
public readonly restApiRootResourceId = attrs.rootResourceId;
717731
public readonly root: IResource = new RootResource(this, {}, this.restApiRootResourceId);
718732
}

packages/@aws-cdk/aws-apigateway/lib/stage.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
12
import { ArnFormat, Duration, IResource, Resource, Stack, Token } from '@aws-cdk/core';
23
import { Construct } from 'constructs';
34
import { AccessLogFormat, IAccessLogDestination } from './access-log';
5+
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
46
import { CfnStage } from './apigateway.generated';
57
import { Deployment } from './deployment';
68
import { IRestApi, RestApiBase } from './restapi';
@@ -348,4 +350,93 @@ export class Stage extends Resource implements IStage {
348350
};
349351
}
350352
}
353+
354+
/**
355+
* Returns the given named metric for this stage
356+
*/
357+
public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
358+
return new cloudwatch.Metric({
359+
namespace: 'AWS/ApiGateway',
360+
metricName,
361+
dimensionsMap: { ApiName: this.restApi.restApiName, Stage: this.stageName },
362+
...props,
363+
}).attachTo(this);
364+
}
365+
366+
/**
367+
* Metric for the number of client-side errors captured in a given period.
368+
*
369+
* @default - sum over 5 minutes
370+
*/
371+
public metricClientError(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
372+
return this.cannedMetric(ApiGatewayMetrics._4XxErrorSum, props);
373+
}
374+
375+
/**
376+
* Metric for the number of server-side errors captured in a given period.
377+
*
378+
* @default - sum over 5 minutes
379+
*/
380+
public metricServerError(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
381+
return this.cannedMetric(ApiGatewayMetrics._5XxErrorSum, props);
382+
}
383+
384+
/**
385+
* Metric for the number of requests served from the API cache in a given period.
386+
*
387+
* @default - sum over 5 minutes
388+
*/
389+
public metricCacheHitCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
390+
return this.cannedMetric(ApiGatewayMetrics.cacheHitCountSum, props);
391+
}
392+
393+
/**
394+
* Metric for the number of requests served from the backend in a given period,
395+
* when API caching is enabled.
396+
*
397+
* @default - sum over 5 minutes
398+
*/
399+
public metricCacheMissCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
400+
return this.cannedMetric(ApiGatewayMetrics.cacheMissCountSum, props);
401+
}
402+
403+
/**
404+
* Metric for the total number API requests in a given period.
405+
*
406+
* @default - sample count over 5 minutes
407+
*/
408+
public metricCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
409+
return this.cannedMetric(ApiGatewayMetrics.countSum, {
410+
statistic: 'SampleCount',
411+
...props,
412+
});
413+
}
414+
415+
/**
416+
* Metric for the time between when API Gateway relays a request to the backend
417+
* and when it receives a response from the backend.
418+
*
419+
* @default - average over 5 minutes.
420+
*/
421+
public metricIntegrationLatency(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
422+
return this.cannedMetric(ApiGatewayMetrics.integrationLatencyAverage, props);
423+
}
424+
425+
/**
426+
* The time between when API Gateway receives a request from a client
427+
* and when it returns a response to the client.
428+
* The latency includes the integration latency and other API Gateway overhead.
429+
*
430+
* @default - average over 5 minutes.
431+
*/
432+
public metricLatency(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
433+
return this.cannedMetric(ApiGatewayMetrics.latencyAverage, props);
434+
}
435+
436+
private cannedMetric(fn: (dims: { ApiName: string; Stage: string }) => cloudwatch.MetricProps, props?: cloudwatch.MetricOptions) {
437+
return new cloudwatch.Metric({
438+
...fn({ ApiName: this.restApi.restApiName, Stage: this.stageName }),
439+
...props,
440+
}).attachTo(this);
441+
}
351442
}

packages/@aws-cdk/aws-apigateway/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
},
8181
"license": "Apache-2.0",
8282
"devDependencies": {
83+
"@aws-cdk/integ-tests": "0.0.0",
8384
"@aws-cdk/assertions": "0.0.0",
8485
"@aws-cdk/cdk-build-tools": "0.0.0",
8586
"@aws-cdk/integ-runner": "0.0.0",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
2+
import * as cdk from '@aws-cdk/core';
3+
import * as integ from '@aws-cdk/integ-tests';
4+
import * as apigw from '../lib';
5+
6+
const app = new cdk.App();
7+
const stack = new cdk.Stack(app, 'restapi-metrics');
8+
const restApi = new apigw.RestApi(stack, 'Api');
9+
const stage = restApi.deploymentStage;
10+
const method = restApi.root.addMethod('GET');
11+
12+
new cloudwatch.Alarm(stack, 'RestApiAlarm', {
13+
metric: restApi.metricClientError(),
14+
evaluationPeriods: 1,
15+
threshold: 1,
16+
});
17+
18+
new cloudwatch.Alarm(stack, 'MethodAlarm', {
19+
metric: method.metricServerError(stage),
20+
evaluationPeriods: 1,
21+
threshold: 1,
22+
});
23+
24+
new cloudwatch.Alarm(stack, 'StageAlarm', {
25+
metric: stage.metricCount(),
26+
evaluationPeriods: 1,
27+
threshold: 1,
28+
});
29+
30+
new integ.IntegTest(app, 'MetricsTest', {
31+
testCases: [stack],
32+
});
33+
34+
app.synth();

0 commit comments

Comments
 (0)