Skip to content

Commit

Permalink
Merge branch 'master' into hotswap_inline_lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
tmokmss committed Jan 15, 2022
2 parents a131157 + 626e6aa commit d031faa
Show file tree
Hide file tree
Showing 34 changed files with 2,833 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $ yarn install
```

We recommend that you use [Visual Studio Code](https://code.visualstudio.com/) to work on the CDK.
We use `eslint` to keep our code consistent in terms of style and reducing defects. We recommend installing the
We use `eslint` to keep our code consistent in terms of style and reducing defects. We recommend installing
the [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) as well.

### Repo Layout
Expand Down Expand Up @@ -726,7 +726,7 @@ these directories.
### Linking against this repository

If you are developing your own CDK application or library and want to use the locally checked out version of the
AWS CDK, instead of the the version of npm, the `./link-all.sh` script will help here.
AWS CDK, instead of the version of npm, the `./link-all.sh` script will help here.

This script symlinks the built modules from the local AWS CDK repo under the `node_modules/` folder of the CDK app or
library.
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ApiKey extends ApiKeyBase {
const resource = new CfnApiKey(this, 'Resource', {
customerId: props.customerId,
description: props.description,
enabled: props.enabled || true,
enabled: props.enabled ?? true,
generateDistinctId: props.generateDistinctId,
name: this.physicalName,
stageKeys: this.renderStageKeys(props.resources),
Expand Down
61 changes: 54 additions & 7 deletions packages/@aws-cdk/aws-apigateway/test/api-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,33 @@ describe('api key', () => {
// should have an api key with no props defined.
});


test('enabled flag is respected', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new apigateway.ApiKey(stack, 'my-api-key', {
enabled: false,
value: 'arandomstringwithmorethantwentycharacters',
});

// THEN
expect(stack).toHaveResource('AWS::ApiGateway::ApiKey', {
Enabled: false,
Value: 'arandomstringwithmorethantwentycharacters',
});
});


test('specify props for apiKey', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down Expand Up @@ -61,7 +84,11 @@ describe('api key', () => {
test('use an imported api key', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand All @@ -83,7 +110,11 @@ describe('api key', () => {
// GIVEN
const stack = new cdk.Stack();
const user = new iam.User(stack, 'User');
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down Expand Up @@ -130,7 +161,11 @@ describe('api key', () => {
// GIVEN
const stack = new cdk.Stack();
const user = new iam.User(stack, 'User');
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down Expand Up @@ -182,7 +217,11 @@ describe('api key', () => {
// GIVEN
const stack = new cdk.Stack();
const user = new iam.User(stack, 'User');
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down Expand Up @@ -253,7 +292,11 @@ describe('api key', () => {
test('only api key is created when rate limiting properties are not provided', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down Expand Up @@ -281,7 +324,11 @@ describe('api key', () => {
test('api key and usage plan are created and linked when rate limiting properties are provided', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: true,
deployOptions: { stageName: 'test' },
});
api.root.addMethod('GET'); // api must have atleast one method.

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ export class TargetTrackingScalingPolicy extends CoreConstruct {

super(scope, id);

// replace dummy value in DYNAMODB_WRITE_CAPACITY_UTILIZATION due to a jsii bug (https://github.com/aws/jsii/issues/2782)
const predefinedMetric = props.predefinedMetric === PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION ?
PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION :
props.predefinedMetric;

const resource = new CfnScalingPolicy(this, 'Resource', {
policyName: props.policyName || cdk.Names.uniqueId(this),
policyType: 'TargetTrackingScaling',
scalingTargetId: props.scalingTarget.scalableTargetId,
targetTrackingScalingPolicyConfiguration: {
customizedMetricSpecification: renderCustomMetric(props.customMetric),
disableScaleIn: props.disableScaleIn,
predefinedMetricSpecification: props.predefinedMetric !== undefined ? {
predefinedMetricType: props.predefinedMetric,
predefinedMetricSpecification: predefinedMetric !== undefined ? {
predefinedMetricType: predefinedMetric,
resourceLabel: props.resourceLabel,
} : undefined,
scaleInCooldown: props.scaleInCooldown && props.scaleInCooldown.toSeconds(),
Expand Down Expand Up @@ -183,9 +188,20 @@ export enum PredefinedMetric {
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_READ_CAPACITY_UTILIZATION = 'DynamoDBReadCapacityUtilization',
/**
* DYNAMODB_WRITE_CAPACITY_UTILIZATION
*
* Suffix `dummy` is necessary due to jsii bug (https://github.com/aws/jsii/issues/2782).
* Duplicate values will be dropped, so this suffix is added as a workaround.
* The value will be replaced when this enum is used.
*
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization-dummy',
/**
* DYANMODB_WRITE_CAPACITY_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
* @deprecated use `PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION`
*/
DYANMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization',
/**
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.StepScalingPolicyProps",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ECS_SERVICE_AVERAGE_CPU_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ALB_REQUEST_COUNT_PER_TARGET",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.RDS_READER_AVERAGE_CPU_UTILIZATION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ describe('target tracking', () => {

});

test('test setup target tracking on predefined metric for DYNAMODB_WRITE_CAPACITY_UTILIZATION', () => {
// GIVEN
const stack = new cdk.Stack();
const target = createScalableTarget(stack);

// WHEN
target.scaleToTrackMetric('Tracking', {
predefinedMetric: appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION,
targetValue: 0.9,
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
TargetTrackingScalingPolicyConfiguration: {
PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBWriteCapacityUtilization' },
TargetValue: 0.9,
},
});
});

test('test setup target tracking on custom metric', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-cognito-identitypool/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
module.exports = baseConfig;
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-cognito-identitypool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.js
*.js.map
*.d.ts
tsconfig.json
node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
!jest.config.js

junit.xml
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-cognito-identitypool/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz

dist
.LAST_PACKAGE
.LAST_BUILD
!*.js

# Include .jsii
!.jsii

*.snk

*.tsbuildinfo

tsconfig.json
.eslintrc.js
jest.config.js

# exclude cdk artifacts
**/cdk.out
junit.xml
test/
!*.lit.ts
Loading

0 comments on commit d031faa

Please sign in to comment.