Skip to content

Commit

Permalink
refactor(s3-data-source): use aws lite client for header check PE-6106
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen authored and djwhitt committed Jun 7, 2024
1 parent 7651320 commit e3d2e70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/data/s3-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
} from '../types.js';
import { AwsLiteS3 } from '@aws-lite/s3-types';
import { Readable } from 'node:stream';
import axios from 'axios';
import { AWS_ENDPOINT } from '../config.js';
import { awsClient } from '../system.js';

export class S3DataSource implements ContiguousDataSource {
private log: winston.Logger;
Expand Down Expand Up @@ -66,7 +65,7 @@ export class S3DataSource implements ContiguousDataSource {
});

try {
// TODO: Use S3 client instead of axios when aws-lite supports Metadata on head-requests
// TODO: Use S3 client instead of accessing aws client directly when aws-lite s3 supports Metadata on head-requests
// const head = this.s3Client.HeadObject({
// Bucket: this.s3Bucket,
// Key: `${this.s3Prefix}/${id}`,
Expand All @@ -77,11 +76,14 @@ export class S3DataSource implements ContiguousDataSource {
bucket: this.s3Bucket,
prefix: this.s3Prefix,
});
const head = await axios.head(
`${AWS_ENDPOINT}/${this.s3Bucket}/${this.s3Prefix}/${id}`,
{ validateStatus: () => true },
);
if (head.status !== 200) {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const head = await awsClient!({
service: 's3',
path: `${this.s3Bucket}/${this.s3Prefix}/${id}`,
});

if (head.statusCode !== 200) {
throw new Error('Failed to head data from S3');
}

Expand Down
2 changes: 1 addition & 1 deletion src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ process.on('uncaughtException', (error) => {

const arweave = Arweave.init({});
const arIO = IO.init({ processId: config.IO_PROCESS_ID });
const awsClient =
export const awsClient =
config.AWS_ACCESS_KEY_ID !== undefined &&
config.AWS_SECRET_ACCESS_KEY !== undefined &&
config.AWS_REGION !== undefined
Expand Down

0 comments on commit e3d2e70

Please sign in to comment.