90 lines
3.3 KiB
TypeScript
90 lines
3.3 KiB
TypeScript
import { Construct } from 'constructs';
|
|
import { CfnBucket, EventType, IBucket } from 'aws-cdk-lib/aws-s3';
|
|
import { BackendOutputStorageStrategy, ConstructFactory, FunctionResources, ResourceProvider, StackProvider } from '@aws-amplify/plugin-types';
|
|
import { StorageOutput } from '@aws-amplify/backend-output-schemas';
|
|
import { Stack } from 'aws-cdk-lib';
|
|
import { IFunction } from 'aws-cdk-lib/aws-lambda';
|
|
import { StorageAccessDefinitionOutput } from './private_types.js';
|
|
export type AmplifyStorageTriggerEvent = 'onDelete' | 'onUpload';
|
|
export type AmplifyStorageProps = {
|
|
/**
|
|
* Whether this storage resource is the default storage resource for the backend.
|
|
* required and relevant only if there are multiple storage resources defined.
|
|
* @default false.
|
|
*/
|
|
isDefault?: boolean;
|
|
/**
|
|
* Friendly name that will be used to derive the S3 Bucket name
|
|
*/
|
|
name: string;
|
|
/**
|
|
* Whether to enable S3 object versioning on the bucket.
|
|
* @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/Versioning.html
|
|
* @default false
|
|
*/
|
|
versioned?: boolean;
|
|
outputStorageStrategy?: BackendOutputStorageStrategy<StorageOutput>;
|
|
/**
|
|
* S3 event trigger configuration
|
|
* @see https://docs.amplify.aws/gen2/build-a-backend/storage/#configure-storage-triggers
|
|
* @example
|
|
* import { triggerHandler } from '../functions/trigger-handler/resource.ts'
|
|
*
|
|
* export const storage = defineStorage({
|
|
* triggers: {
|
|
* onUpload: triggerHandler
|
|
* }
|
|
* })
|
|
*/
|
|
triggers?: Partial<Record<AmplifyStorageTriggerEvent, ConstructFactory<ResourceProvider<FunctionResources>>>>;
|
|
/**
|
|
* Whether to keep the S3 bucket when the stack is deleted.
|
|
*
|
|
* - `true` — The bucket and its objects are preserved when the stack is removed.
|
|
* - `false` — The bucket and all objects are deleted when the stack is removed.
|
|
*
|
|
* Sandbox deployments (via `npx ampx sandbox`) always delete the bucket regardless of this setting.
|
|
* @example
|
|
* ```typescript
|
|
* export const storage = defineStorage({
|
|
* name: 'productionData',
|
|
* keepOnDelete: true,
|
|
* });
|
|
* ```
|
|
* @default false
|
|
*/
|
|
keepOnDelete?: boolean;
|
|
};
|
|
export type StorageResources = {
|
|
bucket: IBucket;
|
|
cfnResources: {
|
|
cfnBucket: CfnBucket;
|
|
};
|
|
};
|
|
/**
|
|
* Amplify Storage CDK Construct
|
|
*
|
|
* Currently just a thin wrapper around an S3 bucket
|
|
*/
|
|
export declare class AmplifyStorage extends Construct implements ResourceProvider<StorageResources>, StackProvider {
|
|
readonly stack: Stack;
|
|
readonly resources: StorageResources;
|
|
readonly isDefault: boolean;
|
|
readonly name: string;
|
|
accessDefinition: StorageAccessDefinitionOutput;
|
|
/**
|
|
* Create a new AmplifyStorage instance
|
|
*/
|
|
constructor(scope: Construct, id: string, props: AmplifyStorageProps);
|
|
/**
|
|
* Attach a Lambda function trigger handler to the S3 events
|
|
* @param events - list of S3 events that will trigger the handler
|
|
* @param handler - The function that will handle the event
|
|
*/
|
|
addTrigger: (events: EventType[], handler: IFunction) => void;
|
|
/**
|
|
* Add access definitions to storage
|
|
*/
|
|
addAccessDefinition: (accessOutput: StorageAccessDefinitionOutput) => void;
|
|
}
|
|
//# sourceMappingURL=construct.d.ts.map
|