in source/aws-connect-vm-serverless/src/service/s3.service.js [17:54]
constructor() {
this.secretsManager = new AWS.SecretsManager();
const getAWSCredentials = async() => {
const results = await this.secretsManager.getSecretValue({SecretId: process.env.SECRET_ARN}).promise()
.then((res) => {
return res;
})
.catch((err) => {
console.log('error ', err);
return err;
});
return results;
};
(async () => {
const data = await getAWSCredentials()
this.isTempToken = false;
if ('SecretString' in data) {
var secret = data.SecretString;
var jsonParsed = JSON.parse(secret);
var accessKeyId = jsonParsed.accessKeyId;
var secretAccessKey = jsonParsed.secretAccessKey;
// Creating a S3 client to include the access key ID and secret access key of an IAM user and to use AWS Signature Version 4
this.s3 = new AWS.S3({
signatureVersion: 'v4',
credentials: {
secretAccessKey: secretAccessKey,
accessKeyId: accessKeyId
}
});
} else {
this.isTempToken = true;
// Creating a S3 client using temporary credentials of Lambda IAM Role
this.s3 = new AWS.S3();
}
})()
}