MCPcopy Create free account
hub / github.com/api3dao/airnode / getFileFromBucket

Function getFileFromBucket

packages/airnode-deployer/src/infrastructure/aws.ts:186–206  ·  view source on GitHub ↗
(bucket: Bucket, filePath: string)

Source from the content-addressed store, hash-verified

184};
185
186export const getFileFromBucket = async (bucket: Bucket, filePath: string) => {
187 const { name: bucketName, region: bucketRegion } = bucket;
188 const s3 = initializeS3Service(bucketRegion);
189
190 logger.debug(`Fetching file '${filePath}' from S3 bucket '${bucketName}'`);
191 const getCommand = new GetObjectCommand({ Bucket: bucketName, Key: filePath });
192 const goGet = await go(() => s3.send(getCommand));
193 if (!goGet.success) {
194 throw new Error(`Failed to fetch file '${filePath}' from S3 bucket '${bucketName}': ${goGet.error}`);
195 }
196 if (!goGet.data.Body) {
197 throw new Error(`The response for file '${filePath}' from S3 bucket '${bucketName}' contained an empty body`);
198 }
199
200 const goFileContent = await go(() => goGet.data.Body!.transformToString('utf-8'));
201 if (!goFileContent.success) {
202 throw new Error(`The response for file '${filePath}' from S3 bucket '${bucketName}' is not parsable`);
203 }
204
205 return goFileContent.data;
206};
207
208export const copyFileInBucket = async (bucket: Bucket, fromFilePath: string, toFilePath: string) => {
209 const { name: bucketName, region: bucketRegion } = bucket;

Callers 1

aws.test.tsFile · 0.90

Calls 1

initializeS3ServiceFunction · 0.85

Tested by

no test coverage detected