Created
April 28, 2022 14:13
-
-
Save odbol/2dca19186346c43f40da343acfc405b2 to your computer and use it in GitHub Desktop.
Node.js script to read AWS Credentials from the CVS file that the AWS Console provides you. Baffling that they don't offer this by default...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {promises as fs} from 'fs'; | |
import os from 'os'; | |
import { parse } from 'csv-parse/sync'; | |
/** | |
* Creates a credential provider to pass to S3Client which reads a credentials | |
* CSV downloaded from the AWS console. | |
* | |
* @param csvFile string path of the CSV file from AWS console. | |
* @returns a Provider<Credentials> to give to S3Client as the credentials option. | |
*/ | |
export async function createProvider(csvFile) { | |
const content = await fs.readFile(csvFile); | |
// Parse the CSV content | |
const records = parse(content, { | |
columns: true | |
}); | |
//console.log('cols', records) | |
return { | |
accessKeyId: records[records.length - 1]['Access key ID'], | |
secretAccessKey: records[records.length - 1]['Secret access key'] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createProvider} from './CsvCredentialsProvider.mjs'; | |
// Create an Amazon S3 service client object. | |
const s3Client = new SDK.S3Client({ | |
region: REGION, | |
credentials: createProvider("new_user_credentials.csv") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment