Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run aws configure on Amazon AWS EC2 automatically without interaction without prompt?

I'm trying to set up Amazon AWS EC2 instance to talk to s3. The basic command is

aws configure 

then follow the prompt to enter

AWS Access Key ID [None]: my-20-digit-id AWS Secret Access Key [None]: my-40-digit-secret-key Default region name [None]: us-east-1 Default output format [None]: text 

However, what I really want is to have the command

aws configure 

automatically without interaction, i.e., no prompt and wait for input

I know there are files at

~.aws/credentials ~.aws/config 

where I put those 4 key=value pairs. And the "credentials" file looks like

[default] aws_secret_access_key = my-40-digit-secret-key aws_access_key_id = my-20-digit-id 

while the "config" file looks like

[default] region = us-east-1 output = text 

However, with those file at ~/.aws/, I get into ~/.aws/, and at the command line, I type and enter command

aws configure 

I still got the prompt to ask me

AWS Access Key ID [None]: AWS Secret Access Key [None]: Default region name [None]: Default output format [None]: 

If I don't enter valid values at prompt, I won't be able to connect to s3, for example via command

aws s3 ls s3://mybucket 

I turned help to amazon aws documentation pages. At this page, it mentions this option

"Command line options – region, output format and profile can be specified as command options to override default settings."

as the first option for aws configure

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

However, it didn't mention how to use the command line options. I tried something like this

aws configure --region us-east-1 

but I still got

AWS Access Key ID [None]: AWS Secret Access Key [None]: Default region name [None]: Default output format [None]: 

exactly like I have no option of "--region us-east-1"

If I try to

aws configure --aws_access_key_id my-20-digit-id --aws_secret_access_key my-40-digit-secret-key --region us-east-1 

I get this

usage: aws [options] <command> <subcommand> [parameters] aws: error: argument subcommand: Invalid choice, valid choices are: 

How I can run the command

aws configure 

automatically, no prompt, no interaction.

Please help! TIA

Edit and response to helloV, as the format in main post is much clearer than comment. I tried the command helloV mentioned, but I got error

aws configure set aws_access_key_id my-20-digit-id usage: aws [options] <command> <subcommand> [parameters] aws: error: argument subcommand: Invalid choice, valid choices are: 

Thanks though. Continue on "aws configure set" On another EC2 instance where I've already set connection to s3, I enter

aws configure set region us-east-1 

runs and returns to command prompt ">"

aws configure set aws_access_key_id my-20-digit-id 

runs and returns to command prompt ">"

aws configure set aws_secret_access_key my-40-digit-secret-key 

runs and returns to command prompt ">"

aws configure 

runs but comes with prompts and waits for interaction

AWS Access Key ID [****************ABCD]: AWS Secret Access Key [****************1234]: Default region name [us-east-1]: Default output format [text]: 

helloV: here is my screen looks like

ubuntu@ip-11111:~/.aws$ more config [default] region = us-east-1 output = text ubuntu@ip-11111:~/.aws$ more credentials [default] aws_secret_access_key = my-40-digit-secret-key aws_access_key_id = my-20-digit-id ubuntu@ip-11111:~/.aws$ aws s3 ls s3:// 

I got this

Unable to locate credentials. You can configure credentials by running "aws configure". 

After this, I run

aws configure list   Name                    Value             Type    Location   ----                    -----             ----    -------- profile                <not set>             None    None access_key                <not set>             None    None secret_key                <not set>             None    None region                us-east-1      config_file    ~/.aws/config 

Looks like it does not check ~/.aws/credentials file, but ~/.aws/config file is in the list.

like image 387
Tony Xu Avatar asked Feb 08 '18 22:02

Tony Xu


People also ask

How do I keep my EC2 instance running?

Press Ctrl-A then Ctrl-D . This will detach your screen session but leave your processes running. Now, you can log out of the remote box. If you want to come back later, log on again and type screen -r , this will resume your screen session and you can see the output of your process.

What tool can be run from the aws Management Console that to execute the script on all target EC2 instances?

EC2 Run Command is part of EC2 Systems Manager. It allows you to operate on collections of EC2 instances and on-premises servers reliably and at scale, in a controlled and selective fashion. You can run scripts, install software, collect metrics and log files, manage patches, and much more, on both Windows and Linux.

Can you use AWS CLI without access key?

For CLI access, you need an access key ID and secret access key. Use IAM user access keys instead of AWS account root user access keys. IAM lets you securely control access to AWS services and resources in your AWS account.


1 Answers

I figured out, finally. Use export such as

export AWS_ACCESS_KEY_ID=my-20-digit-id export AWS_SECRET_ACCESS_KEY=my-40-digit-secret-key export AWS_DEFAULT_REGION=us-east-1 

then run

aws s3 ls s3:// 

would work. Don't run "aws configure" as others mentioned.

Thank you all.

like image 153
Tony Xu Avatar answered Sep 20 '22 02:09

Tony Xu