Skip to content

Commit

Permalink
lazily initialize S3
Browse files Browse the repository at this point in the history
  • Loading branch information
yushih committed Jun 8, 2022
1 parent 95c339c commit 62da1c8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions script/coin-price-data-fetcher/src/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ const logger = require('./logger');

import type { Ticker } from './types';

AWS.config.update({region: config.get("s3.region")});
let _S3 = null;

const S3 = new AWS.S3({
accessKeyId: config.get('s3.accessKeyId'),
secretAccessKey: config.get('s3.secretAccessKey'),
});
function getS3() {
if (_S3) {
return _S3;
}

AWS.config.update({region: config.get("s3.region")});

_S3 = new AWS.S3({
accessKeyId: config.get('s3.accessKeyId'),
secretAccessKey: config.get('s3.secretAccessKey'),
});

return _S3;
}

const RETRY_COUNT = 3;

async function upload(ticker: Ticker): Promise<void> {
const S3 = getS3();
const fileName = `prices-${ticker.from}-${ticker.timestamp}.json`;
const uploadParams = {
Body: JSON.stringify(ticker),
Expand Down

0 comments on commit 62da1c8

Please sign in to comment.