I’d like to set the S3 endpoint globally, once, rather than setting it each time I make a new AWS.S3()
call. Is this possible?
This is different than global region setting. I’m looking to set a per service endpoint globally.
I’d like to set the S3 endpoint globally, once, rather than setting it each time I make a new AWS.S3()
call. Is this possible?
This is different than global region setting. I’m looking to set a per service endpoint globally.
create a file named aws.js
inside that file create all the functions you want to use for your s3 bucket i.e for uploading content or deleting content.
then just export that file and use it anywhere you want.
e.g : i'm using SQS in my case:
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-east-1" });
// Create an SQS service object
const sqs = new AWS.SQS({ apiVersion: "2012-11-05", "accessKeyId": process.env.ACCESS_KEY_ID, "secretAccessKey": process.env.SECRET_ACCESS_KEY });
const QueueUrl = process.env.SQS_QUEUE_URL;
const sendPayloadToSQS = async message => {
const params = {
MessageBody: JSON.stringify(message),
QueueUrl
};
const request = sqs.sendMessage(params);
const result = await request.promise();
if (result) {
console.log(`Message queued to SQS successfully : ${result.MessageId}`);
} else {
console.log("Message queued failed");
}
};
module.exports = sendPayloadToSQS;
What is your aws-sdk version?
const AWS = require("aws-sdk");
console.log(new AWS.S3().config.endpoint); // s3.amazonaws.com
AWS.config.s3 = { endpoint: "https://my-endpoint" }; // sure this line has been call first of all
console.log(new AWS.S3().config.endpoint); // https://my-endpoint