Skip to content

Commit

Permalink
Merge branch 'master' into otaviom/stage-depends-on-cwaccount
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 15, 2021
2 parents c390179 + 890c4c5 commit 0f56919
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 16 deletions.
21 changes: 19 additions & 2 deletions packages/@aws-cdk/aws-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,32 @@ by deploying with CDK version `1.126.0` or later **before** switching this value

```ts
const bucket = new s3.Bucket(this, 'MyBucket', {
transferAcceleration: true,
transferAcceleration: true,
});
```

To access the bucket that is enabled for Transfer Acceleration, you must use a special endpoint. The URL can be generated using method `transferAccelerationUrlForObject`:

```ts
const bucket = new s3.Bucket(this, 'MyBucket', {
transferAcceleration: true,
transferAcceleration: true,
});
bucket.transferAccelerationUrlForObject('objectname');
```

## Intelligent Tiering

[Intelligent Tiering](https://docs.aws.amazon.com/AmazonS3/latest/userguide/intelligent-tiering.html) can be configured to automatically move files to glacier:

```ts
new s3.Bucket(this, 'MyBucket', {
intelligentTieringConfigurations: [{
name: 'foo',
prefix: 'folder/name',
archiveAccessTierTime: cdk.Duration.days(90),
deepArchiveAccessTierTime: cdk.Duration.days(180),
tags: [{key: 'tagname', value: 'tagvalue'}]
}],
});

```
161 changes: 160 additions & 1 deletion packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import {
Fn, IResource, Lazy, RemovalPolicy, Resource, ResourceProps, Stack, Token,
CustomResource, CustomResourceProvider, CustomResourceProviderRuntime, FeatureFlags, Tags,
CustomResource, CustomResourceProvider, CustomResourceProviderRuntime, FeatureFlags, Tags, Duration,
} from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -1222,6 +1222,48 @@ export enum ObjectOwnership {
*/
OBJECT_WRITER = 'ObjectWriter',
}
/**
* The intelligent tiering configuration.
*/
export interface IntelligentTieringConfiguration {
/**
* Configuration name
*/
readonly name: string;


/**
* Add a filter to limit the scope of this configuration to a single prefix.
*
* @default this configuration will apply to **all** objects in the bucket.
*/
readonly prefix?: string;

/**
* You can limit the scope of this rule to the key value pairs added below.
*
* @default No filtering will be performed on tags
*/
readonly tags?: Tag[];

/**
* When enabled, Intelligent-Tiering will automatically move objects that
* haven’t been accessed for a minimum of 90 days to the Archive Access tier.
*
* @default Objects will not move to Glacier
*/
readonly archiveAccessTierTime?: Duration;

/**
* When enabled, Intelligent-Tiering will automatically move objects that
* haven’t been accessed for a minimum of 180 days to the Deep Archive Access
* tier.
*
* @default Objects will not move to Glacier Deep Access
*/
readonly deepArchiveAccessTierTime?: Duration;
}

export interface BucketProps {
/**
* The kind of server-side encryption to apply to this bucket.
Expand Down Expand Up @@ -1418,6 +1460,31 @@ export interface BucketProps {
* @default false
*/
readonly transferAcceleration?: boolean;

/**
* Inteligent Tiering Configurations
*
* @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/intelligent-tiering.html
*
* @default No Intelligent Tiiering Configurations.
*/
readonly intelligentTieringConfigurations?: IntelligentTieringConfiguration[];
}


/**
* Tag
*/
export interface Tag {

/**
* key to e tagged
*/
readonly key: string;
/**
* additional value
*/
readonly value: string;
}

/**
Expand Down Expand Up @@ -1585,6 +1652,7 @@ export class Bucket extends BucketBase {
inventoryConfigurations: Lazy.any({ produce: () => this.parseInventoryConfiguration() }),
ownershipControls: this.parseOwnershipControls(props),
accelerateConfiguration: props.transferAcceleration ? { accelerationStatus: 'Enabled' } : undefined,
intelligentTieringConfigurations: this.parseTieringConfig(props),
});
this._resource = resource;

Expand Down Expand Up @@ -1887,6 +1955,35 @@ export class Bucket extends BucketBase {
};
}

private parseTieringConfig({ intelligentTieringConfigurations }: BucketProps): CfnBucket.IntelligentTieringConfigurationProperty[] | undefined {
if (!intelligentTieringConfigurations) {
return undefined;
}

return intelligentTieringConfigurations.map(config => {
const tierings = [];
if (config.archiveAccessTierTime) {
tierings.push({
accessTier: 'ARCHIVE_ACCESS',
days: config.archiveAccessTierTime.toDays({ integral: true }),
});
}
if (config.deepArchiveAccessTierTime) {
tierings.push({
accessTier: 'DEEP_ARCHIVE_ACCESS',
days: config.deepArchiveAccessTierTime.toDays({ integral: true }),
});
}
return {
id: config.name,
prefix: config.prefix,
status: 'Enabled',
tagFilters: config.tags,
tierings: tierings,
};
});
}

private renderWebsiteConfiguration(props: BucketProps): CfnBucket.WebsiteConfigurationProperty | undefined {
if (!props.websiteErrorDocument && !props.websiteIndexDocument && !props.websiteRedirect && !props.websiteRoutingRules) {
return undefined;
Expand Down Expand Up @@ -2057,6 +2154,7 @@ export enum BucketEncryption {

/**
* Notification event types.
* @link https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-how-to-event-types-and-destinations.html#supported-notification-event-types
*/
export enum EventType {
/**
Expand Down Expand Up @@ -2208,6 +2306,67 @@ export enum EventType {
* by replication metrics.
*/
REPLICATION_OPERATION_NOT_TRACKED = 's3:Replication:OperationNotTracked',

/**
* By using the LifecycleExpiration event types, you can receive a notification
* when Amazon S3 deletes an object based on your S3 Lifecycle configuration.
*/
LIFECYCLE_EXPIRATION = 's3:LifecycleExpiration:*',

/**
* The s3:LifecycleExpiration:Delete event type notifies you when an object
* in an unversioned bucket is deleted.
* It also notifies you when an object version is permanently deleted by an
* S3 Lifecycle configuration.
*/
LIFECYCLE_EXPIRATION_DELETE = 's3:LifecycleExpiration:Delete',

/**
* The s3:LifecycleExpiration:DeleteMarkerCreated event type notifies you
* when S3 Lifecycle creates a delete marker when a current version of an
* object in versioned bucket is deleted.
*/
LIFECYCLE_EXPIRATION_DELETE_MARKER_CREATED = 's3:LifecycleExpiration:DeleteMarkerCreated',

/**
* You receive this notification event when an object is transitioned to
* another Amazon S3 storage class by an S3 Lifecycle configuration.
*/
LIFECYCLE_TRANSITION = 's3:LifecycleTransition',

/**
* You receive this notification event when an object within the
* S3 Intelligent-Tiering storage class moved to the Archive Access tier or
* Deep Archive Access tier.
*/
INTELLIGENT_TIERING = 's3:IntelligentTiering',

/**
* By using the ObjectTagging event types, you can enable notification when
* an object tag is added or deleted from an object.
*/
OBJECT_TAGGING = 's3:ObjectTagging:*',

/**
* The s3:ObjectTagging:Put event type notifies you when a tag is PUT on an
* object or an existing tag is updated.
*/
OBJECT_TAGGING_PUT = 's3:ObjectTagging:Put',

/**
* The s3:ObjectTagging:Delete event type notifies you when a tag is removed
* from an object.
*/
OBJECT_TAGGING_DELETE = 's3:ObjectTagging:Delete',

/**
* You receive this notification event when an ACL is PUT on an object or when
* an existing ACL is changed.
* An event is not generated when a request results in no change to an
* object’s ACL.
*/
OBJECT_ACL_PUT = 's3:ObjectAcl:Put',
}

export interface NotificationKeyFilter {
Expand Down
139 changes: 138 additions & 1 deletion packages/@aws-cdk/aws-s3/test/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,144 @@ describe('bucket', () => {
},
},
});
});

test('bucket with intelligent tiering turned on', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
intelligentTieringConfigurations: [{
name: 'foo',
}],
});

expect(stack).toMatchTemplate({
'Resources': {
'MyBucketF68F3FF0': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'IntelligentTieringConfigurations': [
{
'Id': 'foo',
'Status': 'Enabled',
'Tierings': [],
},
],
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
},
});
});

test('bucket with intelligent tiering turned on with archive access', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
intelligentTieringConfigurations: [{
name: 'foo',
archiveAccessTierTime: cdk.Duration.days(90),
}],
});

expect(stack).toMatchTemplate({
'Resources': {
'MyBucketF68F3FF0': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'IntelligentTieringConfigurations': [
{
'Id': 'foo',
'Status': 'Enabled',
'Tierings': [{
'AccessTier': 'ARCHIVE_ACCESS',
'Days': 90,
}],
},
],
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
},
});
});

test('bucket with intelligent tiering turned on with deep archive access', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
intelligentTieringConfigurations: [{
name: 'foo',
deepArchiveAccessTierTime: cdk.Duration.days(180),
}],
});

expect(stack).toMatchTemplate({
'Resources': {
'MyBucketF68F3FF0': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'IntelligentTieringConfigurations': [
{
'Id': 'foo',
'Status': 'Enabled',
'Tierings': [{
'AccessTier': 'DEEP_ARCHIVE_ACCESS',
'Days': 180,
}],
},
],
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
},
});
});

test('bucket with intelligent tiering turned on with all properties', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
intelligentTieringConfigurations: [{
name: 'foo',
prefix: 'bar',
archiveAccessTierTime: cdk.Duration.days(90),
deepArchiveAccessTierTime: cdk.Duration.days(180),
tags: [{ key: 'test', value: 'bazz' }],
}],
});

expect(stack).toMatchTemplate({
'Resources': {
'MyBucketF68F3FF0': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'IntelligentTieringConfigurations': [
{
'Id': 'foo',
'Prefix': 'bar',
'Status': 'Enabled',
'TagFilters': [
{
'Key': 'test',
'Value': 'bazz',
},
],
'Tierings': [{
'AccessTier': 'ARCHIVE_ACCESS',
'Days': 90,
},
{
'AccessTier': 'DEEP_ARCHIVE_ACCESS',
'Days': 180,
}],
},
],
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
},
});
});
});

});
Loading

0 comments on commit 0f56919

Please sign in to comment.