From 375a1572073001232fb9c1c96bb8c1b689e2535d Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Fri, 28 Feb 2020 18:08:12 +0530 Subject: [PATCH 01/19] fix(apigateway): Allows configuring authorization scopes in apigateway method fixes#6390 --- .../@aws-cdk/aws-apigateway/lib/method.ts | 9 +++- .../aws-apigateway/test/test.method.ts | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 438a2d1601e8f..93bcd6443f494 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -75,6 +75,12 @@ export interface MethodOptions { * The ID of the associated request validator. */ readonly requestValidator?: IRequestValidator; + + /** + * The authorizationScopes for the method + * @default none + */ + readonly authorizationScopes?: string[] } export interface MethodProps { @@ -152,7 +158,8 @@ export class Method extends Resource { integration: this.renderIntegration(props.integration), methodResponses: this.renderMethodResponses(options.methodResponses), requestModels: this.renderRequestModels(options.requestModels), - requestValidatorId: options.requestValidator ? options.requestValidator.requestValidatorId : undefined + requestValidatorId: options.requestValidator ? options.requestValidator.requestValidatorId : undefined, + authorizationScopes: options.authorizationScopes || defaultMethodOptions.authorizationScopes }; const resource = new CfnMethod(this, 'Resource', methodProps); diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index ef799d8c65225..290dfc16f3bd1 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -693,6 +693,57 @@ export = { }); }, /Authorization type is set to NONE which is different from what is required by the authorizer/); + test.done(); + }, + 'method has Auth Scopes'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: false }); + + // WHEN + new apigw.Method(stack, 'my-method', { + httpMethod: 'POST', + resource: api.root, + options: { + apiKeyRequired: true, + authorizationScopes: ['AuthScope1', 'AuthScope2'], + } + }); + + // THEN + expect(stack).to(haveResource('AWS::ApiGateway::Method', { + ApiKeyRequired: true, + authorizationScopes: ['AuthScope1', 'AuthScope2'] + })); + + test.done(); + }, + 'use default Auth Scopes'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'test-api', { + cloudWatchRole: false, + deploy: false, + defaultMethodOptions: { + authorizationScopes: ['DefaultAuth'] + } + }); + + // WHEN + new apigw.Method(stack, 'defaultAuthScopes', { + httpMethod: 'POST', + resource: api.root, + options: { + operationName: 'defaultAuthScopes' + } + }); + + // THEN + expect(stack).to(haveResource('AWS::ApiGateway::Method', { + OperationName: 'defaultAuthScopes', + authorizationScopes: ['DefaultAuth'] + })); + test.done(); } }; From 37249b23e51ffcd8966063394fb6d6b9b9d5c533 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Fri, 28 Feb 2020 18:42:09 +0530 Subject: [PATCH 02/19] Fixes build failure for Case sensitive fields --- packages/@aws-cdk/aws-apigateway/test/test.method.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index 290dfc16f3bd1..6e3ffaa12de1b 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -713,7 +713,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::ApiGateway::Method', { ApiKeyRequired: true, - authorizationScopes: ['AuthScope1', 'AuthScope2'] + AuthorizationScopes: ['AuthScope1', 'AuthScope2'] })); test.done(); @@ -741,7 +741,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::ApiGateway::Method', { OperationName: 'defaultAuthScopes', - authorizationScopes: ['DefaultAuth'] + AuthorizationScopes: ['DefaultAuth'] })); test.done(); From 71ab43336874829fd25c769ffb8f73db42b97f90 Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Thu, 5 Mar 2020 14:48:59 +0530 Subject: [PATCH 03/19] Update packages/@aws-cdk/aws-apigateway/lib/method.ts Co-Authored-By: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> --- packages/@aws-cdk/aws-apigateway/lib/method.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 93bcd6443f494..f0dc854634223 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -77,7 +77,9 @@ export interface MethodOptions { readonly requestValidator?: IRequestValidator; /** - * The authorizationScopes for the method + * A list of authorization scopes configured on the method. The scopes are used with + * a COGNITO_USER_POOLS authorizer to authorize the method invocation. + * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes * @default none */ readonly authorizationScopes?: string[] From 26c31ea1b92ee9bb6a45cd577c89b4a8f4a51a44 Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Thu, 5 Mar 2020 14:49:34 +0530 Subject: [PATCH 04/19] Update packages/@aws-cdk/aws-apigateway/lib/method.ts Co-Authored-By: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> --- packages/@aws-cdk/aws-apigateway/lib/method.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index f0dc854634223..6a9e28a7e6e9a 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -80,7 +80,7 @@ export interface MethodOptions { * A list of authorization scopes configured on the method. The scopes are used with * a COGNITO_USER_POOLS authorizer to authorize the method invocation. * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes - * @default none + * @default - no authorization scopes */ readonly authorizationScopes?: string[] } From 14dfbe726c9b9b9955b2c466d8f6003ed92f82cd Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Thu, 5 Mar 2020 14:50:56 +0530 Subject: [PATCH 05/19] Update packages/@aws-cdk/aws-apigateway/lib/method.ts Co-Authored-By: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> --- packages/@aws-cdk/aws-apigateway/lib/method.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 6a9e28a7e6e9a..3f00a94596dae 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -161,7 +161,7 @@ export class Method extends Resource { methodResponses: this.renderMethodResponses(options.methodResponses), requestModels: this.renderRequestModels(options.requestModels), requestValidatorId: options.requestValidator ? options.requestValidator.requestValidatorId : undefined, - authorizationScopes: options.authorizationScopes || defaultMethodOptions.authorizationScopes + authorizationScopes: options.authorizationScopes ?? defaultMethodOptions.authorizationScopes, }; const resource = new CfnMethod(this, 'Resource', methodProps); From 4612c8337017892b74726971cdcbc1bf682816f3 Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Thu, 5 Mar 2020 14:51:18 +0530 Subject: [PATCH 06/19] Update packages/@aws-cdk/aws-apigateway/test/test.method.ts Co-Authored-By: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> --- packages/@aws-cdk/aws-apigateway/test/test.method.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index 6e3ffaa12de1b..f81c848089734 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -695,6 +695,7 @@ export = { test.done(); }, + 'method has Auth Scopes'(test: Test) { // GIVEN const stack = new cdk.Stack(); From 87cbb71cccbb4be93f5d665809c77e8e6ce5ed3d Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Thu, 5 Mar 2020 14:51:35 +0530 Subject: [PATCH 07/19] Update packages/@aws-cdk/aws-apigateway/test/test.method.ts Co-Authored-By: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> --- packages/@aws-cdk/aws-apigateway/test/test.method.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index f81c848089734..4d17e7b58f7d3 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -719,6 +719,7 @@ export = { test.done(); }, + 'use default Auth Scopes'(test: Test) { // GIVEN const stack = new cdk.Stack(); From 49d3752d2fb718fd0395c121e34b00e88a8f8cb3 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Thu, 5 Mar 2020 15:05:08 +0530 Subject: [PATCH 08/19] Added test cases to cover auth scopes absent and method options auth scope take the priority in case method options and default options are passed --- .../aws-apigateway/test/test.method.ts | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index 4d17e7b58f7d3..f4c5052e1ec40 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -1,4 +1,4 @@ -import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; +import { ABSENT, expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import * as iam from '@aws-cdk/aws-iam'; @@ -746,6 +746,62 @@ export = { AuthorizationScopes: ['DefaultAuth'] })); + test.done(); + }, + + 'Method options Auth Scopes is picked up'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'test-api', { + cloudWatchRole: false, + deploy: false, + defaultMethodOptions: { + authorizationScopes: ['DefaultAuth'] + } + }); + + // WHEN + new apigw.Method(stack, 'MethodAuthScopeUsed', { + httpMethod: 'POST', + resource: api.root, + options: { + apiKeyRequired: true, + authorizationScopes: ['MethodAuthScope'], + } + }); + + // THEN + expect(stack).to(haveResource('AWS::ApiGateway::Method', { + ApiKeyRequired: true, + AuthorizationScopes: ['MethodAuthScope'] + })); + + test.done(); + }, + + 'Auth Scopes absent'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigw.RestApi(stack, 'test-api', { + cloudWatchRole: false, + deploy: false + }); + + // WHEN + new apigw.Method(stack, 'authScopesAbsent', { + httpMethod: 'POST', + resource: api.root, + options: { + operationName: 'authScopesAbsent' + } + }); + + // THEN + expect(stack).to(haveResource('AWS::ApiGateway::Method', { + OperationName: 'authScopesAbsent', + AuthorizationScopes: ABSENT + })); + test.done(); } }; From 3399253ab4b891d4be259e418decc12a83241585 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Thu, 5 Mar 2020 15:21:12 +0530 Subject: [PATCH 09/19] Updating readme for authorizationScopes --- packages/@aws-cdk/aws-apigateway/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/@aws-cdk/aws-apigateway/README.md b/packages/@aws-cdk/aws-apigateway/README.md index a2367e302a613..f74948ba1a4c7 100644 --- a/packages/@aws-cdk/aws-apigateway/README.md +++ b/packages/@aws-cdk/aws-apigateway/README.md @@ -678,6 +678,15 @@ properties and new resource types will not be available. Move to using `aws-apigatewayv2` to get the latest APIs and updates. +## Configure AuthorizationScopes for a method +AuthorizationScopes are used with COGNITO_USER_POOLS to authorize method invocation. More info about AuthorizationScopes can be found [here] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes + +```ts +books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), { + authorizationType: AuthorizationType.COGNITO, + authorizationScopes: ['Scope1','Scope2'] +}); +``` ---- This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. From 913df3803cb15e0373bcc110bb8099c0059cf1d5 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Thu, 5 Mar 2020 15:46:36 +0530 Subject: [PATCH 10/19] removing trailing white space to fix @aws-cdk/aws-apigateway: ERROR: /codebuild/output/src052287507/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-apigateway/lib/method.ts:80:87 - trailing whitespace --- packages/@aws-cdk/aws-apigateway/lib/method.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 3f00a94596dae..9b43cec12d593 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -77,7 +77,7 @@ export interface MethodOptions { readonly requestValidator?: IRequestValidator; /** - * A list of authorization scopes configured on the method. The scopes are used with + * A list of authorization scopes configured on the method. The scopes are used with * a COGNITO_USER_POOLS authorizer to authorize the method invocation. * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes * @default - no authorization scopes From 6b3e232db40b0f920c3254cfe9770610ddca6ff7 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Fri, 13 Mar 2020 09:09:45 +0530 Subject: [PATCH 11/19] adds comments under default integration and method section. --- packages/@aws-cdk/aws-apigateway/README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/README.md b/packages/@aws-cdk/aws-apigateway/README.md index f74948ba1a4c7..9d763091844da 100644 --- a/packages/@aws-cdk/aws-apigateway/README.md +++ b/packages/@aws-cdk/aws-apigateway/README.md @@ -322,6 +322,18 @@ const book = books.addResource('{book_id}'); book.addMethod('GET'); // integrated with `booksBackend` ``` +A method can be configured with authorization scopes. The scopes are used with a COGNITO_USER_POOLS authorizer to +authorize the method invocation. When the method scope is configured, the client must provide an access token instead +of an identity token for authorization purposes. Read more about authorization scopes +[here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes). +Authorization scopes for a Method can be configured via the `authorizationScopes` property as shown below - +```ts +books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), { + authorizationType: AuthorizationType.COGNITO, + authorizationScopes: ['Scope1','Scope2'] +}); +``` + ### Proxy Routes The `addProxy` method can be used to install a greedy `{proxy+}` resource @@ -678,15 +690,6 @@ properties and new resource types will not be available. Move to using `aws-apigatewayv2` to get the latest APIs and updates. -## Configure AuthorizationScopes for a method -AuthorizationScopes are used with COGNITO_USER_POOLS to authorize method invocation. More info about AuthorizationScopes can be found [here] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes - -```ts -books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), { - authorizationType: AuthorizationType.COGNITO, - authorizationScopes: ['Scope1','Scope2'] -}); -``` ---- This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. From 5cea74b6d851d4ef856df9365f81d79e884e7439 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Fri, 13 Mar 2020 10:20:12 +0000 Subject: [PATCH 12/19] adjust lang in README --- packages/@aws-cdk/aws-apigateway/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/README.md b/packages/@aws-cdk/aws-apigateway/README.md index 424fd00a203fb..31cf3e03e1efc 100644 --- a/packages/@aws-cdk/aws-apigateway/README.md +++ b/packages/@aws-cdk/aws-apigateway/README.md @@ -352,11 +352,14 @@ const book = books.addResource('{book_id}'); book.addMethod('GET'); // integrated with `booksBackend` ``` -A method can be configured with authorization scopes. The scopes are used with a COGNITO_USER_POOLS authorizer to -authorize the method invocation. When the method scope is configured, the client must provide an access token instead -of an identity token for authorization purposes. Read more about authorization scopes +A Method can be configured with authorization scopes. Authorization scopes are +used in conjunction with an [authorizer that uses Amazon Cognito user +pools](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html#apigateway-enable-cognito-user-pool). +Read more about authorization scopes [here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes). -Authorization scopes for a Method can be configured via the `authorizationScopes` property as shown below - + +Authorization scopes for a Method can be configured using the `authorizationScopes` property as shown below - + ```ts books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), { authorizationType: AuthorizationType.COGNITO, From fcc79bf5d6c4ba913537dcdae52a2915e8e4acff Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Wed, 18 Mar 2020 16:01:57 +0530 Subject: [PATCH 13/19] feat(rds): configure maxAllocatedStorage for rds fixes #6666 --- packages/@aws-cdk/aws-rds/README.md | 15 ++++++ packages/@aws-cdk/aws-rds/lib/instance.ts | 9 +++- .../@aws-cdk/aws-rds/test/test.instance.ts | 46 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-rds/README.md b/packages/@aws-cdk/aws-rds/README.md index 527a05e72fc7d..88ce3326b26ff 100644 --- a/packages/@aws-cdk/aws-rds/README.md +++ b/packages/@aws-cdk/aws-rds/README.md @@ -76,6 +76,21 @@ new DatabaseInstanceReadReplica(stack, 'ReadReplica', { vpc }); ``` + +To use the storage auto scaling option of RDS you can specify the maximum allocated storage. +This is the upper limit to which RDS can automatically scale the storage. More info can be found +[here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-maxallocatedstorage) +Example for max storage configuration: +```ts +const instance = new DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.ORACLE_SE1, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), + masterUsername: 'syscdk', + vpc, + maxAllocatedStorage: 200 +}); +``` + Creating a "production" Oracle database instance with option and parameter groups: [example of setting up a production oracle instance](test/integ.instance.lit.ts) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 03e33c6c18fe1..8e54e8fc73be3 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -478,6 +478,12 @@ export interface DatabaseInstanceNewProps { * @default RemovalPolicy.Retain */ readonly removalPolicy?: RemovalPolicy + + /** + * Upper limit to which RDS can scale the storage + * @default - No default value + */ + readonly maxAllocatedStorage?: number; } /** @@ -567,7 +573,8 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures), publiclyAccessible: props.vpcPlacement && props.vpcPlacement.subnetType === ec2.SubnetType.PUBLIC, storageType, - vpcSecurityGroups: securityGroups.map(s => s.securityGroupId) + vpcSecurityGroups: securityGroups.map(s => s.securityGroupId), + maxAllocatedStorage: props.maxAllocatedStorage }; } diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 2052594ef691f..65f576811c80e 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -716,6 +716,52 @@ export = { }), /timezone property can be configured only for Microsoft SQL Server/); }); + test.done(); + }, + + 'create an instance from snapshot with maxiumum allocated storage'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + new rds.DatabaseInstanceFromSnapshot(stack, 'Instance', { + snapshotIdentifier: 'my-snapshot', + engine: rds.DatabaseInstanceEngine.POSTGRES, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.LARGE), + vpc, + maxAllocatedStorage: 200 + }); + + expect(stack).to(haveResource('AWS::RDS::DBInstance', { + DBSnapshotIdentifier: 'my-snapshot', + MaxAllocatedStorage: 200 + })); + + test.done(); + }, + + 'create a DB instance with maxiumum allocated storage'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + new rds.DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.MYSQL, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), + masterUsername: 'admin', + vpc, + backupRetention: cdk.Duration.seconds(0), + maxAllocatedStorage: 250 + }); + + // THEN + expect(stack).to(haveResource('AWS::RDS::DBInstance', { + BackupRetentionPeriod: 0, + MaxAllocatedStorage: 250 + })); + test.done(); } }; From 7b6fb747bfa5e91daec0ce28bdf42977a523f55e Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Mon, 23 Mar 2020 18:29:36 +0530 Subject: [PATCH 14/19] spell fix Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-rds/test/test.instance.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 65f576811c80e..83630cf5dd054 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -741,7 +741,7 @@ export = { test.done(); }, - 'create a DB instance with maxiumum allocated storage'(test: Test) { + 'create a DB instance with maximum allocated storage'(test: Test) { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); From 84f84b7f8ceac8c28256176c04048191b8325bc0 Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Mon, 23 Mar 2020 18:29:51 +0530 Subject: [PATCH 15/19] spell fix Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-rds/test/test.instance.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 83630cf5dd054..96c2c7c5bad29 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -719,7 +719,7 @@ export = { test.done(); }, - 'create an instance from snapshot with maxiumum allocated storage'(test: Test) { + 'create an instance from snapshot with maximum allocated storage'(test: Test) { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); From 7ffd5721f262db5dd883cd85b0ef2a15854cf27c Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Mon, 23 Mar 2020 18:30:22 +0530 Subject: [PATCH 16/19] Adding docs url Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-rds/lib/instance.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 8e54e8fc73be3..012f207722e52 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -481,6 +481,7 @@ export interface DatabaseInstanceNewProps { /** * Upper limit to which RDS can scale the storage + * @see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling * @default - No default value */ readonly maxAllocatedStorage?: number; From e1e2c23ec89739060471cdea89a0b349f85e03ad Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Mon, 23 Mar 2020 18:31:18 +0530 Subject: [PATCH 17/19] Correct url of autoscale document Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-rds/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-rds/README.md b/packages/@aws-cdk/aws-rds/README.md index 88ce3326b26ff..cec5246563fe1 100644 --- a/packages/@aws-cdk/aws-rds/README.md +++ b/packages/@aws-cdk/aws-rds/README.md @@ -79,7 +79,7 @@ new DatabaseInstanceReadReplica(stack, 'ReadReplica', { To use the storage auto scaling option of RDS you can specify the maximum allocated storage. This is the upper limit to which RDS can automatically scale the storage. More info can be found -[here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-maxallocatedstorage) +[here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling) Example for max storage configuration: ```ts const instance = new DatabaseInstance(stack, 'Instance', { From c6e6b4de4aa836b4af66799320d8f20e3a438703 Mon Sep 17 00:00:00 2001 From: nirvana124 Date: Mon, 23 Mar 2020 18:31:37 +0530 Subject: [PATCH 18/19] Adding new line Co-Authored-By: Niranjan Jayakar --- packages/@aws-cdk/aws-rds/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-rds/README.md b/packages/@aws-cdk/aws-rds/README.md index cec5246563fe1..9912089ba970c 100644 --- a/packages/@aws-cdk/aws-rds/README.md +++ b/packages/@aws-cdk/aws-rds/README.md @@ -81,6 +81,7 @@ To use the storage auto scaling option of RDS you can specify the maximum alloca This is the upper limit to which RDS can automatically scale the storage. More info can be found [here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling) Example for max storage configuration: + ```ts const instance = new DatabaseInstance(stack, 'Instance', { engine: rds.DatabaseInstanceEngine.ORACLE_SE1, From 8253fc2a6648ebdeeb865fca65f563d3868af24d Mon Sep 17 00:00:00 2001 From: Pankaj Yadav Date: Tue, 24 Mar 2020 10:00:15 +0530 Subject: [PATCH 19/19] Review comment fixes --- packages/@aws-cdk/aws-rds/README.md | 30 +++++++++++------------ packages/@aws-cdk/aws-rds/lib/instance.ts | 4 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/@aws-cdk/aws-rds/README.md b/packages/@aws-cdk/aws-rds/README.md index 9912089ba970c..cfa53cc0a4abc 100644 --- a/packages/@aws-cdk/aws-rds/README.md +++ b/packages/@aws-cdk/aws-rds/README.md @@ -58,6 +58,21 @@ const instance = new DatabaseInstance(stack, 'Instance', { ``` By default, the master password will be generated and stored in AWS Secrets Manager. +To use the storage auto scaling option of RDS you can specify the maximum allocated storage. +This is the upper limit to which RDS can automatically scale the storage. More info can be found +[here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling) +Example for max storage configuration: + +```ts +const instance = new DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.ORACLE_SE1, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), + masterUsername: 'syscdk', + vpc, + maxAllocatedStorage: 200 +}); +``` + Use `DatabaseInstanceFromSnapshot` and `DatabaseInstanceReadReplica` to create an instance from snapshot or a source database respectively: @@ -77,21 +92,6 @@ new DatabaseInstanceReadReplica(stack, 'ReadReplica', { }); ``` -To use the storage auto scaling option of RDS you can specify the maximum allocated storage. -This is the upper limit to which RDS can automatically scale the storage. More info can be found -[here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling) -Example for max storage configuration: - -```ts -const instance = new DatabaseInstance(stack, 'Instance', { - engine: rds.DatabaseInstanceEngine.ORACLE_SE1, - instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), - masterUsername: 'syscdk', - vpc, - maxAllocatedStorage: 200 -}); -``` - Creating a "production" Oracle database instance with option and parameter groups: [example of setting up a production oracle instance](test/integ.instance.lit.ts) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 012f207722e52..7971d5bdd55ad 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -480,9 +480,9 @@ export interface DatabaseInstanceNewProps { readonly removalPolicy?: RemovalPolicy /** - * Upper limit to which RDS can scale the storage + * Upper limit to which RDS can scale the storage in GiB(Gibibyte). * @see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling - * @default - No default value + * @default - No autoscaling of RDS instance */ readonly maxAllocatedStorage?: number; }