3

I am working on setting up something with S3 and Chef, I have AWS CLI installed and working but I need to figure out how to specify the access ID and the secret access key. I know there are cookbooks out there for this but I have tried a few with no luck so I am not using anyone else's cookbooks for this project anymore.

Suggestions on how I can run aws configure and then output the correct value for each of the 4 things it asks?

Code in my script to set env variables:

export AWS_ACCESS_KEY_ID=<key>

export AWS_SECRET_ACCESS_KEY=<secret_key>

export AWS_DEFAULT_REGION=<region>
2

1 Answer 1

2

Have you tried setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables? By setting these variables before you run your cli commands, you should not have to run the aws configure command.

Environment Variables

Environment variables override configuration and credential files and can be useful for scripting or temporarily setting a named profile as the default. The AWS CLI supports the following environment variables.

AWS_ACCESS_KEY_ID – AWS access key.

AWS_SECRET_ACCESS_KEY – AWS secret key. Access and secret key variables override credentials stored in credential and config files.

AWS_SESSION_TOKEN – Specify a session token if you are using temporary security credentials.

AWS_DEFAULT_REGION – AWS region. This variable overrides the default region of the in-use profile, if set.

....

10
  • Yes those are the settings I wanted to change, I was not aware they were env variables, thanks
    – user8517
    Aug 14, 2018 at 15:09
  • I have the values for everything except AWS_SESSION_TOKEN am I fine to go without it? I can't seem to find anything about this in the credentials I was provided.
    – user8517
    Aug 14, 2018 at 19:21
  • I'm assuming you don't have multifactor authentication enabled? You should be good then.
    – Preston Martin
    Aug 14, 2018 at 19:33
  • No 2FA enabled correct, it seems I am not so fine doing export AWS_ACCESS_KEY_ID="value" doesn't seem to be working and setting it correctly in my script.
    – user8517
    Aug 15, 2018 at 12:44
  • I tried it without the " and the export as well with no luck
    – user8517
    Aug 15, 2018 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.