(bucket: Bucket, bucketFilePath: string, filePath: string)
| 168 | }; |
| 169 | |
| 170 | export const storeFileToBucket = async (bucket: Bucket, bucketFilePath: string, filePath: string) => { |
| 171 | const { name: bucketName, region: bucketRegion } = bucket; |
| 172 | const s3 = initializeS3Service(bucketRegion); |
| 173 | |
| 174 | logger.debug(`Storing file '${filePath}' as '${bucketFilePath}' to S3 bucket '${bucketName}'`); |
| 175 | const putCommand = new PutObjectCommand({ |
| 176 | Bucket: bucketName, |
| 177 | Key: bucketFilePath, |
| 178 | Body: fs.readFileSync(filePath, { encoding: 'utf-8' }), |
| 179 | }); |
| 180 | const goPut = await go(() => s3.send(putCommand)); |
| 181 | if (!goPut.success) { |
| 182 | throw new Error(`Failed to store file '${filePath}' to S3 bucket '${bucketName}': ${goPut.error}`); |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | export const getFileFromBucket = async (bucket: Bucket, filePath: string) => { |
| 187 | const { name: bucketName, region: bucketRegion } = bucket; |
no test coverage detected