1

I want to load the AWS config file and edit the contents of the file.

I found @aws-sdk/shared-ini-file-loader, that works well to load the config file data as the JSON object.

import { loadSharedConfigFiles } from '@aws-sdk/shared-ini-file-loader'

let awsFileContents = await loadSharedConfigFiles({ configFilepath: '~/.aws/config' })
console.log(awsFileContents.configFile)

Now I want to perform some changes in the awsFileContents.configFile object, parse it back to the correct format, and write it back to the ~/.aws/config file.

Is there an AWS module available that can do that?

I have tried ini, multi-ini, and conf-cfg-ini. But they have issues while parsing the JSON back to the correct format.

Shishir Anshuman
  • 1,115
  • 7
  • 23

1 Answers1

0

You do not need the SDK to read/write the config file. It is a normal INI file you can modify with standard tools for INI files. You can use e.g. the ini package for this: https://www.npmjs.com/package/ini

In other languages like Python and also for my "AWS Manager" (Windows application written in Delphi) I use simple ini function to read and also write the config file without any issues.

Daniel Seichter
  • 809
  • 1
  • 8
  • 14
  • The ini module has an issue while writing to the file. It doesn't handle the value with spaces well which leads to the failure of the AWS CLI commands. I added the link to the issue in the description. – Shishir Anshuman Aug 03 '22 at 20:44
  • 1
    @ShishirAnshuman damn... than this is really related to Javascript... normally this should work without any issues... maybe someone can provide a usable library for this or can fix this behaviour in this library as soon as possible -> https://www.npmjs.com/package/js-ini? – Daniel Seichter Aug 03 '22 at 20:53