AWS Credentials folder location - amazon-web-services

I am trying to install the Amazon Web Services Python SDK. I cannot find the ~/.aws/credentials folder on my machine though.
This is the page I am using for reference: https://aws.amazon.com/developers/getting-started/python/
It says the location on Windows should be like: C:\Users\USER_NAME.aws\credentials
I've done pip installs for boto, boto3, and awscli. Is there something else I need to install to get a credentials folder?

According to the link you posted...
Create your credentials file at ~/.aws/credentials (C:\Users\USER_NAME.aws\credentials for Windows users) and save the following lines after replacing the underlined values with your own.
With the contents
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
There's nothing you need to install, just create the file, and put that in. (obviously swapping out YOUR_ACCESS_KEY_ID for your actual access key, and YOUR_SECRET_ACCESS_KEY for your actual secret key ;) )

Related

Unable to locate credentials aws cli

I am using AWS CLI version 2. I am using centos > Nginx > php 7.1, Following command works fine when I directly run on command line.
aws s3 cp files/abc.pdf s3://bucketname/
but when I run same command from index.php file using following code
echo exec("aws s3 cp files/abc.pdf s3://bucketname/ 2>&1");
then it gives error
upload failed: Unable to locate credentials
#Jass Add your credentials in "~/.aws/credentials" or "~/.aws/config" and make it [default] or else use profile_name incase you have multiple accounts.
Also verify, if you are using keys as Environment variables by export, then it will work for that terminal only. So try to execute the php from same terminal where you exported the keys or add it in ~/.aws/credentials.
I tried this and it worked for me and I believe should work for you as well. In your PHP code (index.php), try exporting the credential file location like below
echo exec("export AWS_SHARED_CREDENTIALS_FILE=/<path_to_aws_folder>/.credentials; aws s3 cp files/abc.pdf s3://bucketname/ 2>&1");
When you run from your command-line the AWS CLI picks up the credentials from your home directory i.e. ~/.aws/credentials (this is default). When the index.php is being executed it is looking for the above file in its home directory which appears is not the same as your home directory and hence cannot find the credentials. With the above change you are explicitly pointing it to your AWS credentials.

aws configure creates userprofile folder and files

Is there a way to set the path other than %USERPROFILE% for aws configure?
I cannot explain why, but on Windows 10 after aws configure runs, it automatically creates the following path and files:
C:\Users\myusername\%USERPROFILE%\Documents.aws
Note the userprofile folder is actually named that way. It's not the windows environment folder.
Normally its supposed to create C:\users\myusername.aws etc.
No, apart from %USERPROFILE there is no other way for aws configure
aws cli configure code
def _write_out_creds_file_values(self, new_values, profile_name):
# The access_key/secret_key are now *always* written to the shared
# credentials file (~/.aws/credentials), see aws/aws-cli#847.
# post-conditions: ~/.aws/credentials will have the updated credential
# file values and new_values will have the cred vars removed.
credential_file_values = {}
Where are configuration settings stored?
Home directory is referred to using the environment variables %UserProfile% in Windows and $HOME or ~ (tilde) in Unix-based systems.
But there is something more to it:
As a general rule, any value that you can place in the credentials file can alternatively be placed in the config file. The other way isn't true: only a few settings can be placed in the credentials file.
So you can place credentials in .aws/config file,and for there is an environment variable named AWS_CONFIG_FILE you can pass and it will be written there. Even though it is not recommended to place credentials in config file

How to reset or start from scratch aws cdk configrations?

I have recently start using aws cdk as a newbie. so i ran lot of commands that i had no idea about.
now i want to remove all settings like env variables i created or profiles and start from scratch. what should in un install to achieve that?
I'm not totally sure what you're trying to reset but here's a few suggestions that might help:
Remove Deployed CDK Stacks
cdk destroy stack_name
Note: You'll have to do this for every stack you've deployed. This can also be done through "CloudFormation" in the AWS dashboard in your browser.
Remove CLI Settings
As per https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-configure-files.html
To remove a setting, use an empty string as the value, or manually delete the setting in your config and credentials files in a text editor.
Example:
aws configure set cli_pager ""
Remove Profiles
Unsure if you can do this easily through the CLI but you can just manually remove them from your config files. There are only two config files and they can be found using https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-configure-profiles.html
~/.aws/credentials (Linux & Mac) or %USERPROFILE%.aws\credentials (Windows)
~/.aws/config (Linux & Mac) or %USERPROFILE%.aws\config (Windows)
If you need more specific help on how to undo something then please provide an example of what exactly you ran that you would like to undo.

How do i create aws config and credential in windows system.?

I have accidentally deleted aws credential and config file from the location c:\user\admin.aws.
Now when i use the aws cli through powershell its throwing an error saying profile not found ,i am unable to create or get those two files. How do i do it?
I tried creating these files using notepad which did not work for me.
I think the path for the files would be "c:\users\admin\.aws\", right?
Once the files are added there, with the right settings, just try
aws sts get-caller-identity
to check if the profile's configuration files are accessible by the command line.

Partial credentials found in env, missing: AWS_SECRET_ACCESS_KEY

Just configured the AWS CLI on my computer with my AWS Access and Secret Key. When I try to use the AWS CLI though it gives me this error.
Partial credentials found in env, missing: AWS_SECRET_ACCESS_KEY
I went to ~/.aws/config, and sure enough those credentials are there, including the AWS Secret Key, so I'm not sure why its squawking at me.
You should have this file ~/.aws/credentials
and the contents should be in the following format:
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
For anyone who is having the same problem - this is solution that worked for me:
If you are on Windows - check if you don't have AWS_ACCESS_KEY_ID set in your system variables. AWS CLI uses something called configuration provider chain - and environment variables take precedence over configuration file. In my case somehow I had only set AWS_ACCESS_KEY_ID thus the error message.
If you are using MacOS, this may be caused because you set other credentials in the environmental variables.
Setting the new credentials to the environmental variables might solve your problem.
To do so run this in the terminal:
export AWS_ACCESS_KEY_ID=X
export AWS_SECRET_ACCESS_KEY=Y
export AWS_DEFAULT_REGION=REGION
Substitute X, Y, and REGION with the values corresponding to your application.
Source documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
I ran with this problem and I did rerun the same workflow yml again and again but changes were never actually occurs. Finally, I had to remove existing workflow from GitHub and re-initiate/pushed yml configuration file again. Worked for me. Thank You!