Skip to content

Commit

Permalink
Allow passing custom client arguments to S3 client
Browse files Browse the repository at this point in the history
  • Loading branch information
shadyvb committed May 17, 2022
1 parent d82520f commit 46d948d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {};
module.exports.s3 = function(config, key, args, callback) {
AWS.config.region = config.region;

var s3config = {};
var s3config = Object.assign( {}, config.clientArgs );
if (config.endpoint) {
s3config.endpoint = config.endpoint;
}
Expand Down
2 changes: 1 addition & 1 deletion proxy-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const AWS = require( 'aws-sdk' );
const authenticatedRequest = !!process.env.S3_AUTHENTICATED_REQUEST ? process.env.S3_AUTHENTICATED_REQUEST.toLowerCase() === 'true' : false;

function sendOriginal( config, bucket, key, callback ) {
const s3 = new AWS.S3(config);
const s3 = new AWS.S3( Object.assign( {}, config, config.clientArgs ) );

let request;
if ( authenticatedRequest ) {
Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if ( process.env.AWS_REGION && process.env.AWS_S3_BUCKET ) {
config = JSON.parse( fs.readFileSync( 'config.json' ) );
}

config.clientArgs = config.clientArgs || {};
if ( process.env.AWS_S3_CLIENT_ARGS ) {
( new url.URLSearchParams( process.env.AWS_S3_CLIENT_ARGS ) ).forEach( ( value, key ) => config.clientArgs[ key ] = value );
}

http.createServer( function( request, response ) {
var params = url.parse( request.url, true );

Expand Down

0 comments on commit 46d948d

Please sign in to comment.