Skip to content

Commit

Permalink
Merge branch 'main' into add-websocket-iam-authorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
d0z0 authored Aug 4, 2022
2 parents 0c6890a + 7ccc644 commit 7177dc1
Show file tree
Hide file tree
Showing 186 changed files with 7,916 additions and 1,033 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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.

## [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)


### Bug Fixes

* **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)

## [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)

## [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)
Expand Down
31 changes: 31 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

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.

## [2.35.0](https://github.com/aws/aws-cdk/compare/v2.34.2...v2.35.0) (2022-08-02)


### Features

* **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)
* **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)
* **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)
* **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)
* **fsx:** support AutoImportPolicy in LustreFilesystem ([#21301](https://github.com/aws/aws-cdk/issues/21301)) ([b1ce472](https://github.com/aws/aws-cdk/commit/b1ce472ed2a15480980286f21a028fdc20cdb91d))
* **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)
* **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)
* **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)
* **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)


### Bug Fixes

* **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))
* **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)
* **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)
* **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)
* **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)
* **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)
* **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)


### Reverts

* **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)

## [2.34.2](https://github.com/aws/aws-cdk/compare/v2.34.1...v2.34.2) (2022-07-29)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"devDependencies": {
"@types/prettier": "2.6.0",
"@yarnpkg/lockfile": "^1.1.0",
"cdk-generate-synthetic-examples": "^0.1.12",
"cdk-generate-synthetic-examples": "^0.1.14",
"conventional-changelog-cli": "^2.2.2",
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.10",
Expand Down
14 changes: 10 additions & 4 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1305,13 +1305,19 @@ in your openApi file.
## Metrics

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

```ts
const api = new apigateway.RestApi(this, 'my-api');
const clientErrorMetric = api.metricClientError();
const stage = api.deploymentStage;
const method = api.root.addMethod('GET');

const clientErrorApiMetric = api.metricClientError();
const serverErrorStageMetric = stage.metricServerError();
const latencyMethodMetric = method.metricLatency(stage);
```

## APIGateway v2
Expand Down
97 changes: 97 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { ArnFormat, Lazy, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
import { CfnMethod, CfnMethodProps } from './apigateway.generated';
import { Authorizer, IAuthorizer } from './authorizer';
import { Integration, IntegrationConfig } from './integration';
Expand All @@ -9,6 +11,7 @@ import { IModel } from './model';
import { IRequestValidator, RequestValidatorOptions } from './requestvalidator';
import { IResource } from './resource';
import { IRestApi, RestApi, RestApiBase } from './restapi';
import { IStage } from './stage';
import { validateHttpMethod } from './util';

export interface MethodOptions {
Expand Down Expand Up @@ -364,6 +367,100 @@ export class Method extends Resource {
// For backward compatibility
return options.requestValidator?.requestValidatorId;
}

/**
* Returns the given named metric for this API method
*/
public metric(metricName: string, stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/ApiGateway',
metricName,
dimensionsMap: { ApiName: this.api.restApiName, Method: this.httpMethod, Resource: this.resource.path, Stage: stage.stageName },
...props,
}).attachTo(this);
}

/**
* Metric for the number of client-side errors captured in a given period.
*
* @default - sum over 5 minutes
*/
public metricClientError(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics._4XxErrorSum, stage, props);
}

/**
* Metric for the number of server-side errors captured in a given period.
*
* @default - sum over 5 minutes
*/
public metricServerError(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics._5XxErrorSum, stage, props);
}

/**
* Metric for the number of requests served from the API cache in a given period.
*
* @default - sum over 5 minutes
*/
public metricCacheHitCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.cacheHitCountSum, stage, props);
}

/**
* Metric for the number of requests served from the backend in a given period,
* when API caching is enabled.
*
* @default - sum over 5 minutes
*/
public metricCacheMissCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.cacheMissCountSum, stage, props);
}

/**
* Metric for the total number API requests in a given period.
*
* @default - sample count over 5 minutes
*/
public metricCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.countSum, stage, {
statistic: 'SampleCount',
...props,
});
}

/**
* Metric for the time between when API Gateway relays a request to the backend
* and when it receives a response from the backend.
*
* @default - average over 5 minutes.
*/
public metricIntegrationLatency(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.integrationLatencyAverage, stage, props);
}

/**
* The time between when API Gateway receives a request from a client
* and when it returns a response to the client.
* The latency includes the integration latency and other API Gateway overhead.
*
* @default - average over 5 minutes.
*/
public metricLatency(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.latencyAverage, stage, props);
}

private cannedMetric(fn: (dims: {
ApiName: string;
Method: string;
Resource: string;
Stage: string;
}) => cloudwatch.MetricProps, stage: IStage, props?: cloudwatch.MetricOptions) {
return new cloudwatch.Metric({
...fn({ ApiName: this.api.restApiName, Method: this.httpMethod, Resource: this.resource.path, Stage: stage.stageName }),
...props,
}).attachTo(this);
}
}

export enum AuthorizationType {
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export interface IRestApi extends IResourceBase {
*/
readonly restApiId: string;

/**
* The name of this API Gateway RestApi.
* @attribute
*/
readonly restApiName: string;

/**
* The resource ID of the root resource.
* @attribute
Expand Down Expand Up @@ -673,6 +679,13 @@ export interface RestApiAttributes {
*/
readonly restApiId: string;

/**
* The name of the API Gateway RestApi.
*
* @default - ID of the RestApi construct.
*/
readonly restApiName?: string;

/**
* The resource ID of the root resource.
*/
Expand Down Expand Up @@ -713,6 +726,7 @@ export class RestApi extends RestApiBase {
public static fromRestApiAttributes(scope: Construct, id: string, attrs: RestApiAttributes): IRestApi {
class Import extends RestApiBase {
public readonly restApiId = attrs.restApiId;
public readonly restApiName = attrs.restApiName ?? id;
public readonly restApiRootResourceId = attrs.rootResourceId;
public readonly root: IResource = new RootResource(this, {}, this.restApiRootResourceId);
}
Expand Down
91 changes: 91 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/stage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { ArnFormat, Duration, IResource, Resource, Stack, Token } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { AccessLogFormat, IAccessLogDestination } from './access-log';
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
import { CfnStage } from './apigateway.generated';
import { Deployment } from './deployment';
import { IRestApi, RestApiBase } from './restapi';
Expand Down Expand Up @@ -348,4 +350,93 @@ export class Stage extends Resource implements IStage {
};
}
}

/**
* Returns the given named metric for this stage
*/
public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/ApiGateway',
metricName,
dimensionsMap: { ApiName: this.restApi.restApiName, Stage: this.stageName },
...props,
}).attachTo(this);
}

/**
* Metric for the number of client-side errors captured in a given period.
*
* @default - sum over 5 minutes
*/
public metricClientError(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics._4XxErrorSum, props);
}

/**
* Metric for the number of server-side errors captured in a given period.
*
* @default - sum over 5 minutes
*/
public metricServerError(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics._5XxErrorSum, props);
}

/**
* Metric for the number of requests served from the API cache in a given period.
*
* @default - sum over 5 minutes
*/
public metricCacheHitCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.cacheHitCountSum, props);
}

/**
* Metric for the number of requests served from the backend in a given period,
* when API caching is enabled.
*
* @default - sum over 5 minutes
*/
public metricCacheMissCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.cacheMissCountSum, props);
}

/**
* Metric for the total number API requests in a given period.
*
* @default - sample count over 5 minutes
*/
public metricCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.countSum, {
statistic: 'SampleCount',
...props,
});
}

/**
* Metric for the time between when API Gateway relays a request to the backend
* and when it receives a response from the backend.
*
* @default - average over 5 minutes.
*/
public metricIntegrationLatency(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.integrationLatencyAverage, props);
}

/**
* The time between when API Gateway receives a request from a client
* and when it returns a response to the client.
* The latency includes the integration latency and other API Gateway overhead.
*
* @default - average over 5 minutes.
*/
public metricLatency(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.cannedMetric(ApiGatewayMetrics.latencyAverage, props);
}

private cannedMetric(fn: (dims: { ApiName: string; Stage: string }) => cloudwatch.MetricProps, props?: cloudwatch.MetricOptions) {
return new cloudwatch.Metric({
...fn({ ApiName: this.restApi.restApiName, Stage: this.stageName }),
...props,
}).attachTo(this);
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/integ-tests": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "0.0.0",
Expand Down
34 changes: 34 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/integ.restapi-metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as cdk from '@aws-cdk/core';
import * as integ from '@aws-cdk/integ-tests';
import * as apigw from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'restapi-metrics');
const restApi = new apigw.RestApi(stack, 'Api');
const stage = restApi.deploymentStage;
const method = restApi.root.addMethod('GET');

new cloudwatch.Alarm(stack, 'RestApiAlarm', {
metric: restApi.metricClientError(),
evaluationPeriods: 1,
threshold: 1,
});

new cloudwatch.Alarm(stack, 'MethodAlarm', {
metric: method.metricServerError(stage),
evaluationPeriods: 1,
threshold: 1,
});

new cloudwatch.Alarm(stack, 'StageAlarm', {
metric: stage.metricCount(),
evaluationPeriods: 1,
threshold: 1,
});

new integ.IntegTest(app, 'MetricsTest', {
testCases: [stack],
});

app.synth();
Loading

0 comments on commit 7177dc1

Please sign in to comment.