Skip to content

Commit 5cd9609

Browse files
Elad Ben-Israelshivlaks
Elad Ben-Israel
authored andcommitted
feat(s3): add missing storage classes and API cleanups (#2834)
Fixes #2708 BREAKING CHANGE: `s3.StorageClass` is now an enum-like class instead of a regular enum. This means that you need to call `.value` in order to obtain it's value. * **s3:** `s3.Coordinates` renamed to `s3.Location` * **codepipeline:** `Artifact.s3Coordinates` renamed to `Artifact.s3Location`.
1 parent e9a4a79 commit 5cd9609

File tree

7 files changed

+70
-21
lines changed

7 files changed

+70
-21
lines changed

packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pipeline.addStage({
121121
stackName: 'LambdaStackDeployedName',
122122
adminPermissions: true,
123123
parameterOverrides: {
124-
...lambdaCode.assign(lambdaBuildOutput.s3Coordinates),
124+
...lambdaCode.assign(lambdaBuildOutput.s3Location),
125125
},
126126
extraInputs: [
127127
lambdaBuildOutput,

packages/@aws-cdk/aws-codepipeline/lib/artifact.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export class Artifact {
7070
}
7171

7272
/**
73-
* Returns the coordinates of the .zip file in S3 that this Artifact represents.
73+
* Returns the location of the .zip file in S3 that this Artifact represents.
7474
* Used by Lambda's `CfnParametersCode` when being deployed in a CodePipeline.
7575
*/
76-
public get s3Coordinates(): s3.Coordinates {
76+
public get s3Location(): s3.Location {
7777
return {
7878
bucketName: this.bucketName,
7979
objectKey: this.objectKey,

packages/@aws-cdk/aws-lambda/lib/code.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,18 @@ export class CfnParametersCode extends Code {
262262
* Create a parameters map from this instance's CloudFormation parameters.
263263
*
264264
* It returns a map with 2 keys that correspond to the names of the parameters defined in this Lambda code,
265-
* and as values it contains the appropriate expressions pointing at the provided S3 coordinates
266-
* (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Coordinates` method).
265+
* and as values it contains the appropriate expressions pointing at the provided S3 location
266+
* (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Location` method).
267267
* The result should be provided to the CloudFormation Action
268268
* that is deploying the Stack that the Lambda with this code is part of,
269269
* in the `parameterOverrides` property.
270270
*
271-
* @param coordinates the coordinates of the object in S3 that represents the Lambda code
271+
* @param location the location of the object in S3 that represents the Lambda code
272272
*/
273-
public assign(coordinates: s3.Coordinates): { [name: string]: any } {
273+
public assign(location: s3.Location): { [name: string]: any } {
274274
const ret: { [name: string]: any } = {};
275-
ret[this.bucketNameParam] = coordinates.bucketName;
276-
ret[this.objectKeyParam] = coordinates.objectKey;
275+
ret[this.bucketNameParam] = location.bucketName;
276+
ret[this.objectKeyParam] = location.objectKey;
277277
return ret;
278278
}
279279

packages/@aws-cdk/aws-s3/lib/bucket.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1060,17 +1060,24 @@ export class Bucket extends BucketBase {
10601060
function parseLifecycleRule(rule: LifecycleRule): CfnBucket.RuleProperty {
10611061
const enabled = rule.enabled !== undefined ? rule.enabled : true;
10621062

1063-
const x = {
1063+
const x: CfnBucket.RuleProperty = {
10641064
// tslint:disable-next-line:max-line-length
10651065
abortIncompleteMultipartUpload: rule.abortIncompleteMultipartUploadAfterDays !== undefined ? { daysAfterInitiation: rule.abortIncompleteMultipartUploadAfterDays } : undefined,
10661066
expirationDate: rule.expirationDate,
10671067
expirationInDays: rule.expirationInDays,
10681068
id: rule.id,
10691069
noncurrentVersionExpirationInDays: rule.noncurrentVersionExpirationInDays,
1070-
noncurrentVersionTransitions: rule.noncurrentVersionTransitions,
1070+
noncurrentVersionTransitions: mapOrUndefined(rule.noncurrentVersionTransitions, t => ({
1071+
storageClass: t.storageClass.value,
1072+
transitionInDays: t.transitionInDays
1073+
})),
10711074
prefix: rule.prefix,
10721075
status: enabled ? 'Enabled' : 'Disabled',
1073-
transitions: rule.transitions,
1076+
transitions: mapOrUndefined(rule.transitions, t => ({
1077+
storageClass: t.storageClass.value,
1078+
transitionDate: t.transitionDate,
1079+
transitionInDays: t.transitionInDays
1080+
})),
10741081
tagFilters: self.parseTagFilters(rule.tagFilters)
10751082
};
10761083

@@ -1280,3 +1287,11 @@ export interface OnCloudTrailBucketEventOptions extends events.OnEventOptions {
12801287
*/
12811288
readonly paths?: string[];
12821289
}
1290+
1291+
function mapOrUndefined<T, U>(list: T[] | undefined, callback: (element: T) => U): U[] | undefined {
1292+
if (!list || list.length === 0) {
1293+
return undefined;
1294+
}
1295+
1296+
return list.map(callback);
1297+
}

packages/@aws-cdk/aws-s3/lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from './bucket';
22
export * from './bucket-policy';
33
export * from './destination';
4-
export * from './coordinates';
4+
export * from './location';
55
export * from './rule';
66

77
// AWS::S3 CloudFormation Resources:

packages/@aws-cdk/aws-s3/lib/coordinates.ts packages/@aws-cdk/aws-s3/lib/location.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* An interface that represents the coordinates of a specific object in an S3 Bucket.
2+
* An interface that represents the location of a specific object in an S3 Bucket.
33
*/
4-
export interface Coordinates {
4+
export interface Location {
55
/**
66
* The name of the S3 Bucket the object is in.
77
*/

packages/@aws-cdk/aws-s3/lib/rule.ts

+40-6
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,57 @@ export interface NoncurrentVersionTransition {
146146
/**
147147
* Storage class to move an object to
148148
*/
149-
export enum StorageClass {
149+
export class StorageClass {
150150
/**
151-
* Storage class for data that is accessed less frequently, but requires rapid access when needed.
151+
* Storage class for data that is accessed less frequently, but requires rapid
152+
* access when needed.
152153
*
153154
* Has lower availability than Standard storage.
154155
*/
155-
InfrequentAccess = 'STANDARD_IA',
156+
public static readonly InfrequentAccess = new StorageClass('STANDARD_IA');
156157

157158
/**
158159
* Infrequent Access that's only stored in one availability zone.
159160
*
160161
* Has lower availability than standard InfrequentAccess.
161162
*/
162-
OneZoneInfrequentAccess = 'ONEZONE_IA',
163+
public static readonly OneZoneInfrequentAccess = new StorageClass('ONEZONE_IA');
163164

164165
/**
165-
* Storage class for long-term archival that can take between minutes and hours to access.
166+
* Storage class for long-term archival that can take between minutes and
167+
* hours to access.
168+
*
169+
* Use for archives where portions of the data might need to be retrieved in
170+
* minutes. Data stored in the GLACIER storage class has a minimum storage
171+
* duration period of 90 days and can be accessed in as little as 1-5 minutes
172+
* using expedited retrieval. If you delete an object before the 90-day
173+
* minimum, you are charged for 90 days.
166174
*/
167-
Glacier = 'GLACIER'
175+
public static readonly Glacier = new StorageClass('GLACIER');
176+
177+
/**
178+
* Use for archiving data that rarely needs to be accessed. Data stored in the
179+
* DEEP_ARCHIVE storage class has a minimum storage duration period of 180
180+
* days and a default retrieval time of 12 hours. If you delete an object
181+
* before the 180-day minimum, you are charged for 180 days. For pricing
182+
* information, see Amazon S3 Pricing.
183+
*/
184+
public static readonly DeepArchive = new StorageClass('DEEP_ARCHIVE');
185+
186+
/**
187+
* The INTELLIGENT_TIERING storage class is designed to optimize storage costs
188+
* by automatically moving data to the most cost-effective storage access
189+
* tier, without performance impact or operational overhead.
190+
* INTELLIGENT_TIERING delivers automatic cost savings by moving data on a
191+
* granular object level between two access tiers, a frequent access tier and
192+
* a lower-cost infrequent access tier, when access patterns change. The
193+
* INTELLIGENT_TIERING storage class is ideal if you want to optimize storage
194+
* costs automatically for long-lived data when access patterns are unknown or
195+
* unpredictable.
196+
*/
197+
public static readonly IntelligentTiering = new StorageClass('INTELLIGENT_TIERING');
198+
199+
constructor(public readonly value: string) { }
200+
201+
public toString() { return this.value; }
168202
}

0 commit comments

Comments
 (0)