Skip to content

Commit

Permalink
Merge branch 'main' into otaviom/events-bus-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 7, 2022
2 parents 09f11db + bef86f6 commit cd1f9b5
Show file tree
Hide file tree
Showing 256 changed files with 5,290 additions and 500 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-efs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
});
```

⚠️ An Amazon EFS file system's performance mode can't be MAX_IO when its throughputMode is ELASTIC.

⚠️ An Amazon EFS file system's performance mode can't be changed after the file system has been created.
Updating this property will replace the file system.

Expand Down
18 changes: 16 additions & 2 deletions packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { CfnFileSystem, CfnMountTarget } from './efs.generated';
* @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-elasticfilesystem-filesystem-lifecyclepolicies
*/
export enum LifecyclePolicy {

/**
* After 1 day of not being accessed.
*/
AFTER_1_DAY = 'AFTER_1_DAY',

/**
* After 7 days of not being accessed.
*/
Expand Down Expand Up @@ -82,14 +88,19 @@ export enum PerformanceMode {
*/
export enum ThroughputMode {
/**
* This mode on Amazon EFS scales as the size of the file system in the standard storage class grows.
* This mode scales as the size of the file system in the standard storage class grows.
*/
BURSTING = 'bursting',

/**
* This mode can instantly provision the throughput of the file system (in MiB/s) independent of the amount of data stored.
*/
PROVISIONED = 'provisioned'
PROVISIONED = 'provisioned',

/**
* This mode scales the throughput automatically regardless of file system size.
*/
ELASTIC = 'elastic'
}

/**
Expand Down Expand Up @@ -333,6 +344,9 @@ export class FileSystem extends FileSystemBase {
throw new Error('Property provisionedThroughputPerSecond is required when throughputMode is PROVISIONED');
}

if (props.throughputMode === ThroughputMode.ELASTIC && props.performanceMode === PerformanceMode.MAX_IO) {
throw new Error('ThroughputMode ELASTIC is not supported for file systems with performanceMode MAX_IO');
}
// we explictly use 'undefined' to represent 'false' to maintain backwards compatibility since
// its considered an actual change in CloudFormations eyes, even though they have the same meaning.
const encrypted = props.encrypted ?? (FeatureFlags.of(this).isEnabled(
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ test('file system is created correctly with bursting throughput mode', () => {
});
});

test('file system is created correctly with elastic throughput mode', () => {
// WHEN
new FileSystem(stack, 'EfsFileSystem', {
vpc,
throughputMode: ThroughputMode.ELASTIC,
performanceMode: PerformanceMode.GENERAL_PURPOSE,
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::EFS::FileSystem', {
ThroughputMode: 'elastic',
});
});

test('Exception when throughput mode is set to ELASTIC, performance mode cannot be MaxIO', () => {
expect(() => {
new FileSystem(stack, 'EfsFileSystem', {
vpc,
throughputMode: ThroughputMode.ELASTIC,
performanceMode: PerformanceMode.MAX_IO,
});
}).toThrowError(/ThroughputMode ELASTIC is not supported for file systems with performanceMode MAX_IO/);
});

test('Exception when throughput mode is set to PROVISIONED, but provisioned throughput is not set', () => {
expect(() => {
new FileSystem(stack, 'EfsFileSystem', {
Expand Down
18 changes: 1 addition & 17 deletions packages/@aws-cdk/aws-glue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ A `SecurityConfiguration` is a set of security properties that can be used by AW

```ts
new glue.SecurityConfiguration(this, 'MySecurityConfiguration', {
securityConfigurationName: 'name',
cloudWatchEncryption: {
mode: glue.CloudWatchEncryptionMode.KMS,
},
Expand All @@ -154,7 +153,6 @@ By default, a shared KMS key is created for use with the encryption configuratio
```ts
declare const key: kms.Key;
new glue.SecurityConfiguration(this, 'MySecurityConfiguration', {
securityConfigurationName: 'name',
cloudWatchEncryption: {
mode: glue.CloudWatchEncryptionMode.KMS,
kmsKey: key,
Expand All @@ -169,9 +167,7 @@ See [documentation](https://docs.aws.amazon.com/glue/latest/dg/encryption-securi
A `Database` is a logical grouping of `Tables` in the Glue Catalog.

```ts
new glue.Database(this, 'MyDatabase', {
databaseName: 'my_database',
});
new glue.Database(this, 'MyDatabase');
```

## Table
Expand All @@ -182,7 +178,6 @@ A Glue table describes a table of data in S3: its structure (column names and ty
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -205,7 +200,6 @@ new glue.Table(this, 'MyTable', {
s3Prefix: 'my-table/',
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -224,7 +218,6 @@ To improve query performance, a table can specify `partitionKeys` on which data
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand Down Expand Up @@ -256,7 +249,6 @@ property:
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand Down Expand Up @@ -294,7 +286,6 @@ If you have a table with a large number of partitions that grows over time, cons
declare const myDatabase: glue.Database;
new glue.Table(this, 'MyTable', {
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand Down Expand Up @@ -324,7 +315,6 @@ new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.S3_MANAGED,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -342,7 +332,6 @@ new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.KMS,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -356,7 +345,6 @@ new glue.Table(this, 'MyTable', {
encryptionKey: new kms.Key(this, 'MyKey'),
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -373,7 +361,6 @@ new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.KMS_MANAGED,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -391,7 +378,6 @@ new glue.Table(this, 'MyTable', {
encryption: glue.TableEncryption.CLIENT_SIDE_KMS,
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand All @@ -405,7 +391,6 @@ new glue.Table(this, 'MyTable', {
encryptionKey: new kms.Key(this, 'MyKey'),
// ...
database: myDatabase,
tableName: 'my_table',
columns: [{
name: 'col1',
type: glue.Schema.STRING,
Expand Down Expand Up @@ -447,7 +432,6 @@ new glue.Table(this, 'MyTable', {
}],
// ...
database: myDatabase,
tableName: 'my_table',
dataFormat: glue.DataFormat.JSON,
});
```
Expand Down
15 changes: 10 additions & 5 deletions packages/@aws-cdk/aws-glue/lib/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArnFormat, IResource, Resource, Stack } from '@aws-cdk/core';
import { ArnFormat, IResource, Lazy, Names, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDatabase } from './glue.generated';

Expand Down Expand Up @@ -31,8 +31,10 @@ export interface IDatabase extends IResource {
export interface DatabaseProps {
/**
* The name of the database.
*
* @default - generated by CDK.
*/
readonly databaseName: string;
readonly databaseName?: string;

/**
* The location of the database (for example, an HDFS path).
Expand Down Expand Up @@ -86,13 +88,16 @@ export class Database extends Resource implements IDatabase {
*/
public readonly locationUri?: string;

constructor(scope: Construct, id: string, props: DatabaseProps) {
constructor(scope: Construct, id: string, props: DatabaseProps = {}) {
super(scope, id, {
physicalName: props.databaseName,
physicalName: props.databaseName ??
Lazy.string({
produce: () => Names.uniqueResourceName(this, {}).toLowerCase(),
}),
});

let databaseInput: CfnDatabase.DatabaseInputProperty = {
name: props.databaseName,
name: this.physicalName,
};

if (props.locationUri !== undefined) {
Expand Down
14 changes: 10 additions & 4 deletions packages/@aws-cdk/aws-glue/lib/security-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as kms from '@aws-cdk/aws-kms';
import * as cdk from '@aws-cdk/core';
import { Lazy, Names } from '@aws-cdk/core';
import * as constructs from 'constructs';
import { CfnSecurityConfiguration } from './glue.generated';

Expand Down Expand Up @@ -114,8 +115,10 @@ export interface JobBookmarksEncryption {
export interface SecurityConfigurationProps {
/**
* The name of the security configuration.
*
* @default - generated by CDK.
*/
readonly securityConfigurationName: string;
readonly securityConfigurationName?: string;

/**
* The encryption configuration for Amazon CloudWatch Logs.
Expand Down Expand Up @@ -184,9 +187,12 @@ export class SecurityConfiguration extends cdk.Resource implements ISecurityConf
*/
public readonly s3EncryptionKey?: kms.IKey;

constructor(scope: constructs.Construct, id: string, props: SecurityConfigurationProps) {
constructor(scope: constructs.Construct, id: string, props: SecurityConfigurationProps = {}) {
super(scope, id, {
physicalName: props.securityConfigurationName,
physicalName: props.securityConfigurationName ??
Lazy.string({
produce: () => Names.uniqueResourceName(this, {}),
}),
});

if (!props.s3Encryption && !props.cloudWatchEncryption && !props.jobBookmarksEncryption) {
Expand Down Expand Up @@ -230,7 +236,7 @@ export class SecurityConfiguration extends cdk.Resource implements ISecurityConf
}

const resource = new CfnSecurityConfiguration(this, 'Resource', {
name: props.securityConfigurationName,
name: this.physicalName,
encryptionConfiguration: {
cloudWatchEncryption,
jobBookmarksEncryption,
Expand Down
13 changes: 9 additions & 4 deletions packages/@aws-cdk/aws-glue/lib/table.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as s3 from '@aws-cdk/aws-s3';
import { ArnFormat, Fn, IResource, Names, Resource, Stack } from '@aws-cdk/core';
import { ArnFormat, Fn, IResource, Lazy, Names, Resource, Stack } from '@aws-cdk/core';
import * as cr from '@aws-cdk/custom-resources';
import { AwsCustomResource } from '@aws-cdk/custom-resources';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -83,8 +83,10 @@ export interface TableAttributes {
export interface TableProps {
/**
* Name of the table.
*
* @default - generated by CDK.
*/
readonly tableName: string;
readonly tableName?: string;

/**
* Description of the table.
Expand Down Expand Up @@ -282,7 +284,10 @@ export class Table extends Resource implements ITable {

constructor(scope: Construct, id: string, props: TableProps) {
super(scope, id, {
physicalName: props.tableName,
physicalName: props.tableName ??
Lazy.string({
produce: () => Names.uniqueResourceName(this, {}).toLowerCase(),
}),
});

this.database = props.database;
Expand All @@ -306,7 +311,7 @@ export class Table extends Resource implements ITable {

tableInput: {
name: this.physicalName,
description: props.description || `${props.tableName} generated by CDK`,
description: props.description || `${this.physicalName} generated by CDK`,

partitionKeys: renderColumns(props.partitionKeys),

Expand Down
22 changes: 14 additions & 8 deletions packages/@aws-cdk/aws-glue/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ beforeEach( () => {
});

test('default database does not create a bucket', () => {
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
});
new glue.Database(stack, 'Database');

Template.fromStack(stack).templateMatches({
Resources: {
Expand All @@ -27,7 +25,7 @@ test('default database does not create a bucket', () => {
Ref: 'AWS::AccountId',
},
DatabaseInput: {
Name: 'test_database',
Name: 'database',
},
},
},
Expand All @@ -38,7 +36,6 @@ test('default database does not create a bucket', () => {

test('explicit locationURI', () => {
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
locationUri: 's3://my-uri/',
});

Expand All @@ -52,7 +49,7 @@ test('explicit locationURI', () => {
},
DatabaseInput: {
LocationUri: 's3://my-uri/',
Name: 'test_database',
Name: 'database',
},
},
},
Expand All @@ -78,7 +75,6 @@ test('fromDatabase', () => {
test('locationUri length must be >= 1', () => {
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
locationUri: '',
}),
).toThrow();
Expand All @@ -87,8 +83,18 @@ test('locationUri length must be >= 1', () => {
test('locationUri length must be <= 1024', () => {
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
locationUri: 'a'.repeat(1025),
}),
).toThrow();
});

test('can specify a physical name', () => {
new glue.Database(stack, 'Database', {
databaseName: 'my_database',
});
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Database', {
DatabaseInput: {
Name: 'my_database',
},
});
});
Loading

0 comments on commit cd1f9b5

Please sign in to comment.