Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(s3): add missing storage classes and API cleanups #2834

Merged
merged 4 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pipeline.addStage({
stackName: 'LambdaStackDeployedName',
adminPermissions: true,
parameterOverrides: {
...lambdaCode.assign(lambdaBuildOutput.s3Coordinates),
...lambdaCode.assign(lambdaBuildOutput.s3Location),
},
extraInputs: [
lambdaBuildOutput,
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codepipeline/lib/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export class Artifact {
}

/**
* Returns the coordinates of the .zip file in S3 that this Artifact represents.
* Returns the location of the .zip file in S3 that this Artifact represents.
* Used by Lambda's `CfnParametersCode` when being deployed in a CodePipeline.
*/
public get s3Coordinates(): s3.Coordinates {
public get s3Location(): s3.Location {
return {
bucketName: this.bucketName,
objectKey: this.objectKey,
Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-lambda/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ export class CfnParametersCode extends Code {
* Create a parameters map from this instance's CloudFormation parameters.
*
* It returns a map with 2 keys that correspond to the names of the parameters defined in this Lambda code,
* and as values it contains the appropriate expressions pointing at the provided S3 coordinates
* (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Coordinates` method).
* and as values it contains the appropriate expressions pointing at the provided S3 location
* (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Location` method).
* The result should be provided to the CloudFormation Action
* that is deploying the Stack that the Lambda with this code is part of,
* in the `parameterOverrides` property.
*
* @param coordinates the coordinates of the object in S3 that represents the Lambda code
* @param location the location of the object in S3 that represents the Lambda code
*/
public assign(coordinates: s3.Coordinates): { [name: string]: any } {
public assign(location: s3.Location): { [name: string]: any } {
const ret: { [name: string]: any } = {};
ret[this.bucketNameParam] = coordinates.bucketName;
ret[this.objectKeyParam] = coordinates.objectKey;
ret[this.bucketNameParam] = location.bucketName;
ret[this.objectKeyParam] = location.objectKey;
return ret;
}

Expand Down
21 changes: 18 additions & 3 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,17 +1060,24 @@ export class Bucket extends BucketBase {
function parseLifecycleRule(rule: LifecycleRule): CfnBucket.RuleProperty {
const enabled = rule.enabled !== undefined ? rule.enabled : true;

const x = {
const x: CfnBucket.RuleProperty = {
// tslint:disable-next-line:max-line-length
abortIncompleteMultipartUpload: rule.abortIncompleteMultipartUploadAfterDays !== undefined ? { daysAfterInitiation: rule.abortIncompleteMultipartUploadAfterDays } : undefined,
expirationDate: rule.expirationDate,
expirationInDays: rule.expirationInDays,
id: rule.id,
noncurrentVersionExpirationInDays: rule.noncurrentVersionExpirationInDays,
noncurrentVersionTransitions: rule.noncurrentVersionTransitions,
noncurrentVersionTransitions: mapOrUndefined(rule.noncurrentVersionTransitions, t => ({
storageClass: t.storageClass.value,
transitionInDays: t.transitionInDays
})),
prefix: rule.prefix,
status: enabled ? 'Enabled' : 'Disabled',
transitions: rule.transitions,
transitions: mapOrUndefined(rule.transitions, t => ({
storageClass: t.storageClass.value,
transitionDate: t.transitionDate,
transitionInDays: t.transitionInDays
})),
tagFilters: self.parseTagFilters(rule.tagFilters)
};

Expand Down Expand Up @@ -1280,3 +1287,11 @@ export interface OnCloudTrailBucketEventOptions extends events.OnEventOptions {
*/
readonly paths?: string[];
}

function mapOrUndefined<T, U>(list: T[] | undefined, callback: (element: T) => U): U[] | undefined {
if (!list || list.length === 0) {
return undefined;
}

return list.map(callback);
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-s3/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './bucket';
export * from './bucket-policy';
export * from './destination';
export * from './coordinates';
export * from './location';
export * from './rule';

// AWS::S3 CloudFormation Resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* An interface that represents the coordinates of a specific object in an S3 Bucket.
* An interface that represents the location of a specific object in an S3 Bucket.
*/
export interface Coordinates {
export interface Location {
/**
* The name of the S3 Bucket the object is in.
*/
Expand Down
46 changes: 40 additions & 6 deletions packages/@aws-cdk/aws-s3/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,57 @@ export interface NoncurrentVersionTransition {
/**
* Storage class to move an object to
*/
export enum StorageClass {
export class StorageClass {
/**
* Storage class for data that is accessed less frequently, but requires rapid access when needed.
* Storage class for data that is accessed less frequently, but requires rapid
* access when needed.
*
* Has lower availability than Standard storage.
*/
InfrequentAccess = 'STANDARD_IA',
public static readonly InfrequentAccess = new StorageClass('STANDARD_IA');

/**
* Infrequent Access that's only stored in one availability zone.
*
* Has lower availability than standard InfrequentAccess.
*/
OneZoneInfrequentAccess = 'ONEZONE_IA',
public static readonly OneZoneInfrequentAccess = new StorageClass('ONEZONE_IA');

/**
* Storage class for long-term archival that can take between minutes and hours to access.
* Storage class for long-term archival that can take between minutes and
* hours to access.
*
* Use for archives where portions of the data might need to be retrieved in
* minutes. Data stored in the GLACIER storage class has a minimum storage
* duration period of 90 days and can be accessed in as little as 1-5 minutes
* using expedited retrieval. If you delete an object before the 90-day
* minimum, you are charged for 90 days.
*/
Glacier = 'GLACIER'
public static readonly Glacier = new StorageClass('GLACIER');

/**
* Use for archiving data that rarely needs to be accessed. Data stored in the
* DEEP_ARCHIVE storage class has a minimum storage duration period of 180
* days and a default retrieval time of 12 hours. If you delete an object
* before the 180-day minimum, you are charged for 180 days. For pricing
* information, see Amazon S3 Pricing.
*/
public static readonly DeepArchive = new StorageClass('DEEP_ARCHIVE');

/**
* The INTELLIGENT_TIERING storage class is designed to optimize storage costs
* by automatically moving data to the most cost-effective storage access
* tier, without performance impact or operational overhead.
* INTELLIGENT_TIERING delivers automatic cost savings by moving data on a
* granular object level between two access tiers, a frequent access tier and
* a lower-cost infrequent access tier, when access patterns change. The
* INTELLIGENT_TIERING storage class is ideal if you want to optimize storage
* costs automatically for long-lived data when access patterns are unknown or
* unpredictable.
*/
public static readonly IntelligentTiering = new StorageClass('INTELLIGENT_TIERING');

constructor(public readonly value: string) { }

public toString() { return this.value; }
}