import AWSXRay from "aws-xray-sdk" ; import S3 from "aws-sdk/clients/s3" ; class S3Service { private client : S3 ; private static instance : S3Service ; private serverSideEncryption = "aws:kms" ; private constructor ( ) { this . client = new S3 ( ) ; AWSXRay . setContextMissingStrategy ( ( ) => { } ) ; AWSXRay . captureAWSClient ( this . client ) ; } static getInstance ( ) { if ( ! S3Service . instance ) { S3Service . instance = new S3Service ( ) ; } return S3Service . instance ; } async putObject ( bucketName , jsonS3Key , jsonFile ) { const params = { Key : jsonS3Key , Body : jsonFile , Bucket : bucketName , ServerSideEncryption : this . serverSideEncryption , ContentType : "application/json" , } ; return this . client . putObject ( params ) . promise ( ) ; } async objectExists ( bucketName , key ) { try { await this . client . headObject ( { Bucket : bucketName , Key : key , } ) . promise ( ) ; return true ; } catch ( err ) { return false ; } } async deleteObject ( bucketName , jsonS3Key ) { const params = { Key : jsonS3Key , Bucket : bucketName , } ; return this . client . deleteObject ( params ) . promise ( ) ; } } export default S3Service ;