@worktif/purews
Version:
Work TIF TypeScript-based AWS infrastructure toolkit featuring DynamoDB integration, AppSync support, SES functionality, and GraphQL capabilities with comprehensive audit logging and AWS Signature V4 authentication.
69 lines (68 loc) • 3.43 kB
TypeScript
import 'reflect-metadata';
import { GetObjectCommandInput, S3 } from '@aws-sdk/client-s3';
import { Logger } from '@aws-lambda-powertools/logger';
import { BeforeInstance, LoggerInterface, Maybe, Nullable } from '@worktif/utils';
import { EnvConfigPurews } from '@config/env.config.purews';
/**
* S3Service is designed to provide a seamless interface for interacting with AWS S3 services.
* This includes operations such as retrieving object content and managing files in the bucket.
*
* It facilitates structured logging and error handling, ensuring that interactions with S3
* resources are robust, traceable, and reliable.
*
* This service leverages dependency injection to manage configuration and enhance testability.
*/
export declare class S3Service implements LoggerInterface {
protected envConfig: EnvConfigPurews;
protected bucket: Maybe<Nullable<string>>;
/**
* The `loggerInstance` variable is an instance of the Logger class, configured with
* metadata specific to the context in which it is used. It is pre-configured
* with the service name '@services/s3/s3.service.ts' for identifying the service's
* log outputs.
*
* This logger instance is utilized for logging operations, including informational,
* warning, error, or debug messages within the S3 service module. Logs generated by
* this instance will automatically include the specified service name for easier
* traceability and debugging.
*
* Usage of this logger instance provides consistent and structured logging across
* the service, ensuring that logs follow a standard format and include service-specific
* context.
*
* Note: Ensure that the logger's configuration is compatible with the intended log
* aggregation or monitoring system.
*/
loggerInstance: Logger;
/**
* An instance of the AWS S3 service.
* This allows interaction with Amazon S3 for operations like uploading,
* retrieving, and managing data in buckets.
* It provides methods to perform actions such as reading, writing,
* and deleting objects within an S3 bucket.
*
* s3 must be properly configured with required credentials and
* region settings to interact with AWS services.
*
* @type {S3}
*/
protected s3: S3;
/**
* Creates an instance of the class, initializing the S3 client with the provided environment configuration.
*
* @param {EnvConfigPurews} envConfig - The environment configuration object injected to set up AWS S3.
* @return {void}
*/
constructor(envConfig: EnvConfigPurews);
/**
* Retrieves the content of an object stored in an S3 bucket as a string.
*
* @param {Object} params - The input parameters for retrieving the object.
* @param {string} params.Bucket - The name of the S3 bucket.
* @param {string} params.Key - The key of the S3 object.
* @param {BeforeInstance} [beforeInstance] - Optional instance for logging or additional pre-processing.
* @return {Promise<Maybe<string>>} - A promise that resolves to the content of the S3 object as a string, or undefined if no content exists.
* @throws {CustomException} - Throws an exception if the object cannot be processed or retrieved.
*/
getS3ObjectContent({ Bucket, Key }: GetObjectCommandInput, beforeInstance?: BeforeInstance): Promise<Maybe<string>>;
}