function fetchConfigForStage()

in src/lib/config.ts [73:99]


function fetchConfigForStage(stage: Stage): Promise<Config> {
	console.log('Fetching configuration file from S3.');
	return new Promise((resolve, reject) => {
		const key = 'fulfilment.private.json';
		const bucket = `gu-reader-revenue-private/membership/fulfilment-lambdas/${stage}`;
		console.log(`loading ${stage} configuration from ${bucket}/${key}`);

		s3.getObject({ Bucket: bucket, Key: key }, function (err, data) {
			if (err) {
				console.log(`Error fetching config for S3 : ${err}`);
				reject(
					new NamedError(
						'config_error',
						`Error fetching config for S3 : ${err}`,
					),
				);
			} else {
				const json = JSON.parse(Buffer.from(data.Body as Buffer).toString());
				console.log('Config succesfully downloaded and parsed.');
				resolve({
					stage: stage,
					...json,
				});
			}
		});
	});
}