Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Nov 19, 2021
2 parents 06b835a + 55df760 commit 93db006
Show file tree
Hide file tree
Showing 12 changed files with 645 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-lambda/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ describe('code', () => {
expect(stack).toHaveResource('AWS::Lambda::Function', {
Metadata: {
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232',
[cxapi.ASSET_RESOURCE_METADATA_ORIGINAL_PATH_KEY]: location,
[cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false,
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code',
},
}, ResourcePart.CompleteDefinition);
Expand Down Expand Up @@ -462,8 +464,9 @@ describe('code', () => {
stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true);

// when
const FunctionCodepath = path.join(__dirname, 'docker-build-lambda');
new lambda.Function(stack, 'Fn', {
code: lambda.Code.fromDockerBuild(path.join(__dirname, 'docker-build-lambda')),
code: lambda.Code.fromDockerBuild(FunctionCodepath),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_12_X,
});
Expand All @@ -472,6 +475,8 @@ describe('code', () => {
expect(stack).toHaveResource('AWS::Lambda::Function', {
Metadata: {
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.fbafdbb9ae8d1bae0def415b791a93c486d18ebc63270c748abecc3ac0ab9533',
[cxapi.ASSET_RESOURCE_METADATA_ORIGINAL_PATH_KEY]: FunctionCodepath,
[cxapi.ASSET_RESOURCE_METADATA_IS_BUNDLED_KEY]: false,
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code',
},
}, ResourcePart.CompleteDefinition);
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-lambda/test/layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ describe('layers', () => {
stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true);

// WHEN
let layerCodePath = path.join(__dirname, 'layer-code');
new lambda.LayerVersion(stack, 'layer', {
code: lambda.Code.fromAsset(path.join(__dirname, 'layer-code')),
code: lambda.Code.fromAsset(layerCodePath),
});

// THEN
expect(canonicalizeTemplate(SynthUtils.toCloudFormation(stack))).toHaveResource('AWS::Lambda::LayerVersion', {
Metadata: {
'aws:asset:path': 'asset.Asset1Hash',
'aws:asset:original-path': layerCodePath,
'aws:asset:is-bundled': false,
'aws:asset:property': 'Content',
},
}, ResourcePart.CompleteDefinition);
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-logs/test/log-retention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ describe('log retention', () => {
expect(stack).toHaveResource('AWS::Lambda::Function', {
Metadata: {
'aws:asset:path': assetLocation,
'aws:asset:original-path': assetLocation,
'aws:asset:is-bundled': false,
'aws:asset:property': 'Code',
},
}, ResourcePart.CompleteDefinition);
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ new rds.DatabaseInstanceReadReplica(this, 'ReadReplica', {
});
```

Automatic backups of read replica instances are only supported for MySQL and MariaDB. By default,
automatic backups are disabled for read replicas and can only be enabled (using `backupRetention`)
if also enabled on the source instance.

Creating a "production" Oracle database instance with option and parameter groups:

[example of setting up a production oracle instance](test/integ.instance.lit.ts)
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/instance-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export interface IInstanceEngine extends IEngine {
/** The application used by this engine to perform rotation for a multi-user scenario. */
readonly multiUserRotationApplication: secretsmanager.SecretRotationApplication;

/**
* Whether this engine supports automatic backups of a read replica instance.
*
* @default false
*/
readonly supportsReadReplicaBackups?: boolean;

/**
* Method called when the engine is used to create a new instance.
*/
Expand All @@ -123,6 +130,7 @@ abstract class InstanceEngineBase implements IInstanceEngine {
public readonly singleUserRotationApplication: secretsmanager.SecretRotationApplication;
public readonly multiUserRotationApplication: secretsmanager.SecretRotationApplication;
public readonly engineFamily?: string;
public readonly supportsReadReplicaBackups?: boolean;

private readonly features?: InstanceEngineFeatures;

Expand Down Expand Up @@ -320,6 +328,8 @@ export interface MariaDbInstanceEngineProps {
}

class MariaDbInstanceEngine extends InstanceEngineBase {
public readonly supportsReadReplicaBackups = true;

constructor(version?: MariaDbEngineVersion) {
super({
engineType: 'mariadb',
Expand Down Expand Up @@ -533,6 +543,8 @@ export interface MySqlInstanceEngineProps {
}

class MySqlInstanceEngine extends InstanceEngineBase {
public readonly supportsReadReplicaBackups = true;

constructor(version?: MysqlEngineVersion) {
super({
engineType: 'mysql',
Expand Down
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export interface DatabaseInstanceNewProps {
* When creating a read replica, you must enable automatic backups on the source
* database instance by setting the backup retention to a value other than zero.
*
* @default Duration.days(1)
* @default - Duration.days(1) for source instances, disabled for read replicas
*/
readonly backupRetention?: Duration;

Expand Down Expand Up @@ -1143,6 +1143,12 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
constructor(scope: Construct, id: string, props: DatabaseInstanceReadReplicaProps) {
super(scope, id, props);

if (props.sourceDatabaseInstance.engine
&& !props.sourceDatabaseInstance.engine.supportsReadReplicaBackups
&& props.backupRetention) {
throw new Error(`Cannot set 'backupRetention', as engine '${engineDescription(props.sourceDatabaseInstance.engine)}' does not support automatic backups for read replicas`);
}

const instance = new CfnDBInstance(this, 'Resource', {
...this.newCfnProps,
// this must be ARN, not ID, because of https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-rds/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,26 @@ describe('instance', () => {
});
});

test('throws with backupRetention on a read replica if engine does not support it', () => {
// GIVEN
const instanceType = ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL);
const backupRetention = cdk.Duration.days(5);
const source = new rds.DatabaseInstance(stack, 'Source', {
engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_13 }),
backupRetention,
instanceType,
vpc,
});

expect(() => {
new rds.DatabaseInstanceReadReplica(stack, 'Replica', {
sourceDatabaseInstance: source,
backupRetention,
instanceType,
vpc,
});
}).toThrow(/Cannot set 'backupRetention', as engine 'postgres-13' does not support automatic backups for read replicas/);
});
});

test.each([
Expand Down
Loading

0 comments on commit 93db006

Please sign in to comment.