@paulbarmstrong/cdk-managed-objects-bucket
Version:
A CDK construct representing a bucket and the objects within it, which can be defined by an Asset or directly in the CDK. It extends the Bucket construct.
84 lines (83 loc) • 3.82 kB
TypeScript
import { Construct } from "constructs";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import * as logs from "aws-cdk-lib/aws-logs";
import * as s3_assets from "aws-cdk-lib/aws-s3-assets";
export type ManagedObjectsBucketProps = Partial<Omit<Omit<s3.BucketProps, "removalPolicy">, "autoDeleteObjects">> & {
/** CloudWatch Log Group for the bucket object manager to send its logs to. */
objectManagerLogGroup?: logs.ILogGroup;
};
type CloudFrontInvalidationObjectChangeActionProps = {
/** CloudFront Distribution to create an invalidation for. */
distribution: cloudfront.Distribution;
/**
* Whether to wait for the invalidation to be completed before allowing the CloudFormation
* update to continue.
* @default false
*/
waitForCompletion?: boolean;
};
/**
* An action to be performed when changes are made to the objects in the bucket.
*/
export declare abstract class ObjectChangeAction {
#private;
/** ObjectChangeAction for performing a CloudFront invalidation after objects
* in the bucket have changed. */
static cloudFrontInvalidation(props: CloudFrontInvalidationObjectChangeActionProps): CloudFrontInvalidationObjectChangeAction;
}
/** ObjectChangeAction for performing an invalidation on a CloudFront distribution after objects
* in the bucket have changed. */
declare class CloudFrontInvalidationObjectChangeAction extends ObjectChangeAction {
distribution: cloudfront.Distribution;
waitForCompletion?: boolean;
constructor(props: CloudFrontInvalidationObjectChangeActionProps);
}
/**
* An S3 Bucket where the objects in the bucket are completely managed by CDK. A
* `Custom::ManagedBucketObjects` CFN resource internal to the ManagedObjectsBucket construct
* mutates objects in the bucket to align the bucket with the objects defined in the CDK
* definition. The objects in the bucket are otherwise read-only. Objects are added by calling
* the `addObject` and `addObjectsFromAsset` methods.
*
* ManagedObjectsBucket extends [Bucket](
* https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html). All props from
* Bucket are allowed except:
*
* 1. `removalPolicy` and `autoDeleteObjects` are not configurable. ManagedObjectsBuckets are
* always emptied and destroyed on removal.
*
* In the event of ManagedObjectsBucket's `Custom::ManagedBucketObjects` custom resource having
* a persistent problem, you can unblock your stack by adding the following environment variable
* to the ObjectManagerFunction lambda function also inside the stack:
*
* Key: `SKIP`, Value: `true`
*/
export declare class ManagedObjectsBucket extends s3.Bucket {
#private;
constructor(scope: Construct, id: string, props: ManagedObjectsBucketProps);
/**
* Add an object to the bucket based on a given key and body. Deploy-time values from the CDK
* like resource ARNs can be used here.
*/
addObject(props: {
/** S3 object key for the object. */
key: string;
/** Content to be stored within the S3 object. */
body: string;
}): void;
/** Add objects to the bucket based on an [Asset](
* https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_assets-readme.html).
* For example:
*
* `bucket.addObjectsFromAsset({ asset: new Asset(this, "MyAsset", { path: "./my-local-files" }) })`
*/
addObjectsFromAsset(props: {
/** The [Asset](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_assets-readme.html
* ) to be added to the bucket. */
asset: s3_assets.Asset;
}): void;
/** Add an action to be performed when objects in the bucket are changed. */
addObjectChangeAction(action: ObjectChangeAction): void;
}
export {};